Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions src/middleware/packages/ldp/services/resource/actions/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu peux effacer ce fichier inutile STP