rename envi to envar

This commit is contained in:
陆柯 2022-04-03 16:19:04 +08:00
parent 0a4cf537d1
commit e722b2dca2

View File

@ -10,13 +10,13 @@ module.exports = {
storage: multer.diskStorage({ storage: multer.diskStorage({
destination (req, file, cb) { destination (req, file, cb) {
// 如果直接提供字符串multer会负责创建该目录。如果提供函数你要负责确保该目录存在。 // 如果直接提供字符串multer会负责创建该目录。如果提供函数你要负责确保该目录存在。
cb(null, wo?.envi?.File_Store) // 目录是相对于本应用的入口js的即相对于 server.js 的位置。 cb(null, wo?.envar?.File_Store) // 目录是相对于本应用的入口js的即相对于 server.js 的位置。
}, },
filename (req, file, cb) { filename (req, file, cb) {
// 注意req.body 也许还没有信息因为这取决于客户端发送body和file的顺序。必要的信息请从 req.headers 传递,例如 _passtoken在multer时尚未进入路由不存在已装好的 _passtokenSource // 注意req.body 也许还没有信息因为这取决于客户端发送body和file的顺序。必要的信息请从 req.headers 传递,例如 _passtoken在multer时尚未进入路由不存在已装好的 _passtokenSource
const fileNameExtension = path.extname(file.originalname) const fileNameExtension = path.extname(file.originalname)
const filename = `${Date.now()}_${crypto.randomBytes(16).toString('hex')}${fileNameExtension}` const filename = `${Date.now()}_${crypto.randomBytes(16).toString('hex')}${fileNameExtension}`
//const _passtokenSource = webtoken.verifyToken(req.headers._passtoken, wo.envi.tokenKey) || {} //const _passtokenSource = webtoken.verifyToken(req.headers._passtoken, wo.envar.tokenKey) || {}
//const filename = `${req.path.replace(/^\/api\d*/, '')}_${_passtokenSource.uuid}_${Date.now()}${fileNameExtension}` // 如果最终 filename 含有 / (例如当 req.path 为 Who/todo则必须已经存在该目录否则在这里就出错不会进入下面流程。 //const filename = `${req.path.replace(/^\/api\d*/, '')}_${_passtokenSource.uuid}_${Date.now()}${fileNameExtension}` // 如果最终 filename 含有 / (例如当 req.path 为 Who/todo则必须已经存在该目录否则在这里就出错不会进入下面流程。
cb(null, filename) cb(null, filename)
}, },