created local version of lbry api

This commit is contained in:
bill bittner 2017-08-15 13:48:42 -07:00
parent 1a169565bd
commit 13c5f5dfdb
6 changed files with 23 additions and 16 deletions

View file

@ -32,7 +32,7 @@ module.exports = (claimName) => {
return new Promise((resolve, reject) => {
// make a call to the daemon to get the claims list
lbryApi
.getClaimsList(claimName)
.getClaimList(claimName)
.then(({ claims }) => {
logger.debug(`Number of claims: ${claims.length}`);
// return early if no claims were found

View file

@ -61,7 +61,7 @@ module.exports = {
});
});
},
getClaimsList (claimName) {
getClaimList (claimName) {
logger.debug(`lbryApi >> Getting claim_list for "${claimName}"`);
return new Promise((resolve, reject) => {
axios

View file

@ -2,13 +2,12 @@ const logger = require('winston');
const db = require('../models');
module.exports = {
getLocalClaimsList (name) {
getLocalClaimList (name) {
logger.debug(`db.Claim >> Getting claim_list for "${name}"`);
return db.Claim.findAll({ name })
.then(result => {
logger.debug('db.claim result length', result.length);
if (result.length >= 1) {
console.log('there was a result');
result = result.map(claim => {
return claim.dataValues;
});
@ -40,8 +39,8 @@ module.exports = {
return error;
});
},
createClaimEntryFromLbryResolve (claim) {
logger.debug('db.Claim >> creating claim entry from lbry resolve');
updateLocalClaimRecordFromResolve (claim) {
logger.debug('db.Claim >> creating claim entry from lbry resolve results');
// parse the resolved data
let claimData = {};
claimData['address'] = claim.address;
@ -84,14 +83,14 @@ module.exports = {
claimData['valueVersion'] = claim.value.version;
}
// create search criteria
const searchCriteria = { name: claimData.name, claimId: claimData.claimId };
const updateCriteria = { name: claimData.name, claimId: claimData.claimId };
// create entry in db
db.upsert(db.Claim, claimData, searchCriteria)
.then(() => {
logger.debug('successfully added data to db.Claim');
db.Claim.update(claimData, updateCriteria)
.then((rows, result) => {
logger.debug('successfully updated record in db.Claim');
})
.catch(error => {
logger.error('Sequelize findOne error', error);
logger.error('db.Claim.update error', error);
});
},
};

View file

@ -118,9 +118,9 @@ module.exports = {
return new Promise((resolve, reject) => {
logger.debug('getting claim_id from short url');
// use the daemon to check for claims list
lbryApi.getClaimsList(name)
lbryApi.getClaimList(name)
.then(({ claims }) => {
logger.debug('Number of claims from getClaimsList:', claims.length);
logger.debug('Number of claims from getClaimList:', claims.length);
// if no claims were found, check locally for possible claims
if (claims.length === 0) {
return checkLocalDbForClaims(name, shortId);
@ -159,7 +159,7 @@ module.exports = {
return new Promise((resolve, reject) => {
logger.debug('finding short claim id from full claim id');
// get a list of all the claims
lbryApi.getClaimsList(name)
lbryApi.getClaimList(name)
// find the smallest possible unique url for this claim
.then(({ claims }) => {
const shortId = determineShortClaimId(claimId, height, claims);

View file

@ -66,18 +66,26 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
type : STRING,
default: null,
},
certificateId: {
type : STRING,
default: null,
},
author: {
type : STRING,
default: null,
},
description: {
type : STRING,
type : TEXT('long'),
default: null,
},
language: {
type : STRING,
default: null,
},
license: {
type : STRING,
default: null,
},
licenseUrl: {
type : STRING,
default: null,

View file

@ -14,7 +14,7 @@ module.exports = (app, hostedContentPath) => {
sendGoogleAnalytics('SERVE', headers, ip, originalUrl);
// serve the content
lbryApi
.getClaimsList(params.name)
.getClaimList(params.name)
.then(claimsList => {
postToStats('serve', originalUrl, ip, null, null, 'success');
res.status(200).json(claimsList);