-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract code used by both custom files to one function
- Loading branch information
Showing
4 changed files
with
57 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { pathExists } from "fs-extra"; | ||
import { join } from "path"; | ||
|
||
import { createHash } from "@utils/createHash"; | ||
import settings from "@utils/settings"; | ||
|
||
interface CustomFilesPathObject { | ||
filepath: string; | ||
exists: boolean; | ||
} | ||
|
||
/** | ||
* Creates a path to store an url | ||
* Also says if the file already exists | ||
* | ||
* @param url The url to create a filepath for | ||
* @param type The extension and folder of the file | ||
* @returns An Promise<object> containing the filepath and if it the file already exists | ||
*/ | ||
|
||
export const customFilesHelper = async ( | ||
url: string, | ||
type: "css" | "js" | ||
): Promise<CustomFilesPathObject> => { | ||
const urlHash = createHash(url); | ||
const filepath = join(settings.customFilesPath, type, `${urlHash}.${type}`); | ||
|
||
return { | ||
filepath, | ||
exists: await pathExists(filepath) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters