This commit is contained in:
陆柯 2023-08-14 11:38:35 +08:00
parent 8ce54673c2
commit dd988d4a79

View File

@ -23,7 +23,8 @@ module.exports = {
// 虽然可以把本方法写成 async 的,并且在这里调用 wo.ipfsStore.ipfs.add(file.stream) 来获取 cid但是最后在本地存成的文件是 0字节的。因此还是用个随机数吧。
// 或者,干脆利用这个缺陷,直接提交到 ipfs在本地就留着0字节文件不要使用就好了。同时在 api.receiveFile 里,就要相应的直接返回 IPFS 网址给前端。
const filename = `${Date.now()}-${crypto.randomBytes(16).toString('hex')}${path.extname(file.originalname)}`
const filename =
`${Date.now()}-${crypto.randomBytes(16).toString('hex')}` + (path.extname(file.originalname) || `.${file?.mimetype?.split?.('/')?.[1]}`)
//const _passtokenSource = webtoken.verifyToken(req.headers._passtoken) || {}
//const filename = `${req.path.replace(/^\/api\d*/, '')}_${_passtokenSource.usid}_${Date.now()}${fileNameExtension}` // 如果最终 filename 含有 / (例如当 req.path 为 Who/todo则必须已经存在该目录否则在这里就出错不会进入下面流程。
cb(null, filename)