From a2882cf5cc44964af63374c02263c32940620fe9 Mon Sep 17 00:00:00 2001 From: bourgeoa Date: Thu, 7 Nov 2019 22:41:13 +0100 Subject: [PATCH] PUT copy body for contentType application/json --- lib/ldp.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/ldp.js b/lib/ldp.js index 76663685b..ea1c2b2a6 100644 --- a/lib/ldp.js +++ b/lib/ldp.js @@ -156,12 +156,6 @@ class LDP { } // const { url: putUrl } = await this.resourceMapper.mapFileToUrl({ path: resourceUrl, hostname }) - // HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data - // for JSON bodies. So, the stream needs to be reset - if (contentType.includes('application/json')) { - stream = intoStream(JSON.stringify(stream.body)) - } - await ldp.put(resourceUrl, stream, contentType) return URL.parse(originalUrl).path } @@ -240,6 +234,11 @@ class LDP { // Directory created, now write the file return withLock(path, { mustExist: false }, () => new Promise((resolve, reject) => { + // HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data + // for JSON bodies. So, the stream needs to be reset + if (contentType.includes('application/json')) { + stream = intoStream(JSON.stringify(stream.body)) + } const file = stream.pipe(fs.createWriteStream(path)) file.on('error', function () { reject(error(500, 'Error writing data'))