Edit D:\xinhaisoft\crisis_new\api\controllers\upload.js
// ?????? const fs = require('fs') const config = require('../config') /** * ?????? * post: /upload */ module.exports = async ctx => { const body = ctx.request.body // ?????? const saveDir = config.upload // ???????????? const fn = body.fn // ???????????? const fp = body.fp const files = ctx.request.files if (files) { // ?????????????????ile?? const file = files.file // ????????? const oldPath = file.path // ???????????????????????????????? let name = file.name const dot = name.lastIndexOf('.') // ???????????.?? const ext = name.substring(dot).toLowerCase() if (dot < 0) { ctx.body = { code: 2, message: '?????????' } } else if (fn && /;|\.|#|\\|\/|,/.test(fn)) { ctx.body = { code: 4, message: '???????????????' } } else if (fp && /;|\.|#|\\|\/|,/.test(fp)) { ctx.body = { code: 6, message: '?????????????????' } } else if ('.htm.html.js.php.asp.aspx'.includes(ext)) { ctx.body = { code: 5, message: '???????????' } } else { let newPath = saveDir let url = '' // ???????????????????????????????? if (fn) { if (fn.startsWith('crm_')) { url = 'crm/' + fn.substring(4) + '_' + Math.random().toString().slice(-8) } else if (fn.startsWith('face_')) { url = 'image/face/' + fn.substring(5) } else if ('.xls.xlsx'.includes(ext)) { url = 'excel/' + fn } else if ('.png.jpg.gif.jpeg.bmp.ico.svg'.includes(ext)) { url = 'image/' + fn } else if ('.pdf'.includes(ext)) { url = 'pdf/' + fn } else if ('.doc.docx'.includes(ext)) { url = 'word/' + fn } else if ('.txt'.includes(ext)) { url = 'txt/' + fn } else { url = 'other/' + fn } name = url } else { // ???????????? const now = new Date() const time = { y: now.getFullYear(), m: ('0' + (now.getMonth() + 1)).slice(-2), d: ('0' + now.getDate()).slice(-2), hh: ('0' + now.getHours()).slice(-2), mm: ('0' + now.getMinutes()).slice(-2), ss: ('0' + now.getSeconds()).slice(-2) } // ???????? newPath = saveDir + '/' + time.y if (!fs.existsSync(newPath)) { fs.mkdirSync(newPath) } newPath = saveDir + '/' + time.y + '/' + time.m if (!fs.existsSync(newPath)) { fs.mkdirSync(newPath) } newPath = saveDir + '/' + time.y + '/' + time.m + '/' + time.d if (!fs.existsSync(newPath)) { fs.mkdirSync(newPath) } // ?????????????????? name = time.hh + time.mm + time.ss + String(Math.random()).slice(-2) // ????????????????? url = time.y + '/' + time.m + '/' + time.d + '/' + name + ext } // ??? try { const chunkTotal = body.totalChunks const data = fs.readFileSync(oldPath) fs.unlinkSync(oldPath) if (chunkTotal > 1) { // ?????? const chunkNumber = body.chunkNumber const totalSize = body.totalSize fs.writeFileSync(newPath + '/' + totalSize + '_' + chunkNumber + ext, data) // ?????????????? if (chunkNumber === chunkTotal) { const wrStream = fs.createWriteStream(newPath + '/' + name + ext) const merge = i => { const chunkPath = newPath + '/' + totalSize + '_' + i + ext const reStream = fs.createReadStream(chunkPath) reStream.pipe(wrStream, { end: false }) reStream.once('end', () => { fs.unlinkSync(chunkPath) i < chunkTotal && merge(i + 1) }) } merge(1) } } else { // ???????? fs.writeFileSync(newPath + '/' + name + ext, data) } ctx.body = { code: 0, data: url } } catch (err) { ctx.body = { code: 3, message: '?????????' } } } } else { ctx.body = { code: 1, message: '??????????????' } } }
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de