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
2018-07-30 22:48:47 +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 )
2018-04-29 21:17:23 +02:00
. 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 => {
2018-04-29 21:17:23 +02:00
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' ,
2018-04-29 21:17:23 +02:00
} ) ;
}
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-04-29 21:17:23 +02:00
} ) ;
}
2018-03-29 20:24:52 +02:00
handleErrorResponse ( originalUrl , ip , error , res ) ;
} ) ;
2018-03-29 02:35:41 +02:00
} ;
module . exports = claimLongId ;