This commit is contained in:
Luk 2024-07-03 21:22:05 +08:00
parent e79240db0f
commit 4be9a78e6d

View File

@ -7,9 +7,10 @@ const wo = global.wo
const my = {} const my = {}
module.exports = { module.exports = {
initMy ({ ipfsProvider, ipfsStore }) { initMy ({ ipfsProvider, ipfsStore, fileSizeLimit }) {
my.ipfsProvider = ipfsProvider my.ipfsProvider = ipfsProvider
my.ipfsStore = ipfsStore my.ipfsStore = ipfsStore
my.fileSizeLimit = fileSizeLimit
return this return this
}, },
@ -34,7 +35,7 @@ module.exports = {
}, },
}), }),
// fileFilter:function(req, file, cb) {}, // fileFilter:function(req, file, cb) {},
limits: { fileSize: 10485760 }, limits: { fileSize: my.fileSizeLimit || 10485760 },
}).single('file'), }).single('file'),
api: { api: {
@ -59,7 +60,7 @@ module.exports = {
_file.cid = cid?.toString() // + path.extname(file.filename) _file.cid = cid?.toString() // + path.extname(file.filename)
_file.ipfsUrl = `${global.wo?.envar?.ipfsGateway?.replace?.(/\/$/, '')}/${_file.cid}` // 1) 前端自己选用 cid 或 ipfsUrl。2) 在本地测试成功,但是发现第一次上传的文件,作为 ipfs url 图片在前端显示比较慢不如作为传统服务器的快。第二次上传同样文件的ipfs前端显示就快了。 _file.ipfsUrl = `${global.wo?.envar?.ipfsGateway?.replace?.(/\/$/, '')}/${_file.cid}` // 1) 前端自己选用 cid 或 ipfsUrl。2) 在本地测试成功,但是发现第一次上传的文件,作为 ipfs url 图片在前端显示比较慢不如作为传统服务器的快。第二次上传同样文件的ipfs前端显示就快了。
// rename the file to the cid // rename the file to the cid
const newFileName = `${_file.cid}${path.extname(_file.filename)}` const newFileName = `${Date.now()}-${_file.cid}${path.extname(_file.filename)}`
try { try {
await fs.renameSync( await fs.renameSync(
path.resolve(_file.path), path.resolve(_file.path),