Rename writeAttachmentData
to writeNewAttachmentData
This commit is contained in:
parent
36771a2dab
commit
efd673083d
7 changed files with 28 additions and 25 deletions
|
@ -43,10 +43,10 @@ exports.createReader = (root) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// createWriter :: AttachmentsPath ->
|
// createWriterForNew :: AttachmentsPath ->
|
||||||
// ArrayBuffer ->
|
// ArrayBuffer ->
|
||||||
// IO (Promise RelativePath)
|
// IO (Promise RelativePath)
|
||||||
exports.createWriter = (root) => {
|
exports.createWriterForNew = (root) => {
|
||||||
if (!isString(root)) {
|
if (!isString(root)) {
|
||||||
throw new TypeError('"root" must be a path');
|
throw new TypeError('"root" must be a path');
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,15 @@ const {
|
||||||
|
|
||||||
|
|
||||||
// type Context :: {
|
// type Context :: {
|
||||||
// writeAttachmentData :: ArrayBuffer -> Promise (IO Path)
|
// writeNewAttachmentData :: ArrayBuffer -> Promise (IO Path)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// migrateDataToFileSystem :: Attachment ->
|
// migrateDataToFileSystem :: Attachment ->
|
||||||
// Context ->
|
// Context ->
|
||||||
// Promise Attachment
|
// Promise Attachment
|
||||||
exports.migrateDataToFileSystem = async (attachment, { writeAttachmentData } = {}) => {
|
exports.migrateDataToFileSystem = async (attachment, { writeNewAttachmentData } = {}) => {
|
||||||
if (!isFunction(writeAttachmentData)) {
|
if (!isFunction(writeNewAttachmentData)) {
|
||||||
throw new TypeError('"writeAttachmentData" must be a function');
|
throw new TypeError('"writeNewAttachmentData" must be a function');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = attachment;
|
const { data } = attachment;
|
||||||
|
@ -32,7 +32,7 @@ exports.migrateDataToFileSystem = async (attachment, { writeAttachmentData } = {
|
||||||
` got: ${typeof attachment.data}`);
|
` got: ${typeof attachment.data}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = await writeAttachmentData(data);
|
const path = await writeNewAttachmentData(data);
|
||||||
|
|
||||||
const attachmentWithoutData = omit(
|
const attachmentWithoutData = omit(
|
||||||
Object.assign({}, attachment, { path }),
|
Object.assign({}, attachment, { path }),
|
||||||
|
|
|
@ -166,13 +166,13 @@ const toVersion3 = exports._withSchemaVersion(
|
||||||
);
|
);
|
||||||
|
|
||||||
// UpgradeStep
|
// UpgradeStep
|
||||||
exports.upgradeSchema = async (message, { writeAttachmentData } = {}) => {
|
exports.upgradeSchema = async (message, { writeNewAttachmentData } = {}) => {
|
||||||
if (!isFunction(writeAttachmentData)) {
|
if (!isFunction(writeNewAttachmentData)) {
|
||||||
throw new TypeError('`context.writeAttachmentData` is required');
|
throw new TypeError('`context.writeNewAttachmentData` is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
return toVersion3(
|
return toVersion3(
|
||||||
await toVersion2(await toVersion1(await toVersion0(message))),
|
await toVersion2(await toVersion1(await toVersion0(message))),
|
||||||
{ writeAttachmentData }
|
{ writeNewAttachmentData }
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -113,11 +113,11 @@ window.ProxyAgent = require('proxy-agent');
|
||||||
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
||||||
const deleteAttachmentData = Attachments.createDeleter(attachmentsPath);
|
const deleteAttachmentData = Attachments.createDeleter(attachmentsPath);
|
||||||
const readAttachmentData = Attachments.createReader(attachmentsPath);
|
const readAttachmentData = Attachments.createReader(attachmentsPath);
|
||||||
const writeAttachmentData = Attachments.createWriter(attachmentsPath);
|
const writeNewAttachmentData = Attachments.createWriterForNew(attachmentsPath);
|
||||||
|
|
||||||
// Injected context functions to keep `Message` agnostic from Electron:
|
// Injected context functions to keep `Message` agnostic from Electron:
|
||||||
const upgradeSchemaContext = {
|
const upgradeSchemaContext = {
|
||||||
writeAttachmentData,
|
writeNewAttachmentData,
|
||||||
};
|
};
|
||||||
const upgradeMessageSchema = message =>
|
const upgradeMessageSchema = message =>
|
||||||
Message.upgradeSchema(message, upgradeSchemaContext);
|
Message.upgradeSchema(message, upgradeSchemaContext);
|
||||||
|
|
|
@ -13,7 +13,7 @@ const NAME_LENGTH = 64;
|
||||||
const PATH_LENGTH = PREFIX_LENGTH + NUM_SEPARATORS + NAME_LENGTH;
|
const PATH_LENGTH = PREFIX_LENGTH + NUM_SEPARATORS + NAME_LENGTH;
|
||||||
|
|
||||||
describe('Attachments', () => {
|
describe('Attachments', () => {
|
||||||
describe('createWriter', () => {
|
describe('createWriterForNew', () => {
|
||||||
let tempRootDirectory = null;
|
let tempRootDirectory = null;
|
||||||
before(() => {
|
before(() => {
|
||||||
tempRootDirectory = tmp.dirSync().name;
|
tempRootDirectory = tmp.dirSync().name;
|
||||||
|
@ -25,9 +25,12 @@ describe('Attachments', () => {
|
||||||
|
|
||||||
it('should write file to disk and return path', async () => {
|
it('should write file to disk and return path', async () => {
|
||||||
const input = stringToArrayBuffer('test string');
|
const input = stringToArrayBuffer('test string');
|
||||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_createWriter');
|
const tempDirectory = path.join(
|
||||||
|
tempRootDirectory,
|
||||||
|
'Attachments_createWriterForNew'
|
||||||
|
);
|
||||||
|
|
||||||
const outputPath = await Attachments.createWriter(tempDirectory)(input);
|
const outputPath = await Attachments.createWriterForNew(tempDirectory)(input);
|
||||||
const output = await fse.readFile(path.join(tempDirectory, outputPath));
|
const output = await fse.readFile(path.join(tempDirectory, outputPath));
|
||||||
|
|
||||||
assert.lengthOf(outputPath, PATH_LENGTH);
|
assert.lengthOf(outputPath, PATH_LENGTH);
|
||||||
|
|
|
@ -120,14 +120,14 @@ describe('Attachment', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedAttachmentData = stringToArrayBuffer('Above us only sky');
|
const expectedAttachmentData = stringToArrayBuffer('Above us only sky');
|
||||||
const writeAttachmentData = async (attachmentData) => {
|
const writeNewAttachmentData = async (attachmentData) => {
|
||||||
assert.deepEqual(attachmentData, expectedAttachmentData);
|
assert.deepEqual(attachmentData, expectedAttachmentData);
|
||||||
return 'abc/abcdefgh123456789';
|
return 'abc/abcdefgh123456789';
|
||||||
};
|
};
|
||||||
|
|
||||||
const actual = await Attachment.migrateDataToFileSystem(
|
const actual = await Attachment.migrateDataToFileSystem(
|
||||||
input,
|
input,
|
||||||
{ writeAttachmentData }
|
{ writeNewAttachmentData }
|
||||||
);
|
);
|
||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
@ -145,12 +145,12 @@ describe('Attachment', () => {
|
||||||
size: 1111,
|
size: 1111,
|
||||||
};
|
};
|
||||||
|
|
||||||
const writeAttachmentData = async () =>
|
const writeNewAttachmentData = async () =>
|
||||||
'abc/abcdefgh123456789';
|
'abc/abcdefgh123456789';
|
||||||
|
|
||||||
const actual = await Attachment.migrateDataToFileSystem(
|
const actual = await Attachment.migrateDataToFileSystem(
|
||||||
input,
|
input,
|
||||||
{ writeAttachmentData }
|
{ writeNewAttachmentData }
|
||||||
);
|
);
|
||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
@ -163,11 +163,11 @@ describe('Attachment', () => {
|
||||||
size: 1111,
|
size: 1111,
|
||||||
};
|
};
|
||||||
|
|
||||||
const writeAttachmentData = async () =>
|
const writeNewAttachmentData = async () =>
|
||||||
'abc/abcdefgh123456789';
|
'abc/abcdefgh123456789';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Attachment.migrateDataToFileSystem(input, { writeAttachmentData });
|
await Attachment.migrateDataToFileSystem(input, { writeNewAttachmentData });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
error.message,
|
error.message,
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe('Message', () => {
|
||||||
|
|
||||||
const expectedAttachmentData = stringToArrayBuffer('It’s easy if you try');
|
const expectedAttachmentData = stringToArrayBuffer('It’s easy if you try');
|
||||||
const context = {
|
const context = {
|
||||||
writeAttachmentData: async (attachmentData) => {
|
writeNewAttachmentData: async (attachmentData) => {
|
||||||
assert.deepEqual(attachmentData, expectedAttachmentData);
|
assert.deepEqual(attachmentData, expectedAttachmentData);
|
||||||
return 'abc/abcdefg';
|
return 'abc/abcdefg';
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue