1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19:44 +02:00
planka/server/api/helpers/delete-attachment.js

42 lines
820 B
JavaScript
Raw Normal View History

2020-04-21 05:04:34 +05:00
const path = require('path');
const rimraf = require('rimraf');
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs, exits) {
const attachment = await Attachment.archiveOne(inputs.record.id);
if (attachment) {
try {
rimraf.sync(path.join(sails.config.custom.attachmentsPath, attachment.dirname));
} catch (error) {
console.warn(error.stack); // eslint-disable-line no-console
}
sails.sockets.broadcast(
`board:${inputs.board.id}`,
'attachmentDelete',
{
item: attachment,
},
inputs.request,
);
}
return exits.success(attachment);
},
};