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

ref: Collapse image data into one column

This commit is contained in:
Maksim Eltyshev 2022-06-21 12:01:41 +02:00
parent fe9fdc0191
commit 39fec45a7f
10 changed files with 102 additions and 86 deletions

View file

@ -54,10 +54,8 @@ module.exports = {
const attachment = await sails.helpers.attachments.createOne(
{
dirname: file.extra.dirname,
...file.extra,
filename: file.filename,
isImage: file.extra.isImage,
name: file.extra.name,
},
currentUser,
card,

View file

@ -46,7 +46,7 @@ module.exports = {
}
}
if (!attachment.isImage) {
if (!attachment.image) {
throw Errors.ATTACHMENT_NOT_FOUND;
}

View file

@ -53,7 +53,7 @@ module.exports = {
}
this.res.type(attachment.filename);
if (!attachment.isImage && path.extname(attachment.filename) !== '.pdf') {
if (!attachment.image && path.extname(attachment.filename) !== '.pdf') {
this.res.set('Content-Disposition', 'attachment');
}
this.res.set('Cache-Control', 'private, max-age=900'); // TODO: move to config

View file

@ -38,7 +38,7 @@ module.exports = {
inputs.request,
);
if (!inputs.card.coverAttachmentId && attachment.isImage) {
if (!inputs.card.coverAttachmentId && attachment.image) {
await sails.helpers.cards.updateOne(inputs.card, {
coverAttachmentId: attachment.id,
});

View file

@ -43,15 +43,20 @@ module.exports = {
await writeFile(path.join(rootPath, filename), buffer);
const image = sharp(buffer);
let imageMetadata;
let metadata;
try {
imageMetadata = await image.metadata();
metadata = await image.metadata();
} catch (error) {} // eslint-disable-line no-empty
if (imageMetadata) {
const extra = {
dirname,
name: file.filename,
};
if (metadata && !['svg', 'pdf'].includes(metadata.format)) {
let cover256Buffer;
if (imageMetadata.height > imageMetadata.width) {
if (metadata.height > metadata.width) {
cover256Buffer = await image
.resize(256, 320)
.jpeg({
@ -75,17 +80,16 @@ module.exports = {
fs.mkdirSync(thumbnailsPath);
await writeFile(path.join(thumbnailsPath, 'cover-256.jpg'), cover256Buffer);
extra.image = _.pick(metadata, ['width', 'height']);
} else {
extra.image = null;
}
// eslint-disable-next-line no-param-reassign
file.extra = {
dirname,
isImage: !!imageMetadata,
name: file.filename,
};
// eslint-disable-next-line no-param-reassign
file.filename = filename;
Object.assign(file, {
filename,
extra,
});
return done();
} catch (error) {

View file

@ -19,20 +19,8 @@ module.exports = {
type: 'string',
required: true,
},
isImage: {
type: 'boolean',
required: true,
columnName: 'is_image',
},
imageWidth: {
type: 'number',
allowNull: true,
columnName: 'image_width',
},
imageHeight: {
type: 'number',
allowNull: true,
columnName: 'image_height',
image: {
type: 'json',
},
name: {
type: 'string',
@ -61,9 +49,9 @@ module.exports = {
customToJSON() {
return {
..._.omit(this, ['dirname', 'filename', 'isImage']),
..._.omit(this, ['dirname', 'filename']),
url: `${sails.config.custom.attachmentsUrl}/${this.id}/download/${this.filename}`,
coverUrl: this.isImage
coverUrl: this.image
? `${sails.config.custom.attachmentsUrl}/${this.id}/download/thumbnails/cover-256.jpg`
: null,
};