diff --git a/package-lock.json b/package-lock.json index 7a3bbc21..13a573bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@nzz/q-server", - "version": "6.0.0", + "version": "6.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5e3ca8df..a85f37b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nzz/q-server", - "version": "6.0.0", + "version": "6.1.0", "description": "", "main": "index.js", "scripts": { diff --git a/plugins/core/base/routes/admin/migration.js b/plugins/core/base/routes/admin/migration.js index a057f7ac..06b47840 100644 --- a/plugins/core/base/routes/admin/migration.js +++ b/plugins/core/base/routes/admin/migration.js @@ -20,7 +20,6 @@ module.exports = { }, handler: async (request, h) => { const tool = request.params.tool; - let toolBaseUrl = request.server.settings.app.tools.get(`/${tool}/baseUrl`); if (!toolBaseUrl) { @@ -34,19 +33,18 @@ module.exports = { request.params.id, ignoreInactive ); + const migrationStatus = await migrateItem( + item, + toolBaseUrl, + request.server.app.db + ); + return { + status: migrationStatus.status + }; } catch (err) { Bounce.rethrow(err, "system"); return err; } - - const migrationStatus = await migrateItem( - item, - toolBaseUrl, - request.server.app.db - ); - return { - status: migrationStatus.status - }; } else { const items = await request.server.methods.db.item.getAllByTool(tool); diff --git a/plugins/core/rendering-info/helpers.js b/plugins/core/rendering-info/helpers.js index 17df750d..06672189 100644 --- a/plugins/core/rendering-info/helpers.js +++ b/plugins/core/rendering-info/helpers.js @@ -161,6 +161,26 @@ function getCompiledToolRuntimeConfig( }${path}`; } + // simplify the fileRequestBaseUrl to an url string if it is an object by applying some defaults before sending it to the tool + if ( + typeof overallToolRuntimeConfig.fileRequestBaseUrl === "object" && + overallToolRuntimeConfig.fileRequestBaseUrl.host + ) { + // the default protocol is https + let protocol = "https"; + if (overallToolRuntimeConfig.fileRequestBaseUrl.protocol) { + protocol = overallToolRuntimeConfig.fileRequestBaseUrl.protocol; + } + // the default if no path is given is /file + let path = "/file"; + if (overallToolRuntimeConfig.fileRequestBaseUrl.path) { + path = overallToolRuntimeConfig.fileRequestBaseUrl.path; + } + overallToolRuntimeConfig.fileRequestBaseUrl = `${protocol}://${ + overallToolRuntimeConfig.fileRequestBaseUrl.host + }${path}`; + } + // default to the overall config let toolRuntimeConfig = overallToolRuntimeConfig; diff --git a/plugins/file/index.js b/plugins/file/index.js index dcc662c6..c0938f97 100644 --- a/plugins/file/index.js +++ b/plugins/file/index.js @@ -1,3 +1,4 @@ +const Boom = require("boom"); const AWS = require("aws-sdk"); const Mimos = require("mimos"); const mimos = new Mimos(); @@ -134,5 +135,39 @@ module.exports = { }; } }); + + server.route({ + method: "GET", + path: "/file/{fileKey*}", + options: { + tags: ["api"] + }, + handler: async function(request, h) { + return new Promise((resolve, reject) => { + s3.getObject( + { + Bucket: options.s3Bucket, + Key: request.params.fileKey + }, + (err, data) => { + if (err) { + return reject( + new Boom("error", { statusCode: err.statusCode }) + ); + } + return resolve( + h + .response(data.Body) + .header( + "cache-control", + "max-age=31536000, s-maxage=31536000, stale-while-revalidate=31536000, stale-if-error=31536000, immutable" + ) + .type(data.ContentType) + ); + } + ); + }); + } + }); } };