mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add Content-Type constructor to metadata.
This commit is contained in:
@@ -2,7 +2,6 @@ import type { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import type { ValuePreferences } from '../../ldp/representation/RepresentationPreferences';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { CONTENT_TYPE } from '../../util/Vocabularies';
|
||||
import { matchesMediaType, matchingMediaTypes } from './ConversionUtil';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { RepresentationConverter } from './RepresentationConverter';
|
||||
@@ -50,7 +49,7 @@ export class ContentTypeReplacer extends RepresentationConverter {
|
||||
*/
|
||||
public async handle({ representation, preferences }: RepresentationConverterArgs): Promise<Representation> {
|
||||
const contentType = this.getReplacementType(representation.metadata.contentType, preferences.type);
|
||||
const metadata = new RepresentationMetadata(representation.metadata, { [CONTENT_TYPE]: contentType });
|
||||
const metadata = new RepresentationMetadata(representation.metadata, contentType);
|
||||
return { ...representation, metadata };
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { ValuePreferences } from '../../ldp/representation/RepresentationPr
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { guardStream } from '../../util/GuardedStream';
|
||||
import { pipeSafely } from '../../util/StreamUtil';
|
||||
import { CONTENT_TYPE, PREFERRED_PREFIX_TERM } from '../../util/Vocabularies';
|
||||
import { PREFERRED_PREFIX_TERM } from '../../util/Vocabularies';
|
||||
import { matchingMediaTypes } from './ConversionUtil';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
@@ -27,7 +27,7 @@ export class QuadToRdfConverter extends TypedRepresentationConverter {
|
||||
|
||||
public async handle({ representation: quads, preferences }: RepresentationConverterArgs): Promise<Representation> {
|
||||
const contentType = matchingMediaTypes(preferences.type, await this.getOutputTypes())[0];
|
||||
const metadata = new RepresentationMetadata(quads.metadata, { [CONTENT_TYPE]: contentType });
|
||||
const metadata = new RepresentationMetadata(quads.metadata, contentType);
|
||||
let data: Readable;
|
||||
|
||||
// Use prefixes if possible (see https://github.com/rubensworks/rdf-serialize.js/issues/1)
|
||||
|
||||
@@ -5,7 +5,6 @@ import { RepresentationMetadata } from '../../ldp/representation/RepresentationM
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||
import { pipeSafely } from '../../util/StreamUtil';
|
||||
import { CONTENT_TYPE } from '../../util/Vocabularies';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
|
||||
@@ -18,7 +17,7 @@ export class RdfToQuadConverter extends TypedRepresentationConverter {
|
||||
}
|
||||
|
||||
public async handle({ representation, identifier }: RepresentationConverterArgs): Promise<Representation> {
|
||||
const metadata = new RepresentationMetadata(representation.metadata, { [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const metadata = new RepresentationMetadata(representation.metadata, INTERNAL_QUADS);
|
||||
const rawQuads = rdfParser.parse(representation.data, {
|
||||
contentType: representation.metadata.contentType!,
|
||||
baseIRI: identifier.path,
|
||||
|
||||
@@ -14,7 +14,6 @@ import { NotFoundHttpError } from '../../util/errors/NotFoundHttpError';
|
||||
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
|
||||
import { guardStream } from '../../util/GuardedStream';
|
||||
import type { ResourceLocker } from '../../util/locking/ResourceLocker';
|
||||
import { CONTENT_TYPE } from '../../util/Vocabularies';
|
||||
import type { ResourceStore } from '../ResourceStore';
|
||||
import { PatchHandler } from './PatchHandler';
|
||||
|
||||
@@ -109,7 +108,7 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
this.logger.debug(`${store.size} quads will be stored to ${identifier.path}.`);
|
||||
|
||||
// Write the result
|
||||
const metadata = new RepresentationMetadata(identifier, { [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const metadata = new RepresentationMetadata(identifier, INTERNAL_QUADS);
|
||||
const representation: Representation = {
|
||||
binary: false,
|
||||
data: guardStream(store.match() as Readable),
|
||||
|
||||
Reference in New Issue
Block a user