File upload fix

This commit is contained in:
mrfry 2021-05-05 09:12:41 +02:00
parent 0da1dab95d
commit 8730318741
4 changed files with 30 additions and 14 deletions

View file

@ -149,7 +149,7 @@ function WriteFile(content: string, path: string): void {
function writeFileAsync(content: string, path: string): void {
CreatePath(path)
fs.writeFile(path, content, function(err) {
fs.writeFile(path, content, function (err) {
if (err) {
logger.Log(
'Error writing file: ' + path + ' (sync)',
@ -184,6 +184,13 @@ function deleteFile(fname: string): Boolean {
function uploadFile(req: Request, path: string): Promise<any> {
return new Promise((resolve, reject) => {
try {
if (!req.files) {
logger.Log(
`Unable to upload file, req.files is undefined`,
logger.GetColor('redbg')
)
return
}
const file = req.files.file
// FIXME: Object.keys(req.files).forEach((file) => { saveFile() })
logger.Log('Uploading: ' + file.name, logger.GetColor('blue'))
@ -217,7 +224,10 @@ function uploadFile(req: Request, path: string): Promise<any> {
}
})
} catch (err) {
logger.Log(`Unable to upload file!`, logger.GetColor('redbg'))
logger.Log(
`Unable to upload file, error on stderr`,
logger.GetColor('redbg')
)
console.error(err)
reject(err)
}