mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
feat: Add gallery for attachments
This commit is contained in:
parent
0bf4004046
commit
8f4d60c46f
22 changed files with 351 additions and 102 deletions
|
@ -1,5 +1,5 @@
|
|||
module.exports.up = (knex) =>
|
||||
knex.schema.createTable('card', (table) => {
|
||||
knex.schema.createTable('card', async (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.bigInteger('id').primary().defaultTo(knex.raw('next_id()'));
|
||||
|
@ -12,7 +12,7 @@ module.exports.up = (knex) =>
|
|||
table.specificType('position', 'double precision');
|
||||
table.text('name').notNullable();
|
||||
table.text('description');
|
||||
table.timestamp('dueDate', true);
|
||||
table.timestamp('due_date', true);
|
||||
table.jsonb('timer');
|
||||
|
||||
table.timestamp('created_at', true);
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
const path = require('path');
|
||||
const sharp = require('sharp');
|
||||
|
||||
const getConfig = require('../../get-config');
|
||||
|
||||
module.exports.up = async (knex) => {
|
||||
await knex.schema.table('attachment', (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.integer('image_width');
|
||||
table.integer('image_height');
|
||||
});
|
||||
|
||||
const config = await getConfig();
|
||||
const attachments = await knex('attachment');
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (attachment of attachments) {
|
||||
if (attachment.is_image) {
|
||||
const image = sharp(
|
||||
path.join(config.custom.attachmentsPath, attachment.dirname, attachment.filename),
|
||||
);
|
||||
|
||||
let metadata;
|
||||
try {
|
||||
metadata = await image.metadata(); // eslint-disable-line no-await-in-loop
|
||||
} catch (error) {
|
||||
continue; // eslint-disable-line no-continue
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await knex('attachment')
|
||||
.update({
|
||||
image_width: metadata.width,
|
||||
image_height: metadata.height,
|
||||
})
|
||||
.where('id', attachment.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.down = (knex) =>
|
||||
knex.schema.table('attachment', (table) => {
|
||||
table.dropColumns('image_width', 'image_height');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue