diff --git a/app/types/attachment/write_attachment_data.js b/app/types/attachment/write_attachment_data.js index 99a8cfb0cb..7a595e94f9 100644 --- a/app/types/attachment/write_attachment_data.js +++ b/app/types/attachment/write_attachment_data.js @@ -1,8 +1,8 @@ const crypto = require('crypto'); -const FSE = require('fs-extra'); +const fse = require('fs-extra'); const isArrayBuffer = require('lodash/isArrayBuffer'); const isString = require('lodash/isString'); -const Path = require('path'); +const path = require('path'); // _writeAttachmentData :: AttachmentsPath -> @@ -19,10 +19,11 @@ exports.writeAttachmentData = (root) => { } const buffer = Buffer.from(arrayBuffer); - const path = Path.join(root, exports._getAttachmentPath()); - await FSE.ensureFile(path); - await FSE.writeFile(path, buffer); - return path; + const relativePath = exports._getAttachmentPath(); + const absolutePath = path.join(root, relativePath); + await fse.ensureFile(absolutePath); + await fse.writeFile(absolutePath, buffer); + return relativePath; }; }; @@ -36,5 +37,5 @@ exports._getAttachmentName = () => { exports._getAttachmentPath = () => { const name = exports._getAttachmentName(); const prefix = name.slice(0, 2); - return Path.join(prefix, name); + return path.join(prefix, name); }; diff --git a/js/modules/types/message.js b/js/modules/types/message.js index 5df444c8ff..01cb67db53 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -18,6 +18,7 @@ const PRIVATE = 'private'; // - Attachments: Sanitize Unicode order override characters. // Version 3 // - Attachments: Write attachment data to disk and store relative path to it. + const INITIAL_SCHEMA_VERSION = 0; // Increment this version number every time we add a message schema upgrade diff --git a/test/app/types/attachment/write_attachment_data_test.js b/test/app/types/attachment/write_attachment_data_test.js index ae7d768d52..1e00664e1a 100644 --- a/test/app/types/attachment/write_attachment_data_test.js +++ b/test/app/types/attachment/write_attachment_data_test.js @@ -1,6 +1,6 @@ -const FSE = require('fs-extra'); +const fse = require('fs-extra'); const isEqual = require('lodash/isEqual'); -const Path = require('path'); +const path = require('path'); const stringToArrayBuffer = require('string-to-arraybuffer'); const tmp = require('tmp'); const { assert } = require('chai'); @@ -24,17 +24,17 @@ describe('writeAttachmentData', () => { }); after(async () => { - await FSE.remove(TEMPORARY_DIRECTORY); + await fse.remove(TEMPORARY_DIRECTORY); }); it('should write file to disk and return path', async () => { const input = stringToArrayBuffer('test string'); - const tempDirectory = Path.join(TEMPORARY_DIRECTORY, 'writeAttachmentData'); + const tempDirectory = path.join(TEMPORARY_DIRECTORY, 'writeAttachmentData'); const outputPath = await writeAttachmentData(tempDirectory)(input); - const output = await FSE.readFile(outputPath); + const output = await fse.readFile(path.join(tempDirectory, outputPath)); - assert.lengthOf(Path.relative(tempDirectory, outputPath), PATH_LENGTH); + assert.lengthOf(outputPath, PATH_LENGTH); const inputBuffer = Buffer.from(input); assert.isTrue(isEqual(inputBuffer, output));