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
|
@ -24,6 +24,16 @@ module.exports = {
|
|||
required: true,
|
||||
columnName: 'is_image',
|
||||
},
|
||||
imageWidth: {
|
||||
type: 'number',
|
||||
allowNull: true,
|
||||
columnName: 'image_width',
|
||||
},
|
||||
imageHeight: {
|
||||
type: 'number',
|
||||
allowNull: true,
|
||||
columnName: 'image_height',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
|
|
|
@ -20,20 +20,24 @@
|
|||
* https://sailsjs.com/anatomy/app.js
|
||||
*/
|
||||
|
||||
require('dotenv').config();
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
// Ensure we're in the project directory, so cwd-relative paths work as expected
|
||||
// no matter where we actually lift from.
|
||||
// > Note: This is not required in order to lift, but it is a convenient default.
|
||||
process.chdir(__dirname);
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Attempt to import `sails` dependency, as well as `rc` (for loading `.sailsrc` files).
|
||||
let sails;
|
||||
let rc;
|
||||
|
||||
try {
|
||||
sails = require('sails'); // eslint-disable-line global-require
|
||||
rc = require('sails/accessible/rc'); // eslint-disable-line global-require
|
||||
/* eslint-disable global-require */
|
||||
sails = require('sails');
|
||||
rc = require('sails/accessible/rc');
|
||||
/* eslint-enable global-require */
|
||||
} catch (error) {
|
||||
/* eslint-disable no-console */
|
||||
console.error("Encountered an error when attempting to require('sails'):");
|
||||
|
|
7
server/config/env/production.js
vendored
7
server/config/env/production.js
vendored
|
@ -321,4 +321,11 @@ module.exports = {
|
|||
// baseUrl: 'https://example.com',
|
||||
// internalEmailAddress: 'support@example.com',
|
||||
},
|
||||
|
||||
routes: {
|
||||
'GET /*': {
|
||||
view: 'index',
|
||||
skipAssets: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -84,9 +84,4 @@ module.exports.routes = {
|
|||
action: 'attachments/download-thumbnail',
|
||||
skipAssets: false,
|
||||
},
|
||||
|
||||
'GET /*': {
|
||||
view: 'index',
|
||||
skipAssets: true,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
const config = require('./knexfile');
|
||||
const initKnex = require('knex');
|
||||
|
||||
const knex = require('knex')(config); // eslint-disable-line import/order
|
||||
const knexfile = require('./knexfile');
|
||||
|
||||
const knex = initKnex(knexfile);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const isExists = await knex.schema.hasTable(config.migrations.tableName);
|
||||
const isExists = await knex.schema.hasTable(knexfile.migrations.tableName);
|
||||
|
||||
await knex.migrate.latest();
|
||||
if (!isExists) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const path = require('path');
|
||||
const dotenv = require('dotenv');
|
||||
const _ = require('lodash');
|
||||
|
||||
require('dotenv').config({
|
||||
dotenv.config({
|
||||
path: path.resolve(__dirname, '../.env'),
|
||||
});
|
||||
|
||||
|
|
|
@ -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');
|
||||
});
|
38
server/get-config.js
Normal file
38
server/get-config.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const dotenv = require('dotenv');
|
||||
const sails = require('sails');
|
||||
const rc = require('sails/accessible/rc');
|
||||
|
||||
process.chdir(__dirname);
|
||||
dotenv.config();
|
||||
|
||||
const config = rc('sails');
|
||||
|
||||
const getConfigPromise = new Promise((resolve) => {
|
||||
sails.load(
|
||||
{
|
||||
...config,
|
||||
hooks: {
|
||||
...config.hooks,
|
||||
logger: false,
|
||||
request: false,
|
||||
views: false,
|
||||
blueprints: false,
|
||||
responses: false,
|
||||
helpers: false,
|
||||
pubsub: false,
|
||||
policies: false,
|
||||
services: false,
|
||||
security: false,
|
||||
i18n: false,
|
||||
session: false,
|
||||
http: false,
|
||||
userhooks: false,
|
||||
},
|
||||
},
|
||||
() => {
|
||||
resolve(sails.config);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = () => getConfigPromise;
|
Loading…
Add table
Add a link
Reference in a new issue