u
This commit is contained in:
		
							parent
							
								
									e79240db0f
								
							
						
					
					
						commit
						4be9a78e6d
					
				@ -7,9 +7,10 @@ const wo = global.wo
 | 
			
		||||
const my = {}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
  initMy ({ ipfsProvider, ipfsStore }) {
 | 
			
		||||
  initMy ({ ipfsProvider, ipfsStore, fileSizeLimit }) {
 | 
			
		||||
    my.ipfsProvider = ipfsProvider
 | 
			
		||||
    my.ipfsStore = ipfsStore
 | 
			
		||||
    my.fileSizeLimit = fileSizeLimit
 | 
			
		||||
    return this
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
@ -34,7 +35,7 @@ module.exports = {
 | 
			
		||||
      },
 | 
			
		||||
    }),
 | 
			
		||||
    // fileFilter:function(req, file, cb) {},
 | 
			
		||||
    limits: { fileSize: 10485760 },
 | 
			
		||||
    limits: { fileSize: my.fileSizeLimit || 10485760 },
 | 
			
		||||
  }).single('file'),
 | 
			
		||||
 | 
			
		||||
  api: {
 | 
			
		||||
@ -59,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 = `${_file.cid}${path.extname(_file.filename)}`
 | 
			
		||||
          const newFileName = `${Date.now()}-${_file.cid}${path.extname(_file.filename)}`
 | 
			
		||||
          try {
 | 
			
		||||
            await fs.renameSync(
 | 
			
		||||
              path.resolve(_file.path),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user