u
This commit is contained in:
		
							parent
							
								
									51e2ff7f2f
								
							
						
					
					
						commit
						d6740c4c20
					
				@ -43,10 +43,14 @@ module.exports = {
 | 
			
		||||
      // req 被 multer 处理后,req.file 为 { destination, filename, originialname, path, mimetype, size }, 其中 path 包括了 destination 和 filename 的文件相对路径,但不包括起头的 '/',例如 '_filestore/xxx.png'
 | 
			
		||||
      const ipfsProvider = my.ipfsProvider || global.wo?.ipfsProvider
 | 
			
		||||
      const ipfsStore = my.ipfsStore || global.wo?.ipfsStore
 | 
			
		||||
      if (_file?.path) {
 | 
			
		||||
 | 
			
		||||
      if (!_file?.path) {
 | 
			
		||||
        return { _state: 'WOBASE_FAIL_FILE_NOT_RECEIVED' }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      _file.path = _file.path.replace('\\', '/')
 | 
			
		||||
      _file.baseUrl = `${global.wo?.envar?.servUrl?.replace?.(/\/$/, '')}/${_file.path}` // 传统的基于服务器的 url。在开发环境下,不一定符合前端实际,因为后台只知道预设的 servUrl,而前端会再根据 location.origin 来调整。
 | 
			
		||||
        if (useIpfs && ipfsStore) {
 | 
			
		||||
      if (useIpfs && ipfsStore && ipfsProvider) {
 | 
			
		||||
        // 为了在这里使用 wo.ipfsStore.add, 需要提供 FileContent,不能直接用 req.file
 | 
			
		||||
        // 20230312: not working with nodejs above (not including) 18.2.1! https://github.com/nodejs/node/issues/46221
 | 
			
		||||
        const { cid } = await ipfsStore?.add?.(ipfsProvider.globSource(_file.path, ''), {
 | 
			
		||||
@ -73,11 +77,8 @@ module.exports = {
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
          console.log('FileLoader: rename failed: ', path.resolve(_file.filename), e)
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      return { _state: 'SUCCESS', ..._file }
 | 
			
		||||
        } else {
 | 
			
		||||
          return { _state: 'WOBASE_FAIL_FILE_NOT_RECEIVED' }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user