mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Minor file upload change
This commit is contained in:
parent
347952c6da
commit
07b313bcd9
1 changed files with 6 additions and 3 deletions
|
@ -38,6 +38,7 @@ export default {
|
|||
}
|
||||
|
||||
import fs from 'fs'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import logger from '../utils/logger'
|
||||
|
||||
import { Request } from '../types/basicTypes'
|
||||
|
@ -225,15 +226,13 @@ function uploadFile(
|
|||
}
|
||||
const file = req.files.file
|
||||
// FIXME: Object.keys(req.files).forEach((file) => { saveFile() })
|
||||
logger.Log('Uploading: ' + file.name, logger.GetColor('blue'))
|
||||
|
||||
CreatePath(path, true)
|
||||
|
||||
let fileName = file.name.replace(/\.+/g, '.').replace(/\/+/g, '/')
|
||||
let fileDestination = path + '/' + fileName
|
||||
if (FileExists(fileDestination)) {
|
||||
const date = new Date()
|
||||
const id = date.getHours() + date.getMinutes() + date.getSeconds()
|
||||
const id = uuidv4().split('-')[0]
|
||||
|
||||
const temp = file.name.split('.')
|
||||
const extension = temp.pop()
|
||||
|
@ -247,6 +246,10 @@ function uploadFile(
|
|||
console.error(err)
|
||||
reject(err)
|
||||
} else {
|
||||
logger.Log(
|
||||
`Uploaded: ${fileName} to ${fileDestination}`,
|
||||
logger.GetColor('blue')
|
||||
)
|
||||
resolve({
|
||||
body: req.body,
|
||||
fileName: fileName,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue