Skip to content

Commit

Permalink
Merge pull request #131 from nzzdev/release-6.0.0
Browse files Browse the repository at this point in the history
Release 6.0.0
  • Loading branch information
benib committed Aug 28, 2018
2 parents adecff7 + 7f3488c commit e91fc31
Show file tree
Hide file tree
Showing 8 changed files with 1,529 additions and 1,356 deletions.
2,414 changes: 1,216 additions & 1,198 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nzz/q-server",
"version": "5.1.0",
"version": "6.0.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,6 +28,7 @@
"clone": "^2.1.1",
"deepmerge": "^2.1.0",
"hapi": "^17.5.0",
"hasha": "^3.0.0",
"hoek": "^5.0.3",
"inert": "^5.1.0",
"joi": "^13.3.0",
Expand All @@ -38,6 +39,7 @@
"nano-promises": "^1.2.0",
"node-fetch": "^2.1.2",
"puppeteer": "^1.4.0",
"slugify": "^1.3.1",
"uuid": "^3.2.1",
"vision": "^5.3.2",
"wreck": "^14.0.2"
Expand Down
17 changes: 12 additions & 5 deletions plugins/core/base/routes/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ module.exports = {
_id: res.id,
_rev: res.rev
});
request.server.events.emit("item.new", savedDoc);
request.server.events.emit("item.new", {
newItem: savedDoc
});

return resolve(docDiff);
});
Expand Down Expand Up @@ -208,17 +210,22 @@ module.exports = {
_rev: res.rev
});

const eventData = {
newItem: savedDoc,
oldItem: oldDoc
};

if (isNewActive) {
request.server.events.emit("item.activate", savedDoc);
request.server.events.emit("item.activate", eventData);
}
if (isNewInactive) {
request.server.events.emit("item.deactivate", savedDoc);
request.server.events.emit("item.deactivate", eventData);
}
if (isDeleted) {
request.server.events.emit("item.delete", savedDoc);
request.server.events.emit("item.delete", eventData);
}

request.server.events.emit("item.update", savedDoc);
request.server.events.emit("item.update", eventData);

docDiff._rev = res.rev;
return resolve(docDiff);
Expand Down
8 changes: 6 additions & 2 deletions plugins/core/base/routes/tool-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ module.exports = {
handler: async (request, h) => {
let payload = null;
if (request.query.appendItemToPayload) {
// Get item with ignoreInactive set to true (gets inactive or active item)
const item = await request.server.methods.db.item.getById(
request.query.appendItemToPayload
request.query.appendItemToPayload,
true
);
payload = {
item: item
Expand Down Expand Up @@ -137,8 +139,10 @@ module.exports = {
},
handler: async (request, h) => {
if (request.query.appendItemToPayload) {
// Get item with ignoreInactive set to true (gets inactive or active item)
const item = await request.server.methods.db.item.getById(
request.query.appendItemToPayload
request.query.appendItemToPayload,
true
);
request.payload.item = item;
}
Expand Down
15 changes: 13 additions & 2 deletions plugins/core/rendering-info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,24 @@ module.exports = {
);
}

let toolEndpointConfig;

if (endpointConfig instanceof Function) {
toolEndpointConfig = await endpointConfig.apply(this, [
item,
requestToolRuntimeConfig
]);
} else {
toolEndpointConfig = endpointConfig;
}

// compile the toolRuntimeConfig from runtimeConfig from server, tool endpoint and request
const toolRuntimeConfig = getCompiledToolRuntimeConfig(item, {
serverWideToolRuntimeConfig: options.get("/toolRuntimeConfig", {
target: target,
tool: item.tool
}),
toolEndpointConfig: endpointConfig,
toolEndpointConfig: toolEndpointConfig,
requestToolRuntimeConfig: requestToolRuntimeConfig
});

Expand All @@ -194,7 +205,7 @@ module.exports = {
return await getRenderingInfo(
item,
baseUrl,
endpointConfig,
toolEndpointConfig,
toolRuntimeConfig,
itemStateInDb
);
Expand Down
36 changes: 31 additions & 5 deletions plugins/file/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const AWS = require("aws-sdk");
const uuid = require("uuid");
const Mimos = require("mimos");
const mimos = new Mimos();
const hasha = require("hasha");
const slugify = require("slugify");

function getDateString() {
const now = new Date();
Expand Down Expand Up @@ -79,11 +80,36 @@ module.exports = {
}

const type = mimos.type(contentType);

const extension = type.extensions[0] || "";
const filename = `${uuid.v4()}.${extension}`;

let fileKey = `${getDateString()}/${filename}`;
// buffer the contents to hash and later upload to s3
const fileBuffered = new Promise(resolve => {
let data = [];
file.on("data", d => {
data.push(d);
});
file.on("end", () => {
resolve(Buffer.concat(data));
});
});
const fileBuffer = await fileBuffered;

const hash = await hasha(fileBuffer, {
algorithm: "md5"
});

const filenameParts = file.hapi.filename.split(".");
// remove the extension by removing the last element of the array, we will add a normalized one based on the content-type
filenameParts.pop();
// add the hash to the last element after the split by . and the removing of the extension (this is the filename)
filenameParts[filenameParts.length - 1] = `${
filenameParts[filenameParts.length - 1]
}-${hash}`;
// join everything together again (appending the extension)
const hashedFilename = `${filenameParts
.map(filenamePart => slugify(filenamePart))
.join(".")}.${extension}`;
let fileKey = `${getDateString()}/${hashedFilename}`;

if (options.keyPrefix) {
fileKey = `${options.keyPrefix}${fileKey}`;
Expand All @@ -92,7 +118,7 @@ module.exports = {
const params = {
Bucket: options.s3Bucket,
Key: fileKey,
Body: file,
Body: fileBuffer,
ContentType: contentType
};

Expand Down
Loading

0 comments on commit e91fc31

Please sign in to comment.