fix(KoBoToolbox Node): Fix query and sort + use question name in attachments (#3017)

* Fix query,sort + use question name in attachments

* Change Menu structure

* kobo: Clearer webhook name

* [kobo]: fix when no json filter
This commit is contained in:
Yann Jouanique
2022-05-14 11:20:45 +02:00
committed by GitHub
parent a7d960c561
commit c885115768
5 changed files with 165 additions and 33 deletions

View File

@@ -173,10 +173,14 @@ export async function downloadAttachments(this: IExecuteFunctions | IWebhookFunc
for (const [index, attachment] of attachmentList.entries()) {
// look for the question name linked to this attachment
const filename = attachment.filename;
Object.keys(submission).forEach(question => {
if (filename.endsWith('/' + _.toString(submission[question]).replace(/\s/g, '_'))) {
}
});
let relatedQuestion = null;
if('question' === options.binaryNamingScheme) {
Object.keys(submission).forEach(question => {
if (filename.endsWith('/' + _.toString(submission[question]).replace(/\s/g, '_'))) {
relatedQuestion = question;
}
});
}
// Download attachment
// NOTE: this needs to follow redirects (possibly across domains), while keeping Authorization headers
@@ -209,11 +213,18 @@ export async function downloadAttachments(this: IExecuteFunctions | IWebhookFunc
}
}
const dataPropertyAttachmentsPrefixName = options.dataPropertyAttachmentsPrefixName || 'attachment_';
const fileName = filename.split('/').pop();
if (response && response.body) {
binaryItem.binary![`${dataPropertyAttachmentsPrefixName}${index}`] = await this.helpers.prepareBinaryData(response.body, fileName);
// Use the provided prefix if any, otherwise try to use the original question name
let binaryName;
if('question' === options.binaryNamingScheme && relatedQuestion) {
binaryName = relatedQuestion;
}
else {
binaryName = `${options.dataPropertyAttachmentsPrefixName || 'attachment_'}${index}`;
}
const fileName = filename.split('/').pop();
binaryItem.binary![binaryName] = await this.helpers.prepareBinaryData(response.body, fileName);
}
}
} else {