|
@@ -73,17 +73,23 @@ module.exports = function (storage, runtime, ipfsHttpGatewayUrl, anonymous) {
|
|
|
|
|
|
const id = req.params.id // content id
|
|
|
|
|
|
- // Check if we're the liaison for the content
|
|
|
+ // Check if content exists
|
|
|
const roleAddress = runtime.identities.key.address
|
|
|
const providerId = runtime.storageProviderId
|
|
|
let dataObject
|
|
|
+
|
|
|
try {
|
|
|
- dataObject = await runtime.assets.checkLiaisonForDataObject(providerId, id)
|
|
|
+ dataObject = await runtime.assets.getDataObject(id)
|
|
|
} catch (err) {
|
|
|
errorHandler(res, err, 403)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if (!dataObject) {
|
|
|
+ res.status(404).send({ message: 'Content Not Found' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// Early filtering on content_length..do not wait for fileInfo
|
|
|
// ensure its less than max allowed by node policy.
|
|
|
const filterResult = filter({}, req.headers)
|
|
@@ -156,7 +162,6 @@ module.exports = function (storage, runtime, ipfsHttpGatewayUrl, anonymous) {
|
|
|
if (filterResult.code !== 200) {
|
|
|
debug('Rejecting content')
|
|
|
stream.cleanup()
|
|
|
- await runtime.assets.rejectContent(roleAddress, providerId, id)
|
|
|
res.status(400).send({ message: 'Rejecting content type' })
|
|
|
} else {
|
|
|
try {
|
|
@@ -181,14 +186,21 @@ module.exports = function (storage, runtime, ipfsHttpGatewayUrl, anonymous) {
|
|
|
|
|
|
try {
|
|
|
debug('accepting Content')
|
|
|
- await runtime.assets.acceptContent(roleAddress, providerId, id)
|
|
|
+ // Only if judegment is Pending
|
|
|
+ if (dataObject.liaison_judgement.type === 'Pending') {
|
|
|
+ await runtime.assets.acceptContent(roleAddress, providerId, id)
|
|
|
+ }
|
|
|
|
|
|
- debug('creating storage relationship for newly uploaded content')
|
|
|
- // Create storage relationship and flip it to ready.
|
|
|
- const dosrId = await runtime.assets.createStorageRelationship(roleAddress, providerId, id)
|
|
|
+ // Is there any real value in updating this state? Nobody uses it!
|
|
|
+ const { relationshipId } = await runtime.assets.getStorageRelationshipAndId(providerId, id)
|
|
|
+ if (!relationshipId) {
|
|
|
+ debug('creating storage relationship for newly uploaded content')
|
|
|
+ // Create storage relationship and flip it to ready.
|
|
|
+ const dosrId = await runtime.assets.createStorageRelationship(roleAddress, providerId, id)
|
|
|
|
|
|
- debug('toggling storage relationship for newly uploaded content')
|
|
|
- await runtime.assets.toggleStorageRelationshipReady(roleAddress, providerId, dosrId, true)
|
|
|
+ debug('toggling storage relationship for newly uploaded content')
|
|
|
+ await runtime.assets.toggleStorageRelationshipReady(roleAddress, providerId, dosrId, true)
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
debug(`${err.message}`)
|
|
|
}
|