mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add template based data generator
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
isContainerIdentifier,
|
||||
trimTrailingSlashes,
|
||||
} from '../../util/PathUtil';
|
||||
import type { FileIdentifierMapper, ResourceLink } from '../FileIdentifierMapper';
|
||||
import type { FileIdentifierMapper, FileIdentifierMapperFactory, ResourceLink } from './FileIdentifierMapper';
|
||||
import { getAbsolutePath, getRelativePath, validateRelativePath } from './MapperUtil';
|
||||
|
||||
const { join: joinPath, normalize: normalizePath } = posix;
|
||||
@@ -197,3 +197,10 @@ export class ExtensionBasedMapper implements FileIdentifierMapper {
|
||||
return extension && extension[1];
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtensionBasedMapperFactory implements FileIdentifierMapperFactory<ExtensionBasedMapper> {
|
||||
public async create(base: string, rootFilePath: string): Promise<ExtensionBasedMapper> {
|
||||
return new ExtensionBasedMapper(base, rootFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
48
src/storage/mapping/FileIdentifierMapper.ts
Normal file
48
src/storage/mapping/FileIdentifierMapper.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
|
||||
export interface ResourceLink {
|
||||
/**
|
||||
* Identifier of a resource.
|
||||
*/
|
||||
identifier: ResourceIdentifier;
|
||||
/**
|
||||
* File path of a resource.
|
||||
*/
|
||||
filePath: string;
|
||||
/**
|
||||
* Content-type for a document (not defined for containers).
|
||||
*/
|
||||
contentType?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supports mapping a file to an URL and back.
|
||||
*/
|
||||
export interface FileIdentifierMapper {
|
||||
/**
|
||||
* Maps the given file path to an URL and determines the 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 resource identifier / URL to a file path.
|
||||
* Determines the content-type if no content-type was provided.
|
||||
* For containers the content-type input gets ignored.
|
||||
* @param identifier - The input identifier.
|
||||
* @param contentType - The (optional) content-type of the resource.
|
||||
*
|
||||
* @returns A ResourceLink with all the necessary metadata.
|
||||
*/
|
||||
mapUrlToFilePath: (identifier: ResourceIdentifier, contentType?: string) => Promise<ResourceLink>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory that can create FileIdentifierMappers so the base and rootFilePath can be set dynamically.
|
||||
* Specifically used when identifiers need to be generated for a new pod (since pod identifiers are generated).
|
||||
*/
|
||||
export interface FileIdentifierMapperFactory<T extends FileIdentifierMapper = FileIdentifierMapper> {
|
||||
create: (base: string, rootFilePath: string) => Promise<T>;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ensureTrailingSlash, isContainerIdentifier,
|
||||
trimTrailingSlashes,
|
||||
} from '../../util/PathUtil';
|
||||
import type { FileIdentifierMapper, ResourceLink } from '../FileIdentifierMapper';
|
||||
import type { FileIdentifierMapper, ResourceLink } from './FileIdentifierMapper';
|
||||
import { getAbsolutePath, getRelativePath, validateRelativePath } from './MapperUtil';
|
||||
|
||||
const { normalize: normalizePath } = posix;
|
||||
|
||||
Reference in New Issue
Block a user