Skip to content

Commit

Permalink
multipart support, deactivate bug, local require PipedreamHQ#49
Browse files Browse the repository at this point in the history
  • Loading branch information
psavkar authored Jun 2, 2020
2 parents 8d2c2d4 + 269f8d9 commit 65e3e15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
12 changes: 9 additions & 3 deletions components/jotform/jotform.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ module.exports = {
},
async deleteHook(opts = {}) {
const { formId, endpoint } = opts
const webhooks = (await this.getWebhooks({ formId })).content
const webhookIdx = webhooks.findIndex(w => w === ensureTrailingSlash(endpoint))
if(webhookIdx !== -1) {
const result = await this.getWebhooks({ formId })
let webhooks = Object.values(result && result.content || {})
let webhookIdx = -1
for (let idx in webhooks) {
if (webhooks[idx] === ensureTrailingSlash(endpoint)) {
webhookIdx = idx
}
}
if(webhookIdx === -1) {
console.log(`Did not detect ${endpoint} as a webhook registered for form ID ${formId}.`)
return
}
Expand Down
38 changes: 4 additions & 34 deletions components/jotform/new-submission.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const jotform = require('https://github.com/PipedreamHQ/pipedream/components/jotform/jotform.app.js')
const busboy = require('busboy')
const jotform = require('./jotform.app.js')

module.exports = {
name: "new-submission",
Expand Down Expand Up @@ -28,38 +27,9 @@ module.exports = {
status: 200,
})

const bb = new busboy({ headers: event.headers });
let fileData = {}
let formData = {}

await new Promise((resolve, reject) => {
bb.on('file', function (fieldname, file, filename, encoding, mimetype) {
//console.log('File [%s]: filename=%j; encoding=%j; mimetype=%j', fieldname, filename, encoding, mimetype);
fileData.file = filename
fileData.fileName = filename
fileData.encoding = encoding
fileData.mimetype = mimetype
fileData.data = {}

file
.on('data', data => {
fileData.data[fieldname] = data.length
})
}).on('field', (fieldname, val) => {
try {
formData[fieldname] = JSON.parse(val)
} catch (err) {
formData[fieldname] = val
}
})
.on("finish", resolve)
.on('error', reject)
bb.end(event.body)
})

this.$emit(formData, {
summary: JSON.stringify(formData.rawRequest || formData),
id: formData.submissionID,
this.$emit(event.body, {
summary: event.body.rawRequest || JSON.stringify(event.body),
id: event.body.submissionID,
})
},
}

0 comments on commit 65e3e15

Please sign in to comment.