return cid, ipfsUrl
This commit is contained in:
@@ -26,11 +26,21 @@ module.exports = {
|
||||
}).single('file'),
|
||||
|
||||
api: {
|
||||
receiveFile () {
|
||||
async receiveFile () {
|
||||
const file = wo._req?.file
|
||||
if (file?.path) {
|
||||
file.path = file.path.replace('\\', '/')
|
||||
return Object.assign(file, { _state: 'SUCCESS' })
|
||||
if (wo?.ipfsStore) {
|
||||
const ipfsResult = await wo.ipfsStore.add(file, {
|
||||
cidVersion: 1,
|
||||
hashAlg: 'sha2-256',
|
||||
onlyHash: true,
|
||||
pin: false,
|
||||
})
|
||||
file.cid = ipfsResult?.cid?.toString() // + path.extname(file.filename)
|
||||
file.ipfsUrl = wo.envar.ipfsGateway + file.cid
|
||||
}
|
||||
return { _state: 'SUCCESS', ...file }
|
||||
} else {
|
||||
return { _state: 'WOBASE_FAIL_FILE_NOT_RECEIVED' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user