1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/models/Attachment.js

77 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-04-21 05:04:34 +05:00
/**
* Attachment.js
*
* @description :: A model definition represents a database table/collection.
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
module.exports = {
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
dirname: {
type: 'string',
required: true,
},
filename: {
type: 'string',
required: true,
},
image: {
type: 'json',
2022-06-20 18:27:39 +02:00
},
2020-04-21 05:04:34 +05:00
name: {
type: 'string',
required: true,
},
2024-11-09 18:49:26 +07:00
type: {
type: 'string',
},
url: {
type: 'string',
},
thumb: {
type: 'string',
},
2020-04-21 05:04:34 +05:00
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
cardId: {
model: 'Card',
required: true,
columnName: 'card_id',
},
creatorUserId: {
2020-04-23 03:02:53 +05:00
model: 'User',
required: true,
columnName: 'creator_user_id',
2020-04-23 03:02:53 +05:00
},
2020-04-21 05:04:34 +05:00
},
customToJSON() {
2024-11-09 18:49:26 +07:00
let { url, thumb } = this;
if (!url) {
url = `${sails.config.custom.attachmentsUrl}/${this.id}/download/${this.filename}`;
}
if (!thumb) {
thumb = this.image
? `${sails.config.custom.attachmentsUrl}/${this.id}/download/thumbnails/cover-256.${this.image.thumbnailsExtension}`
2024-11-09 18:49:26 +07:00
: null;
}
return {
..._.omit(this, ['type', 'dirname', 'filename', 'image.thumbnailsExtension']),
url,
coverUrl: thumb,
2020-04-21 05:04:34 +05:00
};
},
};