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;
|
protected readonly rootFilepath: string;
|
||||||
// Extension to use as a fallback when the media type is not supported (could be made configurable).
|
// Extension to use as a fallback when the media type is not supported (could be made configurable).
|
||||||
protected readonly unknownMediaTypeExtension = 'unknown';
|
protected readonly unknownMediaTypeExtension = 'unknown';
|
||||||
|
// Path suffix for metadata
|
||||||
|
private readonly metadataSuffix = '.meta';
|
||||||
|
|
||||||
public constructor(base: string, rootFilepath: string) {
|
public constructor(base: string, rootFilepath: string) {
|
||||||
this.baseRequestURI = trimTrailingSlashes(base);
|
this.baseRequestURI = trimTrailingSlashes(base);
|
||||||
@ -44,7 +46,7 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
|
|||||||
Promise<ResourceLink> {
|
Promise<ResourceLink> {
|
||||||
let path = this.getRelativePath(identifier);
|
let path = this.getRelativePath(identifier);
|
||||||
if (isMetadata) {
|
if (isMetadata) {
|
||||||
path += '.meta';
|
path += this.metadataSuffix;
|
||||||
}
|
}
|
||||||
this.validateRelativePath(path, identifier);
|
this.validateRelativePath(path, identifier);
|
||||||
|
|
||||||
@ -125,7 +127,7 @@ export class BaseFileIdentifierMapper implements FileIdentifierMapper {
|
|||||||
}
|
}
|
||||||
const isMetadata = this.isMetadataPath(filePath);
|
const isMetadata = this.isMetadataPath(filePath);
|
||||||
if (isMetadata) {
|
if (isMetadata) {
|
||||||
url = url.slice(0, -'.meta'.length);
|
url = url.slice(0, -this.metadataSuffix.length);
|
||||||
}
|
}
|
||||||
return { identifier: { path: url }, filePath, contentType, isMetadata };
|
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.
|
* Checks if the given path is a metadata path.
|
||||||
*/
|
*/
|
||||||
protected isMetadataPath(path: string): boolean {
|
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> {
|
protected async getDocumentUrl(relative: string): Promise<string> {
|
||||||
// Handle path suffix
|
// Handle path suffix, but ignore metadata files
|
||||||
if (this.pathSuffix) {
|
if (this.pathSuffix && !this.isMetadataPath(relative)) {
|
||||||
if (relative.endsWith(this.pathSuffix)) {
|
if (relative.endsWith(this.pathSuffix)) {
|
||||||
relative = relative.slice(0, -this.pathSuffix.length);
|
relative = relative.slice(0, -this.pathSuffix.length);
|
||||||
} else {
|
} 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`, false)).rejects.toThrow(NotFoundHttpError);
|
||||||
await expect(mapper.mapFilePathToUrl(`${rootFilepath}test.txt`, 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