From 0b57bcd36c23c8b2370078f2e57f9489599633a4 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:24:03 -0500 Subject: [PATCH] DRY out path getters --- app/attachments.ts | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/app/attachments.ts b/app/attachments.ts index 6be80698aa20..dfb5c02df430 100644 --- a/app/attachments.ts +++ b/app/attachments.ts @@ -79,40 +79,20 @@ export const getBuiltInImages = async (): Promise> => { return map(files, file => relative(dir, file)); }; -export const getPath = (userDataPath: string): string => { +const createPathGetter = (subpath: string) => ( + userDataPath: string +): string => { if (!isString(userDataPath)) { throw new TypeError("'userDataPath' must be a string"); } - return join(userDataPath, PATH); + return join(userDataPath, subpath); }; -export const getAvatarsPath = (userDataPath: string): string => { - if (!isString(userDataPath)) { - throw new TypeError("'userDataPath' must be a string"); - } - return join(userDataPath, AVATAR_PATH); -}; - -export const getStickersPath = (userDataPath: string): string => { - if (!isString(userDataPath)) { - throw new TypeError("'userDataPath' must be a string"); - } - return join(userDataPath, STICKER_PATH); -}; - -export const getTempPath = (userDataPath: string): string => { - if (!isString(userDataPath)) { - throw new TypeError("'userDataPath' must be a string"); - } - return join(userDataPath, TEMP_PATH); -}; - -export const getDraftPath = (userDataPath: string): string => { - if (!isString(userDataPath)) { - throw new TypeError("'userDataPath' must be a string"); - } - return join(userDataPath, DRAFT_PATH); -}; +export const getAvatarsPath = createPathGetter(AVATAR_PATH); +export const getDraftPath = createPathGetter(DRAFT_PATH); +export const getPath = createPathGetter(PATH); +export const getStickersPath = createPathGetter(STICKER_PATH); +export const getTempPath = createPathGetter(TEMP_PATH); export const clearTempPath = (userDataPath: string): Promise => { const tempPath = getTempPath(userDataPath);