Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix accept for file #1012

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
18 changes: 15 additions & 3 deletions src/middleware/packages/ldp/services/resource/actions/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,27 @@ module.exports = {
});
}

if ((result['@type'] === 'semapps:File' || result.type === 'semapps:File') && !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) && !forceSemantic) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comme bodyToTriples retourne des quads, ce ne sera jamais semapps:File mais toujours des URIs complets. Même chose pour mimeType et localPath.

Copy link
Contributor

Choose a reason for hiding this comment

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

Par ailleurs, ce serait bien de mettre la condition if (!forceSemantic) avant l'appel à bodyToTriples, ça évite de faire ces calculs coûteux (forceSemantic est souvent true, par exemple lorsque ldp.resource.get est appelé par ldp.container.get)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

j'ai eu le cas d'un semapps:Filec'est pour ca que j'ai pris des précautions. Je crois que c'est dans le cas d'un json-ld avec prefix/context

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 = result['semapps:mimeType'];
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'
};
return fs.readFileSync(result['semapps:localPath']);
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');
}
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
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