Return relative path from writeAttachmentData
This will make our app more robust to changes in location on the file system.
This commit is contained in:
parent
1262d1d696
commit
6355c54114
3 changed files with 15 additions and 13 deletions
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue