mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Have FixedContentTypeMapper ignore .meta
This commit is contained in:
parent
d401cc862b
commit
9e682f5c4f
@ -24,6 +24,8 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
|
||||
protected readonly rootFilepath: string;
|
||||
// Extension to use as a fallback when the media type is not supported (could be made configurable).
|
||||
protected readonly unknownMediaTypeExtension = 'unknown';
|
||||
// Path suffix for metadata
|
||||
private readonly metadataSuffix = '.meta';
|
||||
|
||||
public constructor(base: string, rootFilepath: string) {
|
||||
this.baseRequestURI = trimTrailingSlashes(base);
|
||||
@ -44,7 +46,7 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
|
||||
Promise<ResourceLink> {
|
||||
let path = this.getRelativePath(identifier);
|
||||
if (isMetadata) {
|
||||
path += '.meta';
|
||||
path += this.metadataSuffix;
|
||||
}
|
||||
this.validateRelativePath(path, identifier);
|
||||
|
||||
@ -125,7 +127,7 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
|
||||
}
|
||||
const isMetadata = this.isMetadataPath(filePath);
|
||||
if (isMetadata) {
|
||||
url = url.slice(0, -'.meta'.length);
|
||||
url = url.slice(0, -this.metadataSuffix.length);
|
||||
}
|
||||
return { identifier: { path: url }, filePath, contentType, isMetadata };
|
||||
}
|
||||
@ -213,6 +215,6 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
|
||||
* Checks if the given path is a metadata path.
|
||||
*/
|
||||
protected isMetadataPath(path: string): boolean {
|
||||
return path.endsWith('.meta');
|
||||
return path.endsWith(this.metadataSuffix);
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ export class FixedContentTypeMapper extends BaseFileIdentifierMapper {
|
||||
}
|
||||
|
||||
protected async getDocumentUrl(relative: string): Promise<string> {
|
||||
// Handle path suffix
|
||||
if (this.pathSuffix) {
|
||||
// Handle path suffix, but ignore metadata files
|
||||
if (this.pathSuffix && !this.isMetadataPath(relative)) {
|
||||
if (relative.endsWith(this.pathSuffix)) {
|
||||
relative = relative.slice(0, -this.pathSuffix.length);
|
||||
} else {
|
||||
|
@ -183,6 +183,15 @@ describe('An FixedContentTypeMapper', (): void => {
|
||||
await expect(mapper.mapFilePathToUrl(`${rootFilepath}test`, false)).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(mapper.mapFilePathToUrl(`${rootFilepath}test.txt`, false)).rejects.toThrow(NotFoundHttpError);
|
||||
});
|
||||
|
||||
it('returns a generate file path for metadata regardless of the suffix.', async(): Promise<void> => {
|
||||
await expect(mapper.mapFilePathToUrl(`${rootFilepath}.meta`, false)).resolves.toEqual({
|
||||
identifier: { path: `${base}` },
|
||||
filePath: `${rootFilepath}.meta`,
|
||||
contentType: 'text/turtle',
|
||||
isMetadata: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user