mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Fix problem with piping streams for PATCH requests
This commit is contained in:
parent
73acb9cd52
commit
6c4378a2de
@ -1,4 +1,3 @@
|
|||||||
import { PassThrough } from 'stream';
|
|
||||||
import type { Algebra } from 'sparqlalgebrajs';
|
import type { Algebra } from 'sparqlalgebrajs';
|
||||||
import { translate } from 'sparqlalgebrajs';
|
import { translate } from 'sparqlalgebrajs';
|
||||||
import { getLoggerFor } from '../../logging/LogUtil';
|
import { getLoggerFor } from '../../logging/LogUtil';
|
||||||
@ -6,7 +5,7 @@ import { APPLICATION_SPARQL_UPDATE } from '../../util/ContentTypes';
|
|||||||
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
|
||||||
import { isNativeError } from '../../util/errors/ErrorUtil';
|
import { isNativeError } from '../../util/errors/ErrorUtil';
|
||||||
import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError';
|
import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError';
|
||||||
import { pipeSafely, readableToString } from '../../util/StreamUtil';
|
import { guardedStreamFrom, readableToString } from '../../util/StreamUtil';
|
||||||
import type { BodyParserArgs } from './BodyParser';
|
import type { BodyParserArgs } from './BodyParser';
|
||||||
import { BodyParser } from './BodyParser';
|
import { BodyParser } from './BodyParser';
|
||||||
import type { SparqlUpdatePatch } from './SparqlUpdatePatch';
|
import type { SparqlUpdatePatch } from './SparqlUpdatePatch';
|
||||||
@ -25,12 +24,9 @@ export class SparqlUpdateBodyParser extends BodyParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async handle({ request, metadata }: BodyParserArgs): Promise<SparqlUpdatePatch> {
|
public async handle({ request, metadata }: BodyParserArgs): Promise<SparqlUpdatePatch> {
|
||||||
const options = { objectMode: request.readableObjectMode };
|
const sparql = await readableToString(request);
|
||||||
const toAlgebraStream = pipeSafely(request, new PassThrough(options));
|
|
||||||
const dataCopy = pipeSafely(request, new PassThrough(options));
|
|
||||||
let algebra: Algebra.Operation;
|
let algebra: Algebra.Operation;
|
||||||
try {
|
try {
|
||||||
const sparql = await readableToString(toAlgebraStream);
|
|
||||||
algebra = translate(sparql, { quads: true, baseIRI: metadata.identifier.value });
|
algebra = translate(sparql, { quads: true, baseIRI: metadata.identifier.value });
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
this.logger.warn('Could not translate SPARQL query to SPARQL algebra', { error });
|
this.logger.warn('Could not translate SPARQL query to SPARQL algebra', { error });
|
||||||
@ -44,7 +40,7 @@ export class SparqlUpdateBodyParser extends BodyParser {
|
|||||||
return {
|
return {
|
||||||
algebra,
|
algebra,
|
||||||
binary: true,
|
binary: true,
|
||||||
data: dataCopy,
|
data: guardedStreamFrom(sparql),
|
||||||
metadata,
|
metadata,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user