mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Check conversion support in base class.
This commit is contained in:
parent
4faf916ece
commit
da5515d50d
@ -6,7 +6,7 @@ import type { RepresentationPreferences } from '../../ldp/representation/Represe
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { guardStream } from '../../util/GuardedStream';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { supportsConversion, matchingMediaTypes } from './ConversionUtil';
|
||||
import { matchingMediaTypes } from './ConversionUtil';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
|
||||
@ -22,10 +22,6 @@ export class QuadToRdfConverter extends TypedRepresentationConverter {
|
||||
return rdfSerializer.getContentTypesPrioritized();
|
||||
}
|
||||
|
||||
public async canHandle(input: RepresentationConverterArgs): Promise<void> {
|
||||
supportsConversion(input, [ INTERNAL_QUADS ], await rdfSerializer.getContentTypes());
|
||||
}
|
||||
|
||||
public async handle(input: RepresentationConverterArgs): Promise<Representation> {
|
||||
return this.quadsToRdf(input.representation, input.preferences);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||
import { pipeSafely } from '../../util/StreamUtil';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { supportsConversion } from './ConversionUtil';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
|
||||
@ -22,10 +21,6 @@ export class RdfToQuadConverter extends TypedRepresentationConverter {
|
||||
return { [INTERNAL_QUADS]: 1 };
|
||||
}
|
||||
|
||||
public async canHandle(input: RepresentationConverterArgs): Promise<void> {
|
||||
supportsConversion(input, await rdfParser.getContentTypes(), [ INTERNAL_QUADS ]);
|
||||
}
|
||||
|
||||
public async handle(input: RepresentationConverterArgs): Promise<Representation> {
|
||||
return this.rdfToQuads(input.representation, input.identifier.path);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { supportsConversion } from './ConversionUtil';
|
||||
import { RepresentationConverter } from './RepresentationConverter';
|
||||
import type { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
|
||||
/**
|
||||
* A {@link RepresentationConverter} that allows requesting the supported types.
|
||||
@ -17,4 +19,13 @@ export abstract class TypedRepresentationConverter extends RepresentationConvert
|
||||
* @returns A promise resolving to a hash mapping content type to a priority number.
|
||||
*/
|
||||
public abstract getOutputTypes(): Promise<Record<string, number>>;
|
||||
|
||||
/**
|
||||
* Verifies whether this converter supports the input.
|
||||
*/
|
||||
public async canHandle(args: RepresentationConverterArgs): Promise<void> {
|
||||
const types = [ this.getInputTypes(), this.getOutputTypes() ];
|
||||
const [ inputTypes, outputTypes ] = await Promise.all(types);
|
||||
supportsConversion(args, Object.keys(inputTypes), Object.keys(outputTypes));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user