Skip to content

Commit

Permalink
handling none or invalid associated cases
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmota committed May 5, 2019
1 parent eb05b4b commit 6d638f0
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/adonisjs/app/Controllers/Http/v1/ArtifactController.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,53 @@ class ArtifactController {
extnames: ['png', 'jpg', 'jpge', 'gif','mp4','avi', '.wmv']
}

this.relative_path = '/artifacts/'
this.relativePath = '/artifacts/'


}

async store({ request, auth, response }) {


const file = request.file('file', this.validationOptions)
const file = request.file('file', this.validationOptions)
const caseID = request.input('case_id', null)

const filename = await uuid() + "." + file.extname
const fs_path = Helpers.publicPath(this.relative_path)
const case_id = request.input('case_id', null)
const artifactID = await uuid()
const artifactFileName = artifactID + "." + file.extname
const fsPath = Helpers.publicPath(this.relativePath)


await file.move(fs_path, {name: filename, overwrite: false})
await file.move(fsPath, {name: artifactFileName, overwrite: false})

if (!file.moved())
return file.error()


var linked_case = null

try{
linked_case = await Case.find(case_id)
}catch(e){
console.log(e)
}
var linkedCase = await Case.find(caseID)



const artifact = new Artifact()
artifact.fs_path = fs_path + filename
artifact.relative_path = this.relative_path + filename
artifact.case_id = linked_case
artifact.fs_path = fsPath + artifactFileName
artifact.relative_path = this.relativePath + artifactFileName
artifact.case_id = linkedCase != null ? linkedCase.id : linkedCase;
await auth.user.artifacts().save(artifact)

const base_url = Env.getOrFail('APP_URL')



return response.status(200).json({ message: "Artifact successfully stored",
filename: filename,
case: linked_case,
filename: artifactFileName,
case: linkedCase,
size_in_bytes: file.size,
type: file.type,
subtype: file.subtype,
extension: file.extname,
status: file.status,
relative_path: artifact.relative_path,
url: base_url+this.relative_path+filename
url: base_url+artifact.relative_path

})

Expand Down

0 comments on commit 6d638f0

Please sign in to comment.