mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add acl support
This commit is contained in:
16
src/storage/ContainerManager.ts
Normal file
16
src/storage/ContainerManager.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
|
||||
/**
|
||||
* Handles the identification of containers in which a resource is contained.
|
||||
*/
|
||||
export interface ContainerManager {
|
||||
/**
|
||||
* Finds the corresponding container.
|
||||
* Should throw an error if there is no such container (in the case of root).
|
||||
*
|
||||
* @param id - Identifier to find container of.
|
||||
*
|
||||
* @returns The identifier of the container this resource is in.
|
||||
*/
|
||||
getContainer: (id: ResourceIdentifier) => Promise<ResourceIdentifier>;
|
||||
}
|
||||
34
src/storage/UrlContainerManager.ts
Normal file
34
src/storage/UrlContainerManager.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { ContainerManager } from './ContainerManager';
|
||||
import { ensureTrailingSlash } from '../util/Util';
|
||||
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
|
||||
/**
|
||||
* Determines containers based on URL decomposition.
|
||||
*/
|
||||
export class UrlContainerManager implements ContainerManager {
|
||||
private readonly root: string;
|
||||
|
||||
public constructor(root: string) {
|
||||
this.root = this.canonicalUrl(root);
|
||||
}
|
||||
|
||||
public async getContainer(id: ResourceIdentifier): Promise<ResourceIdentifier> {
|
||||
const path = this.canonicalUrl(id.path);
|
||||
if (this.root === path) {
|
||||
throw new Error('Root does not have a container.');
|
||||
}
|
||||
|
||||
const parentPath = new URL('..', path).toString();
|
||||
|
||||
// This probably means there is an issue with the root
|
||||
if (parentPath === path) {
|
||||
throw new Error('URL root reached.');
|
||||
}
|
||||
|
||||
return { path: parentPath };
|
||||
}
|
||||
|
||||
private canonicalUrl(path: string): string {
|
||||
return ensureTrailingSlash(new URL(path).toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user