save the received file with datetime digits

This commit is contained in:
Luk 2024-07-08 20:36:00 +08:00
parent 4be9a78e6d
commit d33e87c3e1

View File

@ -60,7 +60,7 @@ module.exports = {
_file.cid = cid?.toString() // + path.extname(file.filename)
_file.ipfsUrl = `${global.wo?.envar?.ipfsGateway?.replace?.(/\/$/, '')}/${_file.cid}` // 1) 前端自己选用 cid 或 ipfsUrl。2) 在本地测试成功,但是发现第一次上传的文件,作为 ipfs url 图片在前端显示比较慢不如作为传统服务器的快。第二次上传同样文件的ipfs前端显示就快了。
// rename the file to the cid
const newFileName = `${Date.now()}-${_file.cid}${path.extname(_file.filename)}`
const newFileName = `${new Date().toJSON().replace(/[-:T]|\.\d\d\dZ$/g, '')}-${_file.cid}${path.extname(_file.filename)}`
try {
await fs.renameSync(
path.resolve(_file.path),