spee.ch/server/controllers/api/claim/longId/index.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-04-29 22:00:41 +02:00
const db = require('../../../../models');
2018-04-27 18:54:36 +02:00
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
2018-03-29 02:35:41 +02:00
const getClaimId = require('../../../utils/getClaimId.js');
2018-04-29 22:00:41 +02:00
2018-03-29 02:35:41 +02:00
const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM';
2018-04-29 22:00:41 +02:00
const BLOCKED_CLAIM = 'BLOCKED_CLAIM';
2018-03-29 02:35:41 +02:00
/*
route to get a long claim id
*/
2018-03-29 20:24:52 +02:00
const claimLongId = ({ ip, originalUrl, body, params }, res) => {
const channelName = body.channelName;
const channelClaimId = body.channelClaimId;
const claimName = body.claimName;
2018-04-29 22:00:41 +02:00
let claimId = body.claimId;
2018-03-29 20:24:52 +02:00
getClaimId(channelName, channelClaimId, claimName, claimId)
.then(fullClaimId => {
2018-04-29 22:00:41 +02:00
claimId = fullClaimId;
2018-07-02 22:53:52 +02:00
return db.Claim.getOutpoint(claimName, fullClaimId);
})
.then(outpoint => {
return db.Blocked.isNotBlocked(outpoint);
2018-04-29 22:00:41 +02:00
})
.then(() => {
res.status(200).json({success: true, data: claimId});
2018-03-29 20:24:52 +02:00
})
.catch(error => {
if (error === NO_CLAIM) {
return res.status(404).json({
success: false,
2018-04-29 22:00:41 +02:00
message: 'No matching claim id could be found for that url',
});
}
if (error === NO_CHANNEL) {
return res.status(404).json({
success: false,
2018-04-29 22:00:41 +02:00
message: 'No matching channel id could be found for that url',
});
}
if (error === BLOCKED_CLAIM) {
return res.status(410).json({
success: false,
message: 'In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this content from our applications. For more details, see https://lbry.io/faq/dmca',
});
}
2018-03-29 20:24:52 +02:00
handleErrorResponse(originalUrl, ip, error, res);
});
2018-03-29 02:35:41 +02:00
};
module.exports = claimLongId;