return cid, ipfsUrl

This commit is contained in:
Luk Lu
2022-12-10 18:46:54 +08:00
parent f7a7a72414
commit 4a23a35e95
2 changed files with 92 additions and 48 deletions

View File

@@ -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' }
}