Skip to content

Commit d2d5d16

Browse files
committed
Merge branch 'master' into kagiura/mobility
2 parents 0cf08a5 + a10caa1 commit d2d5d16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+6687
-1019
lines changed

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ jobs:
9292
command: |
9393
set -e
9494
yarn test --runInBand --reporters=default --reporters=jest-junit
95-
yarn codecov --disable=gcov -f ./coverage/coverage-final.json
95+
if [ "${CIRCLE_BRANCH}" != "master" ] && [ "${CIRCLE_BRANCH}" != "production" ]; then
96+
yarn codecov --disable=gcov -f ./coverage/coverage-final.json
97+
fi
9698
- run:
9799
name: Integration tests
98100
environment:

export/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
},
1919
"dependencies": {
2020
"@sentry/node": "5.30.0",
21-
"@sparticuz/chromium": "92.0.0",
21+
"@sparticuz/chromium": "^123.0.0",
2222
"axios": "0.27.2",
2323
"bunyan": "1.8.15",
2424
"fs-extra": "9.1.0",
2525
"http-graceful-shutdown": "2.4.0",
26+
"joi": "^17.12.3",
2627
"koa": "2.14.2",
2728
"koa-router": "10.1.1",
2829
"koa-views": "6.3.1",
2930
"lodash": "4.17.21",
3031
"nodemon": "2.0.22",
31-
"pug": "3.0.2",
32-
"puppeteer-core": "10.4.0"
32+
"pug": "3.0.3",
33+
"puppeteer-core": "22.6.4"
3334
},
3435
"devDependencies": {
3536
"@types/fs-extra": "9.0.13",

export/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ router
2929
typeof width !== 'undefined' &&
3030
!Number.isNaN(height) && // accept floats
3131
!Number.isNaN(width) && // accept floats
32-
height > 0 &&
33-
width > 0
32+
Number(height) > 0 &&
33+
Number(width) > 0
3434
) {
3535
options = {
3636
...options,

export/src/data.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'path';
22
import fs from 'fs-extra';
33
import axios from 'axios';
44
import _ from 'lodash';
5+
import Joi from 'joi';
56
import type { Middleware } from 'koa';
67

78
import config from './config';
@@ -60,20 +61,26 @@ export const parseExportData: Middleware<State> = (ctx, next) => {
6061
export function validateExportData(data: PageData) {
6162
if (!_.isObject(data)) throw new Error('data should be an object');
6263

63-
if (!_.isInteger(data.semester) || data.semester < 1 || data.semester > 4) {
64-
throw new Error('Invalid semester');
65-
}
66-
67-
// TODO: Improve these validation
68-
if (!_.isObject(data.timetable)) {
69-
throw new Error('Invalid timetable');
70-
}
71-
72-
if (!_.isObject(data.settings)) {
73-
throw new Error('Invalid settings');
74-
}
64+
const timetableSchema = Joi.object().pattern(
65+
Joi.string(),
66+
Joi.object().pattern(Joi.string(), Joi.string()),
67+
);
68+
const themeSchema = Joi.object({
69+
id: Joi.string(),
70+
timetableOrientation: Joi.string().valid('HORIZONTAL', 'VERTICAL'),
71+
showTitle: Joi.boolean(),
72+
});
73+
const pageDataSchema = Joi.object({
74+
semester: Joi.number().integer().greater(0).less(5),
75+
timetable: timetableSchema,
76+
settings: Joi.object({
77+
hiddenInTimeTable: Joi.array().items(Joi.string()),
78+
}),
79+
theme: themeSchema,
80+
});
7581

76-
if (!_.isObject(data.theme)) {
77-
throw new Error('Invalid theme');
82+
const result = pageDataSchema.validate(data, { allowUnknown: true });
83+
if (result.error !== undefined) {
84+
throw new Error(JSON.stringify(result.error));
7885
}
7986
}

export/src/handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Sentry from '@sentry/node';
2-
import type { NowApiHandler, NowRequest, NowResponse } from '@vercel/node';
2+
import type { VercelApiHandler, VercelRequest, VercelResponse } from '@vercel/node';
33
import type { Page } from 'puppeteer-core';
44

55
import * as render from './render-serverless';
@@ -38,9 +38,9 @@ function setUpSentry() {
3838
* @returns A Vercel serverless function handler.
3939
*/
4040
export function makeExportHandler<T>(
41-
parseExportData: (request: NowRequest) => T,
42-
performExport: (response: NowResponse, page: Page, data: T) => void | Promise<void>,
43-
): NowApiHandler {
41+
parseExportData: (request: VercelRequest) => T,
42+
performExport: (response: VercelResponse, page: Page, data: T) => void | Promise<void>,
43+
): VercelApiHandler {
4444
return async function handler(request, response) {
4545
try {
4646
throwIfAcademicYearNotSet();

export/src/render-serverless.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ async function setViewport(page: Page, options: ViewportOptions = {}) {
2323
}
2424

2525
export async function open(url: string) {
26+
const executablePath = await chromium.executablePath();
27+
28+
chromium.setGraphicsMode = false;
29+
2630
const browser = await puppeteer.launch({
2731
// devtools: !!process.env.DEVTOOLS, // TODO: Query string && NODE_ENV === 'development'?
2832
args: chromium.args,
2933
defaultViewport: chromium.defaultViewport,
30-
executablePath: await chromium.executablePath,
34+
executablePath: executablePath,
3135
headless: chromium.headless,
3236
});
3337

export/src/render.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@ async function setViewport(page: Page, options: ViewportOptions = {}) {
2525

2626
export async function launch() {
2727
const browser = await puppeteer.launch({
28+
headless: true,
2829
executablePath: config.chromeExecutable,
2930
devtools: !!process.env.DEVTOOLS,
30-
args: [
31-
'--headless',
32-
'--disable-gpu',
33-
'--disable-software-rasterizer',
34-
'--disable-dev-shm-usage',
35-
],
3631
});
3732

3833
const page = await browser.newPage();

0 commit comments

Comments
 (0)