diff --git a/migrations/20200401_increase_path_length_attachments.sql b/migrations/20200401_increase_path_length_attachments.sql new file mode 100644 index 00000000..e80ff7d0 --- /dev/null +++ b/migrations/20200401_increase_path_length_attachments.sql @@ -0,0 +1,4 @@ +-- UPDATE EXISTING project_attachments table +-- modify column `path` + +ALTER TABLE project_attachments ALTER COLUMN "path" TYPE character varying(2048); \ No newline at end of file diff --git a/src/models/projectAttachment.js b/src/models/projectAttachment.js index 1dcd56c5..42abfa7c 100644 --- a/src/models/projectAttachment.js +++ b/src/models/projectAttachment.js @@ -17,7 +17,7 @@ module.exports = function defineProjectAttachment(sequelize, DataTypes) { size: { type: DataTypes.INTEGER, allowNull: true }, // size in MB category: { type: DataTypes.STRING, allowNull: true }, // size in MB description: { type: DataTypes.STRING, allowNull: true }, - path: { type: DataTypes.STRING, allowNull: false }, + path: { type: DataTypes.STRING(2048), allowNull: false }, contentType: { type: DataTypes.STRING, allowNull: true }, allowedUsers: DataTypes.ARRAY({ type: DataTypes.INTEGER, allowNull: true }), deletedAt: { type: DataTypes.DATE, allowNull: true }, diff --git a/src/routes/attachments/get.js b/src/routes/attachments/get.js index ef6e562a..bd5081f6 100644 --- a/src/routes/attachments/get.js +++ b/src/routes/attachments/get.js @@ -19,17 +19,20 @@ const permissions = tcMiddleware.permissions; * @returns {Array} The array of two promises, first one if the attachment object promise, * The second promise is for the file pre-signed url (if attachment type is file) */ -const getPreSignedUrl = (req, attachment) => { +const getPreSignedUrl = async (req, attachment) => { + // If the attachment is a link return it as-is without getting the pre-signed url if (attachment.type === ATTACHMENT_TYPES.LINK) { - // If the attachment is a link return it as-is without getting the pre-signed url return [attachment, '']; - } // The attachment is a file - // In development/test mode, if file upload is disabled, we return the dummy attachment object - if (_.includes(['development', 'test'], process.env.NODE_ENV) && config.get('enableFileUpload') === 'false') { + } + + // The attachment is a file + // In development mode, if file upload is disabled, we return the dummy attachment object + if (_.includes(['development'], process.env.NODE_ENV) && config.get('enableFileUpload') === 'false') { return [attachment, 'dummy://url']; } - // Not in development mode or file upload is not disabled - return [attachment, util.getFileDownloadUrl(req, attachment.path)]; + // Not in development mode or file upload is not disabled + const url = await util.getFileDownloadUrl(req, attachment.path); + return [attachment, url]; }; module.exports = [