mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Use declarations style for functions.
This commit is contained in:
@@ -14,8 +14,9 @@ const logger = getLoggerFor('MapperUtil');
|
||||
*
|
||||
* @returns Absolute path of the file.
|
||||
*/
|
||||
export const getAbsolutePath = (rootFilepath: string, path: string, identifier = ''): string =>
|
||||
joinFilePath(rootFilepath, path, identifier);
|
||||
export function getAbsolutePath(rootFilepath: string, path: string, identifier = ''): string {
|
||||
return joinFilePath(rootFilepath, path, identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the baseRequestURI from the identifier and checks if the stripped base URI matches the store's one.
|
||||
@@ -27,13 +28,13 @@ export const getAbsolutePath = (rootFilepath: string, path: string, identifier =
|
||||
*
|
||||
* @returns A string representing the relative path.
|
||||
*/
|
||||
export const getRelativePath = (baseRequestURI: string, identifier: ResourceIdentifier): string => {
|
||||
export function getRelativePath(baseRequestURI: string, identifier: ResourceIdentifier): string {
|
||||
if (!identifier.path.startsWith(baseRequestURI)) {
|
||||
logger.warn(`The URL ${identifier.path} is outside of the scope ${baseRequestURI}`);
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
return decodeUriPathComponents(identifier.path.slice(baseRequestURI.length));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given relative path is valid.
|
||||
@@ -44,7 +45,7 @@ export const getRelativePath = (baseRequestURI: string, identifier: ResourceIden
|
||||
* @param path - A relative path, as generated by {@link getRelativePath}.
|
||||
* @param identifier - A resource identifier.
|
||||
*/
|
||||
export const validateRelativePath = (path: string, identifier: ResourceIdentifier): void => {
|
||||
export function validateRelativePath(path: string, identifier: ResourceIdentifier): void {
|
||||
if (!path.startsWith('/')) {
|
||||
logger.warn(`URL ${identifier.path} needs a / after the base`);
|
||||
throw new BadRequestHttpError('URL needs a / after the base');
|
||||
@@ -54,4 +55,4 @@ export const validateRelativePath = (path: string, identifier: ResourceIdentifie
|
||||
logger.warn(`Disallowed /.. segment in URL ${identifier.path}.`);
|
||||
throw new BadRequestHttpError('Disallowed /.. segment in URL');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user