Skip to content

Commit

Permalink
fix(configuration): config allows larger file sizes (#1127)
Browse files Browse the repository at this point in the history
Further changes:
- uuid dynamically fetched from H5P Hub
- Old content and temporary files deleted on startup
- default config values written to config on first startup
  • Loading branch information
sr258 authored Jan 5, 2021
1 parent a58b899 commit 5ef7523
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
"i18next": "^19.8.4",
"i18next-fs-backend": "^1.0.7",
"i18next-http-middleware": "^3.0.6",
"mkdirp": "1.0.4",
"nucleus-nodejs": "3.0.7",
"promisepipe": "3.0.0",
"rimraf": "3.0.2",
"socket.io": "2.4.0"
},
"scripts": {
Expand Down
53 changes: 27 additions & 26 deletions server/src/boot/setup.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import mkdirp from 'mkdirp';
import * as Sentry from '@sentry/node';

import fsExtra from 'fs-extra';

import IServerConfig from '../IServerConfig';
import { fsImplementations, H5PConfig } from '@lumieducation/h5p-server';

export default async function setup(
serverConfig: IServerConfig
): Promise<void> {
try {
mkdirp.sync(serverConfig.workingCachePath);
mkdirp.sync(serverConfig.librariesPath);
mkdirp.sync(serverConfig.temporaryStoragePath);
// Remove old leftovers
await fsExtra.remove(serverConfig.workingCachePath);
await fsExtra.remove(serverConfig.temporaryStoragePath);

// we might need to update settings here and run upgrade scripts when for example the baseUrl changes
await fsExtra.mkdirp(serverConfig.workingCachePath);
await fsExtra.mkdirp(serverConfig.librariesPath);
await fsExtra.mkdirp(serverConfig.temporaryStoragePath);

if (!fsExtra.existsSync(serverConfig.configFile)) {
fsExtra.writeFileSync(
serverConfig.configFile,
JSON.stringify({
fetchingDisabled: 0,
baseUrl: '/api/v1/h5p',
uuid: '8de62c47-f335-42f6-909d-2d8f4b7fb7f5',
siteType: 'local',
sendUsageStatistics: false,
hubRegistrationEndpoint: 'https://api.h5p.org/v1/sites',
hubContentTypesEndpoint:
'https://api.h5p.org/v1/content-types/',
contentTypeCacheRefreshInterval: 86400000,
enableLrsContentTypes: true,
editorAddons: {
'H5P.CoursePresentation': ['H5P.MathDisplay'],
'H5P.InteractiveVideo': ['H5P.MathDisplay'],
'H5P.DragQuestion': ['H5P.MathDisplay']
}
})
// we might need to update settings here and run upgrade scripts when for example the baseUrl changes
if (!(await fsExtra.pathExists(serverConfig.configFile))) {
// We write configuration values that are not automatically saved
// when calling h5pConfig.save()
await fsExtra.writeJSON(serverConfig.configFile, {
baseUrl: '/api/v1/h5p',
editorAddons: {
'H5P.CoursePresentation': ['H5P.MathDisplay'],
'H5P.InteractiveVideo': ['H5P.MathDisplay'],
'H5P.DragQuestion': ['H5P.MathDisplay']
}
});
// Write all other default values to the config.
const h5pConfig = new H5PConfig(
new fsImplementations.JsonStorage(serverConfig.configFile),
{
maxFileSize: 2 * 1024 * 1024 * 1014, // max. 2 GB
maxTotalSize: 2 * 1024 * 1024 * 1014 // max. 2 GB
}
);
await h5pConfig.save();
}
} catch (error) {
Sentry.captureException(error);
Expand Down

0 comments on commit 5ef7523

Please sign in to comment.