mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Create container data before adding content-type
This commit is contained in:
parent
82393ed33b
commit
c2b189184b
@ -1,4 +1,3 @@
|
||||
import type { Readable } from 'stream';
|
||||
import { DataFactory } from 'n3';
|
||||
import type { Quad } from 'rdf-js';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
@ -11,7 +10,6 @@ import { ConflictHttpError } from '../util/errors/ConflictHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { NotImplementedHttpError } from '../util/errors/NotImplementedHttpError';
|
||||
import type { Guarded } from '../util/GuardedStream';
|
||||
import {
|
||||
ensureTrailingSlash,
|
||||
getParentContainer,
|
||||
@ -68,13 +66,12 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
|
||||
// Create the representation of a container
|
||||
if (this.isExistingContainer(metadata)) {
|
||||
// Generate the data stream before setting the content-type to prevent unnecessary triples
|
||||
const data = guardedStreamFrom(metadata.quads());
|
||||
metadata.contentType = INTERNAL_QUADS;
|
||||
result = {
|
||||
binary: false,
|
||||
get data(): Guarded<Readable> {
|
||||
// This allows other modules to still add metadata before the output data is written
|
||||
return guardedStreamFrom(result.metadata.quads());
|
||||
},
|
||||
data,
|
||||
metadata,
|
||||
};
|
||||
|
||||
|
@ -108,9 +108,10 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
it('will return a data stream that matches the metadata for containers.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}container/` };
|
||||
accessor.data[resourceID.path] = { metadata: containerMetadata } as Representation;
|
||||
const metaQuads = containerMetadata.quads();
|
||||
const result = await store.getRepresentation(resourceID);
|
||||
expect(result).toMatchObject({ binary: false });
|
||||
expect(await arrayifyStream(result.data)).toBeRdfIsomorphic(containerMetadata.quads());
|
||||
expect(await arrayifyStream(result.data)).toBeRdfIsomorphic(metaQuads);
|
||||
expect(result.metadata.contentType).toEqual(INTERNAL_QUADS);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user