Skip to content

Commit

Permalink
feat: added debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Aug 1, 2018
1 parent 6835101 commit d49c86f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
37 changes: 24 additions & 13 deletions lib/components/state-resources/upload-file/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const debug = require('debug')('tymly-upload-plugin')
const fs = require('file-system')
const Buffer = require('safe-buffer').Buffer
const fileExtension = require('file-extension')
Expand All @@ -23,22 +24,32 @@ class UploadFile {
binaryData = new Buffer(encodedBase64String, 'base64')
}

this.files.upsert(
{
fileName: event.fileName
},
{}
)
.then((doc) => {
fs.writeFile(`${upath.normalize(this.uploadDirectoryPath)}${doc.idProperties.id}.${fileExtension(event.fileName)}`, binaryData, () => {
context.sendTaskSuccess({
fileId: doc.idProperties.id,
fileName: event.fileName
})
const filePath = `${upath.normalize(this.uploadDirectoryPath)}${doc.idProperties.id}.${fileExtension(event.fileName)}`
debug(`Upserting file '${event.fileName}'`)
this.files
.upsert(
{
fileName: event.fileName
},
{}
)
.then(doc => {
debug(`Writing file '${event.fileName}' to '${filePath}'`)
fs.writeFile(filePath, binaryData, err => {
if (err) {
debug(`Failed to upload '${event.filename}'`, err)
context.sendTaskFailure(err)
} else {
debug(`Upload of '${event.filename}' was successful`)
context.sendTaskSuccess({
fileId: doc.idProperties.id,
fileName: event.fileName
})
}
})
})
.catch(err => {
console.log('fail in upload')
debug(`Failed to upload '${event.filename}'`, err)
context.sendTaskFailure(err)
})
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"main": "./lib/index.js",
"dependencies": {
"debug": "3.1.0",
"dottie": "2.0.0",
"file-extension": "4.0.5",
"file-system": "2.2.2",
Expand Down

0 comments on commit d49c86f

Please sign in to comment.