1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 07:39:44 +02:00

feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev 2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions

View file

@ -0,0 +1,73 @@
/*!
* 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,
);
});
sails.helpers.utils.sendWebhooks.with({
event: 'backgroundImageCreate',
buildData: () => ({
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
included: {
projects: [values.project],
},
}),
user: inputs.actorUser,
});
await sails.helpers.projects.updateOne.with({
scoper,
record: values.project,
values: {
backgroundImage,
backgroundType: Project.BackgroundTypes.IMAGE,
},
actorUser: inputs.actorUser,
});
return backgroundImage;
},
};

View file

@ -0,0 +1,75 @@
/*!
* 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,
});
if (inputs.project.backgroundType === Project.BackgroundTypes.IMAGE) {
if (inputs.record.id === inputs.project.backgroundImageId) {
await sails.helpers.projects.updateOne.with({
scoper,
record: inputs.project,
values: {
backgroundType: null,
},
actorUser: inputs.actorUser,
});
}
}
const backgroundImage = await BackgroundImage.qm.deleteOne(inputs.record.id);
if (backgroundImage) {
sails.helpers.backgroundImages.removeRelatedFiles(backgroundImage);
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({
event: 'backgroundImageDelete',
buildData: () => ({
item: sails.helpers.backgroundImages.presentOne(backgroundImage),
included: {
projects: [inputs.project],
},
}),
user: inputs.actorUser,
});
}
return backgroundImage;
},
};

View file

@ -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,
};
},
};

View file

@ -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));
},
};

View file

@ -0,0 +1,27 @@
/*!
* 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) {
const fileManager = sails.hooks['file-manager'].getInstance();
return {
..._.omit(inputs.record, ['dirname', 'extension']),
url: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.dirname}/original.${inputs.record.extension}`)}`,
thumbnailUrls: {
outside360: `${fileManager.buildUrl(`${sails.config.custom.backgroundImagesPathSegment}/${inputs.record.dirname}/outside-360.${inputs.record.extension}`)}`,
},
};
},
};

View file

@ -0,0 +1,97 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { rimraf } = require('rimraf');
const mime = require('mime');
const { v4: uuid } = require('uuid');
const sharp = require('sharp');
module.exports = {
inputs: {
file: {
type: 'json',
required: true,
},
},
exits: {
fileIsNotImage: {},
},
async fn(inputs) {
const mimeType = mime.getType(inputs.file.filename);
if (['image/svg+xml', 'application/pdf'].includes(mimeType)) {
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';
}
const fileManager = sails.hooks['file-manager'].getInstance();
const dirname = uuid();
const dirPathSegment = `${sails.config.custom.backgroundImagesPathSegment}/${dirname}`;
if (metadata.orientation && metadata.orientation > 4) {
image = image.rotate();
}
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
let sizeInBytes;
try {
const originalBuffer = await image.toBuffer();
sizeInBytes = originalBuffer.length;
await fileManager.save(
`${dirPathSegment}/original.${extension}`,
originalBuffer,
inputs.file.type,
);
const outside360Buffer = await image
.resize(360, 360, {
fit: 'outside',
withoutEnlargement: true,
})
.png({
quality: 75,
force: false,
})
.toBuffer();
await fileManager.save(
`${dirPathSegment}/outside-360.${extension}`,
outside360Buffer,
inputs.file.type,
);
} catch (error) {
sails.log.warn(error.stack);
await fileManager.deleteDir(dirPathSegment);
await rimraf(inputs.file.fd);
throw 'fileIsNotImage';
}
await rimraf(inputs.file.fd);
return {
dirname,
extension,
sizeInBytes,
};
},
};

View file

@ -0,0 +1,29 @@
/*!
* 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: {
recordOrRecords: {
type: 'ref',
required: true,
},
},
fn(inputs) {
const backgroundImages = _.isPlainObject(inputs.recordOrRecords)
? [inputs.recordOrRecords]
: inputs.recordOrRecords;
const fileManager = sails.hooks['file-manager'].getInstance();
backgroundImages.forEach(async (backgroundImage) => {
await fileManager.deleteDir(
`${sails.config.custom.backgroundImagesPathSegment}/${backgroundImage.dirname}`,
);
});
},
};