Move client-relative path logic to helper function

This commit is contained in:
valadaptive
2023-12-05 18:04:32 -05:00
parent 39d771cc4a
commit 5096e70c11
4 changed files with 18 additions and 9 deletions

View File

@ -288,6 +288,16 @@ function tryParse(str) {
}
}
/**
* Takes a path to a client-accessible file in the `public` folder and converts it to a relative URL segment that the
* client can fetch it from. This involves stripping the `public/` prefix and always using `/` as the separator.
* @param {string} inputPath The path to be converted.
* @returns The relative URL path from which the client can access the file.
*/
function clientRelativePath(inputPath) {
return path.normalize(inputPath).split(path.sep).slice(1).join('/');
}
module.exports = {
getConfig,
getConfigValue,
@ -302,4 +312,5 @@ module.exports = {
uuidv4,
humanizedISO8601DateTime,
tryParse,
clientRelativePath,
};