DRY out path getters
This commit is contained in:
parent
d372b47617
commit
0b57bcd36c
1 changed files with 9 additions and 29 deletions
|
@ -79,40 +79,20 @@ export const getBuiltInImages = async (): Promise<ReadonlyArray<string>> => {
|
||||||
return map(files, file => relative(dir, file));
|
return map(files, file => relative(dir, file));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPath = (userDataPath: string): string => {
|
const createPathGetter = (subpath: string) => (
|
||||||
|
userDataPath: string
|
||||||
|
): string => {
|
||||||
if (!isString(userDataPath)) {
|
if (!isString(userDataPath)) {
|
||||||
throw new TypeError("'userDataPath' must be a string");
|
throw new TypeError("'userDataPath' must be a string");
|
||||||
}
|
}
|
||||||
return join(userDataPath, PATH);
|
return join(userDataPath, subpath);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAvatarsPath = (userDataPath: string): string => {
|
export const getAvatarsPath = createPathGetter(AVATAR_PATH);
|
||||||
if (!isString(userDataPath)) {
|
export const getDraftPath = createPathGetter(DRAFT_PATH);
|
||||||
throw new TypeError("'userDataPath' must be a string");
|
export const getPath = createPathGetter(PATH);
|
||||||
}
|
export const getStickersPath = createPathGetter(STICKER_PATH);
|
||||||
return join(userDataPath, AVATAR_PATH);
|
export const getTempPath = createPathGetter(TEMP_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 clearTempPath = (userDataPath: string): Promise<void> => {
|
export const clearTempPath = (userDataPath: string): Promise<void> => {
|
||||||
const tempPath = getTempPath(userDataPath);
|
const tempPath = getTempPath(userDataPath);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue