diff --git a/src/middleware/packages/ldp/services/resource/actions/get.js b/src/middleware/packages/ldp/services/resource/actions/get.js index 26126c743..66acb5481 100644 --- a/src/middleware/packages/ldp/services/resource/actions/get.js +++ b/src/middleware/packages/ldp/services/resource/actions/get.js @@ -125,17 +125,33 @@ module.exports = { }); } - if ((result['@type'] === 'semapps:File' || result.type === 'semapps:File') && !forceSemantic) { - try { - // Overwrite response type set by the api action - ctx.meta.$responseType = result['semapps:mimeType']; - // Since files are currently immutable, we set a maximum browser cache age - ctx.meta.$responseHeaders = { - 'Cache-Control': 'public, max-age=31536000' - }; - return fs.readFileSync(result['semapps:localPath']); - } catch (e) { - throw new MoleculerError('File Not found', 404, 'NOT_FOUND'); + if (!forceSemantic) { + let triples = await this.bodyToTriples(result, accept); + + let type = triples.find(q => ['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'].includes(q.predicate.value)) + .object.value; + + if (['http://semapps.org/ns/core#File', 'semapps:File'].includes(type)) { + try { + const mimeType = triples.find(q => + ['http://semapps.org/ns/core#mimeType', 'semapps:mimeType'].includes(q.predicate.value) + ).object.value; + + // Overwrite response type set by the api action + ctx.meta.$responseType = mimeType; + // Since files are currently immutable, we set a maximum browser cache age + ctx.meta.$responseHeaders = { + 'Cache-Control': 'public, max-age=31536000' + }; + const localPath = triples.find(q => + ['http://semapps.org/ns/core#localPath', 'semapps:localPath'].includes(q.predicate.value) + ).object.value; + return fs.readFileSync(localPath); + } catch (e) { + throw new MoleculerError('File Not found', 404, 'NOT_FOUND'); + } + } else { + return result; } } else { return result; diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 000000000..fb57ccd13 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +