import Planka upstream
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
requestId: {
|
||||
type: 'string',
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const backgroundImage = await BackgroundImage.qm.createOne({
|
||||
...values,
|
||||
projectId: values.project.id,
|
||||
});
|
||||
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: values.project,
|
||||
});
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'backgroundImageCreate',
|
||||
{
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
requestId: inputs.requestId,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.BACKGROUND_IMAGE_CREATE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
included: {
|
||||
projects: [values.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
|
||||
await sails.helpers.projects.updateOne.with({
|
||||
scoper,
|
||||
webhooks,
|
||||
record: values.project,
|
||||
values: {
|
||||
backgroundImage,
|
||||
backgroundType: Project.BackgroundTypes.IMAGE,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
});
|
||||
|
||||
return backgroundImage;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
project: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
actorUser: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const scoper = sails.helpers.projects.makeScoper.with({
|
||||
record: inputs.project,
|
||||
});
|
||||
|
||||
const webhooks = await Webhook.qm.getAll();
|
||||
|
||||
if (inputs.project.backgroundType === Project.BackgroundTypes.IMAGE) {
|
||||
if (inputs.record.id === inputs.project.backgroundImageId) {
|
||||
await sails.helpers.projects.updateOne.with({
|
||||
scoper,
|
||||
webhooks,
|
||||
record: inputs.project,
|
||||
values: {
|
||||
backgroundType: null,
|
||||
},
|
||||
actorUser: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const { backgroundImage, uploadedFile } = await BackgroundImage.qm.deleteOne(inputs.record.id);
|
||||
|
||||
if (backgroundImage) {
|
||||
sails.helpers.utils.removeUnreferencedUploadedFiles(uploadedFile);
|
||||
|
||||
const projectRelatedUserIds = await scoper.getProjectRelatedUserIds();
|
||||
|
||||
projectRelatedUserIds.forEach((userId) => {
|
||||
sails.sockets.broadcast(
|
||||
`user:${userId}`,
|
||||
'backgroundImageDelete',
|
||||
{
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
});
|
||||
|
||||
sails.helpers.utils.sendWebhooks.with({
|
||||
webhooks,
|
||||
event: Webhook.Events.BACKGROUND_IMAGE_DELETE,
|
||||
buildData: () => ({
|
||||
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
},
|
||||
}),
|
||||
user: inputs.actorUser,
|
||||
});
|
||||
}
|
||||
|
||||
return backgroundImage;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
id: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
pathNotFound: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const backgroundImage = await BackgroundImage.qm.getOneById(inputs.id);
|
||||
|
||||
if (!backgroundImage) {
|
||||
throw 'pathNotFound';
|
||||
}
|
||||
|
||||
const project = await Project.qm.getOneById(backgroundImage.projectId);
|
||||
|
||||
if (!project) {
|
||||
throw {
|
||||
pathNotFound: {
|
||||
backgroundImage,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
backgroundImage,
|
||||
project,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
records: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return inputs.records.map((record) => sails.helpers.backgroundImages.presentOne(record));
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
return {
|
||||
..._.omit(inputs.record, ['uploadedFileId', 'extension']),
|
||||
url: `${sails.config.custom.baseUrl}/background-images/${inputs.record.uploadedFileId}/original.${inputs.record.extension}`,
|
||||
thumbnailUrls: {
|
||||
outside360: `${sails.config.custom.baseUrl}/background-images/${inputs.record.uploadedFileId}/outside-360.${inputs.record.extension}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,101 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const { v4: uuid } = require('uuid');
|
||||
const { rimraf } = require('rimraf');
|
||||
const { fileTypeFromFile } = require('file-type');
|
||||
const sharp = require('sharp');
|
||||
|
||||
const { MAX_SIZE_TO_PROCESS_AS_IMAGE } = require('../../../constants');
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
file: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
exits: {
|
||||
fileIsNotImage: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const fileManager = sails.hooks['file-manager'].getInstance();
|
||||
|
||||
const fileType = await fileTypeFromFile(inputs.file.fd);
|
||||
const { mime: mimeType = null } = fileType || {};
|
||||
const { size } = inputs.file;
|
||||
|
||||
if (!mimeType || !mimeType.startsWith('image/') || size > MAX_SIZE_TO_PROCESS_AS_IMAGE) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
let image = sharp(inputs.file.fd, {
|
||||
animated: true,
|
||||
});
|
||||
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await image.metadata();
|
||||
} catch (error) {
|
||||
await rimraf(inputs.file.fd);
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
if (metadata.orientation && metadata.orientation > 4) {
|
||||
image = image.rotate();
|
||||
}
|
||||
|
||||
const { id: uploadedFileId } = await UploadedFile.qm.createOne({
|
||||
mimeType,
|
||||
size,
|
||||
id: uuid(),
|
||||
type: UploadedFile.Types.BACKGROUND_IMAGE,
|
||||
});
|
||||
|
||||
const dirPathSegment = `${sails.config.custom.backgroundImagesPathSegment}/${uploadedFileId}`;
|
||||
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
|
||||
|
||||
const outside360 = image
|
||||
.clone()
|
||||
.resize(360, 360, {
|
||||
fit: 'outside',
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.png({
|
||||
quality: 75,
|
||||
force: false,
|
||||
});
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
fileManager.save(`${dirPathSegment}/original.${extension}`, image, inputs.file.type),
|
||||
fileManager.save(
|
||||
`${dirPathSegment}/outside-360.${extension}`,
|
||||
outside360,
|
||||
inputs.file.type,
|
||||
),
|
||||
]);
|
||||
} catch (error) {
|
||||
sails.log.warn(error.stack);
|
||||
|
||||
await fileManager.deleteDir(dirPathSegment);
|
||||
await rimraf(inputs.file.fd);
|
||||
await UploadedFile.qm.deleteOne(uploadedFileId);
|
||||
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
await rimraf(inputs.file.fd);
|
||||
|
||||
return {
|
||||
uploadedFileId,
|
||||
extension,
|
||||
size,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user