Skip to content

Commit

Permalink
return integrityUrl in Form manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Feb 7, 2025
1 parent 110c66d commit 250812b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/formats/openrosa.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const formManifestTemplate = template(200, `<?xml version="1.0" encoding="UTF-8"
<filename>{{name}}</filename>
<hash>md5:{{openRosaHash}}</hash>
<downloadUrl>{{{domain}}}{{{basePath}}}/attachments/{{urlName}}</downloadUrl>
{{#integrityUrl}}
<integrityUrl>{{{integrityUrl}}}</integrityUrl>
{{/integrityUrl}}
</mediaFile>
{{/hasSource}}
{{/attachments}}
Expand All @@ -77,7 +80,10 @@ const formManifest = (data) => formManifestTemplate(mergeRight(data, {
attachment.with({
hasSource: attachment.blobId || attachment.datasetId,
urlName: encodeURIComponent(attachment.name),
isDataset: attachment.datasetId != null
isDataset: attachment.datasetId != null,
integrityUrl: attachment.datasetId ?
`${data.domain}${data.projectPath}/datasets/${encodeURIComponent(attachment.name.replace(/\.[^/.]+$/, ''))}/integrity`
: null
}))
}));

Expand Down
6 changes: 5 additions & 1 deletion lib/resources/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ module.exports = (service, endpoint) => {
.then((form) => canReadForm(auth, form))
.then((form) => FormAttachments.getAllByFormDefIdForOpenRosa(form.def.id)
.then((attachments) =>
formManifest({ attachments, basePath: path.resolve(originalUrl, '..'), domain: env.domain })))));
formManifest({ attachments,
basePath: path.resolve(originalUrl, '..'),
domain: env.domain,
projectPath: originalUrl.match(/^\/v1\/(.*\/)?projects\/\d+/)[0] }
)))));

////////////////////////////////////////
// READ-ONLY ATTACHMENT ENDPOINTS
Expand Down
3 changes: 3 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,7 @@ describe('datasets and entities', () => {
<filename>goodone.csv</filename>
<hash>md5:${etag.replace(/"/g, '')}</hash>
<downloadUrl>${domain}/v1/projects/1/forms/withAttachments/attachments/goodone.csv</downloadUrl>
<integrityUrl>${domain}/v1/projects/1/datasets/goodone/integrity</integrityUrl>
</mediaFile>
</manifest>`);
}));
Expand Down Expand Up @@ -2090,6 +2091,7 @@ describe('datasets and entities', () => {
<filename>goodone.csv</filename>
<hash>md5:${etag.replace(/"/g, '')}</hash>
<downloadUrl>${domain}/v1/projects/1/forms/withAttachments/attachments/goodone.csv</downloadUrl>
<integrityUrl>${domain}/v1/projects/1/datasets/goodone/integrity</integrityUrl>
</mediaFile>
</manifest>`);
}));
Expand Down Expand Up @@ -2965,6 +2967,7 @@ describe('datasets and entities', () => {
<filename>people.csv</filename>
<hash>md5:${etag.replace(/"/g, '')}</hash>
<downloadUrl>${domain}/v1/projects/1/forms/withAttachments/attachments/people.csv</downloadUrl>
<integrityUrl>${domain}/v1/projects/1/datasets/people/integrity</integrityUrl>
</mediaFile>
</manifest>`);
});
Expand Down

0 comments on commit 250812b

Please sign in to comment.