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 fs from 'fs'
|
||||||
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import logger from '../utils/logger'
|
import logger from '../utils/logger'
|
||||||
|
|
||||||
import { Request } from '../types/basicTypes'
|
import { Request } from '../types/basicTypes'
|
||||||
|
@ -225,15 +226,13 @@ function uploadFile(
|
||||||
}
|
}
|
||||||
const file = req.files.file
|
const file = req.files.file
|
||||||
// FIXME: Object.keys(req.files).forEach((file) => { saveFile() })
|
// FIXME: Object.keys(req.files).forEach((file) => { saveFile() })
|
||||||
logger.Log('Uploading: ' + file.name, logger.GetColor('blue'))
|
|
||||||
|
|
||||||
CreatePath(path, true)
|
CreatePath(path, true)
|
||||||
|
|
||||||
let fileName = file.name.replace(/\.+/g, '.').replace(/\/+/g, '/')
|
let fileName = file.name.replace(/\.+/g, '.').replace(/\/+/g, '/')
|
||||||
let fileDestination = path + '/' + fileName
|
let fileDestination = path + '/' + fileName
|
||||||
if (FileExists(fileDestination)) {
|
if (FileExists(fileDestination)) {
|
||||||
const date = new Date()
|
const id = uuidv4().split('-')[0]
|
||||||
const id = date.getHours() + date.getMinutes() + date.getSeconds()
|
|
||||||
|
|
||||||
const temp = file.name.split('.')
|
const temp = file.name.split('.')
|
||||||
const extension = temp.pop()
|
const extension = temp.pop()
|
||||||
|
@ -247,6 +246,10 @@ function uploadFile(
|
||||||
console.error(err)
|
console.error(err)
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
|
logger.Log(
|
||||||
|
`Uploaded: ${fileName} to ${fileDestination}`,
|
||||||
|
logger.GetColor('blue')
|
||||||
|
)
|
||||||
resolve({
|
resolve({
|
||||||
body: req.body,
|
body: req.body,
|
||||||
fileName: fileName,
|
fileName: fileName,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue