UNPKG

@solid/community-server

Version:

Community Solid Server: an open and modular implementation of the Solid specifications

124 lines (123 loc) 5.03 kB
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier'; import type { FileIdentifierMapper, ResourceLink } from './FileIdentifierMapper'; /** * Base class for {@link FileIdentifierMapper} implementations. */ export declare class BaseFileIdentifierMapper implements FileIdentifierMapper { protected readonly logger: import("global-logger-factory").Logger<unknown>; protected readonly baseRequestURI: string; protected readonly rootFilepath: string; protected readonly unknownMediaTypeExtension = "unknown"; private readonly metadataSuffix; constructor(base: string, rootFilepath: string); /** * Maps the given resource identifier / URL to a file path. * Determines the content type if none was provided. * For containers the content-type input is ignored. * * @param identifier - The input identifier. * @param isMetadata - If we need the data or metadata file path. * @param contentType - The content-type provided with the request. * * @returns A ResourceLink with all the necessary metadata. */ mapUrlToFilePath(identifier: ResourceIdentifier, isMetadata: boolean, contentType?: string): Promise<ResourceLink>; /** * Maps the given container identifier to a file path, * possibly making alterations to the direct translation. * * @param identifier - The input identifier. * @param filePath - The direct translation of the identifier onto the file path. * * @returns A ResourceLink with all the necessary metadata. */ protected mapUrlToContainerPath(identifier: ResourceIdentifier, filePath: string): Promise<ResourceLink>; /** * Maps the given document identifier to a file path, * possibly making alterations to the direct translation * (for instance, based on its content type)). * Determines the content type if none was provided. * * @param identifier - The input identifier. * @param filePath - The direct translation of the identifier onto the file path. * @param contentType - The content-type provided with the request. * * @returns A ResourceLink with all the necessary metadata. */ protected mapUrlToDocumentPath(identifier: ResourceIdentifier, filePath: string, contentType?: string): Promise<ResourceLink>; /** * Determines the content type from the document identifier. * * @param identifier - The input identifier. * @param contentType - The content-type provided with the request. * * @returns The content type of the document. */ protected getContentTypeFromUrl(identifier: ResourceIdentifier, contentType?: string): Promise<string>; /** * Maps the given file path to a URL and determines its content type. * * @param filePath - The input file path. * @param isContainer - If the path corresponds to a file. * * @returns A ResourceLink with all the necessary metadata. */ mapFilePathToUrl(filePath: string, isContainer: boolean): Promise<ResourceLink>; /** * Maps the given container path to a URL and determines its content type. * * @param relative - The relative container path. * * @returns A ResourceLink with all the necessary metadata. */ protected getContainerUrl(relative: string): Promise<string>; /** * Maps the given document path to a URL and determines its content type. * * @param relative - The relative document path. * * @returns A ResourceLink with all the necessary metadata. */ protected getDocumentUrl(relative: string): Promise<string>; /** * Determines the content type from the relative path. * * @param filePath - The file path of the document. * * @returns The content type of the document. */ protected getContentTypeFromPath(filePath: string): Promise<string>; /** * Get the absolute file path based on the rootFilepath. * * @param path - The relative file path. * * @returns Absolute path of the file. */ protected getAbsolutePath(path: string): string; /** * Strips the baseRequestURI from the identifier. * * @param identifier - Incoming identifier. * * @returns A string representing the relative path. * * @throws NotFoundHttpError * If the identifier does not match the baseRequestURI. */ protected getRelativePath(identifier: ResourceIdentifier): string; /** * Check whether the given relative path is valid. * * @param path - A relative path, as generated by {@link getRelativePath}. * @param identifier - A resource identifier. * * @throws BadRequestHttpError * If the relative path is invalid. */ protected validateRelativePath(path: string, identifier: ResourceIdentifier): void; /** * Checks if the given path is a metadata path. */ protected isMetadataPath(path: string): boolean; }