Skip to content

Commit

Permalink
Merge pull request #134 from nzzdev/release-6.1.0
Browse files Browse the repository at this point in the history
Release 6.1.0
  • Loading branch information
benib committed Sep 5, 2018
2 parents e91fc31 + 9eeb718 commit de16104
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nzz/q-server",
"version": "6.0.0",
"version": "6.1.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 8 additions & 10 deletions plugins/core/base/routes/admin/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions plugins/core/rendering-info/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
35 changes: 35 additions & 0 deletions plugins/file/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Boom = require("boom");
const AWS = require("aws-sdk");
const Mimos = require("mimos");
const mimos = new Mimos();
Expand Down Expand Up @@ -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)
);
}
);
});
}
});
}
};

0 comments on commit de16104

Please sign in to comment.