mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Make root storage subject of storage description
This commit is contained in:
parent
d6fd59f7c8
commit
9584ab7549
@ -1,6 +1,7 @@
|
|||||||
import { OkResponseDescription } from '../../http/output/response/OkResponseDescription';
|
import { OkResponseDescription } from '../../http/output/response/OkResponseDescription';
|
||||||
import type { ResponseDescription } from '../../http/output/response/ResponseDescription';
|
import type { ResponseDescription } from '../../http/output/response/ResponseDescription';
|
||||||
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
|
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
|
||||||
|
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier';
|
||||||
import type { ResourceStore } from '../../storage/ResourceStore';
|
import type { ResourceStore } from '../../storage/ResourceStore';
|
||||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||||
import { MethodNotAllowedHttpError } from '../../util/errors/MethodNotAllowedHttpError';
|
import { MethodNotAllowedHttpError } from '../../util/errors/MethodNotAllowedHttpError';
|
||||||
@ -32,7 +33,7 @@ export class StorageDescriptionHandler extends OperationHttpHandler {
|
|||||||
if (method !== 'GET') {
|
if (method !== 'GET') {
|
||||||
throw new MethodNotAllowedHttpError([ method ], `Only GET requests can target the storage description.`);
|
throw new MethodNotAllowedHttpError([ method ], `Only GET requests can target the storage description.`);
|
||||||
}
|
}
|
||||||
const container = { path: ensureTrailingSlash(target.path.slice(0, -this.path.length)) };
|
const container = this.getStorageIdentifier(target);
|
||||||
const representation = await this.store.getRepresentation(container, {});
|
const representation = await this.store.getRepresentation(container, {});
|
||||||
representation.data.destroy();
|
representation.data.destroy();
|
||||||
if (!representation.metadata.has(RDF.terms.type, PIM.terms.Storage)) {
|
if (!representation.metadata.has(RDF.terms.type, PIM.terms.Storage)) {
|
||||||
@ -43,10 +44,17 @@ export class StorageDescriptionHandler extends OperationHttpHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async handle({ operation: { target }}: OperationHttpHandlerInput): Promise<ResponseDescription> {
|
public async handle({ operation: { target }}: OperationHttpHandlerInput): Promise<ResponseDescription> {
|
||||||
const quads = await this.describer.handle(target);
|
const quads = await this.describer.handle(this.getStorageIdentifier(target));
|
||||||
|
|
||||||
const representation = new BasicRepresentation(quads, INTERNAL_QUADS);
|
const representation = new BasicRepresentation(quads, INTERNAL_QUADS);
|
||||||
|
|
||||||
return new OkResponseDescription(representation.metadata, representation.data);
|
return new OkResponseDescription(representation.metadata, representation.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the identifier of the root storage based on the identifier of the root storage description resource.
|
||||||
|
*/
|
||||||
|
protected getStorageIdentifier(descriptionIdentifier: ResourceIdentifier): ResourceIdentifier {
|
||||||
|
return { path: ensureTrailingSlash(descriptionIdentifier.path.slice(0, -this.path.length)) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ describe.each(stores)('A server supporting WebHookChannel2023 using %s', (name,
|
|||||||
const quads = new Store(new Parser().parse(await response.text()));
|
const quads = new Store(new Parser().parse(await response.text()));
|
||||||
|
|
||||||
// Find the notification channel for websockets
|
// Find the notification channel for websockets
|
||||||
const subscriptions = quads.getObjects(storageDescriptionUrl, NOTIFY.terms.subscription, null);
|
const subscriptions = quads.getObjects(null, NOTIFY.terms.subscription, null);
|
||||||
const webhookSubscriptions = subscriptions.filter((channel): boolean => quads.has(
|
const webhookSubscriptions = subscriptions.filter((channel): boolean => quads.has(
|
||||||
quad(channel as NamedNode, NOTIFY.terms.channelType, namedNode(`${NOTIFY.namespace}WebHookChannel2023`)),
|
quad(channel as NamedNode, NOTIFY.terms.channelType, namedNode(`${NOTIFY.namespace}WebHookChannel2023`)),
|
||||||
));
|
));
|
||||||
|
@ -86,7 +86,7 @@ describe.each(stores)('A server supporting WebSocketChannel2023 using %s', (name
|
|||||||
const quads = new Store(new Parser().parse(await response.text()));
|
const quads = new Store(new Parser().parse(await response.text()));
|
||||||
|
|
||||||
// Find the notification channel for websockets
|
// Find the notification channel for websockets
|
||||||
const subscriptions = quads.getObjects(storageDescriptionUrl, NOTIFY.terms.subscription, null);
|
const subscriptions = quads.getObjects(null, NOTIFY.terms.subscription, null);
|
||||||
const websocketSubscriptions = subscriptions.filter((channel): boolean => quads.has(
|
const websocketSubscriptions = subscriptions.filter((channel): boolean => quads.has(
|
||||||
quad(channel as NamedNode, NOTIFY.terms.channelType, namedNode(`${NOTIFY.namespace}WebSocketChannel2023`)),
|
quad(channel as NamedNode, NOTIFY.terms.channelType, namedNode(`${NOTIFY.namespace}WebSocketChannel2023`)),
|
||||||
));
|
));
|
||||||
|
@ -83,8 +83,8 @@ describe('A StorageDescriptionHandler', (): void => {
|
|||||||
expect(result.metadata?.contentType).toBe('internal/quads');
|
expect(result.metadata?.contentType).toBe('internal/quads');
|
||||||
expect(result.data).toBeDefined();
|
expect(result.data).toBeDefined();
|
||||||
const quads = await readableToQuads(result.data!);
|
const quads = await readableToQuads(result.data!);
|
||||||
expect(quads.countQuads(operation.target.path, RDF.terms.type, PIM.terms.Storage, null)).toBe(1);
|
expect(quads.countQuads('http://example.com/', RDF.terms.type, PIM.terms.Storage, null)).toBe(1);
|
||||||
expect(describer.handle).toHaveBeenCalledTimes(1);
|
expect(describer.handle).toHaveBeenCalledTimes(1);
|
||||||
expect(describer.handle).toHaveBeenLastCalledWith(operation.target);
|
expect(describer.handle).toHaveBeenLastCalledWith({ path: 'http://example.com/' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user