2018-04-27 04:19:11 +02:00
|
|
|
const { getClaim } = require('../../utils/lbryApi.js');
|
2018-03-29 02:35:41 +02:00
|
|
|
const { addGetResultsToFileData, createFileData } = require('../../helpers/publishHelpers.js');
|
2018-04-27 03:50:47 +02:00
|
|
|
const { handleErrorResponse } = require('../utils/errorHandlers.js');
|
2018-04-17 23:54:10 +02:00
|
|
|
const db = require('../../models');
|
2018-03-29 02:35:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
route to get a claim
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-03-29 20:24:52 +02:00
|
|
|
const claimGet = ({ ip, originalUrl, params }, res) => {
|
|
|
|
const name = params.name;
|
|
|
|
const claimId = params.claimId;
|
|
|
|
// resolve the claim
|
|
|
|
db.Claim.resolveClaim(name, claimId)
|
|
|
|
.then(resolveResult => {
|
|
|
|
// make sure a claim actually exists at that uri
|
|
|
|
if (!resolveResult) {
|
|
|
|
throw new Error('No matching uri found in Claim table');
|
|
|
|
}
|
|
|
|
let fileData = createFileData(resolveResult);
|
|
|
|
// get the claim
|
|
|
|
return Promise.all([fileData, getClaim(`${name}#${claimId}`)]);
|
|
|
|
})
|
|
|
|
.then(([ fileData, getResult ]) => {
|
|
|
|
fileData = addGetResultsToFileData(fileData, getResult);
|
|
|
|
return Promise.all([db.upsert(db.File, fileData, {name, claimId}, 'File'), getResult]);
|
|
|
|
})
|
|
|
|
.then(([ fileRecord, {message, completed} ]) => {
|
|
|
|
res.status(200).json({ success: true, message, completed });
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
handleErrorResponse(originalUrl, ip, error, res);
|
|
|
|
});
|
2018-03-29 02:35:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = claimGet;
|