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) => { return new Promise((resolve, reject) => {
// make a call to the daemon to get the claims list // make a call to the daemon to get the claims list
lbryApi lbryApi
.getClaimsList(claimName) .getClaimList(claimName)
.then(({ claims }) => { .then(({ claims }) => {
logger.debug(`Number of claims: ${claims.length}`); logger.debug(`Number of claims: ${claims.length}`);
// return early if no claims were found // 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}"`); logger.debug(`lbryApi >> Getting claim_list for "${claimName}"`);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios axios

View file

@ -2,13 +2,12 @@ const logger = require('winston');
const db = require('../models'); const db = require('../models');
module.exports = { module.exports = {
getLocalClaimsList (name) { getLocalClaimList (name) {
logger.debug(`db.Claim >> Getting claim_list for "${name}"`); logger.debug(`db.Claim >> Getting claim_list for "${name}"`);
return db.Claim.findAll({ name }) return db.Claim.findAll({ name })
.then(result => { .then(result => {
logger.debug('db.claim result length', result.length); logger.debug('db.claim result length', result.length);
if (result.length >= 1) { if (result.length >= 1) {
console.log('there was a result');
result = result.map(claim => { result = result.map(claim => {
return claim.dataValues; return claim.dataValues;
}); });
@ -40,8 +39,8 @@ module.exports = {
return error; return error;
}); });
}, },
createClaimEntryFromLbryResolve (claim) { updateLocalClaimRecordFromResolve (claim) {
logger.debug('db.Claim >> creating claim entry from lbry resolve'); logger.debug('db.Claim >> creating claim entry from lbry resolve results');
// parse the resolved data // parse the resolved data
let claimData = {}; let claimData = {};
claimData['address'] = claim.address; claimData['address'] = claim.address;
@ -84,14 +83,14 @@ module.exports = {
claimData['valueVersion'] = claim.value.version; claimData['valueVersion'] = claim.value.version;
} }
// create search criteria // create search criteria
const searchCriteria = { name: claimData.name, claimId: claimData.claimId }; const updateCriteria = { name: claimData.name, claimId: claimData.claimId };
// create entry in db // create entry in db
db.upsert(db.Claim, claimData, searchCriteria) db.Claim.update(claimData, updateCriteria)
.then(() => { .then((rows, result) => {
logger.debug('successfully added data to db.Claim'); logger.debug('successfully updated record in db.Claim');
}) })
.catch(error => { .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) => { return new Promise((resolve, reject) => {
logger.debug('getting claim_id from short url'); logger.debug('getting claim_id from short url');
// use the daemon to check for claims list // use the daemon to check for claims list
lbryApi.getClaimsList(name) lbryApi.getClaimList(name)
.then(({ claims }) => { .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 no claims were found, check locally for possible claims
if (claims.length === 0) { if (claims.length === 0) {
return checkLocalDbForClaims(name, shortId); return checkLocalDbForClaims(name, shortId);
@ -159,7 +159,7 @@ module.exports = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
logger.debug('finding short claim id from full claim id'); logger.debug('finding short claim id from full claim id');
// get a list of all the claims // get a list of all the claims
lbryApi.getClaimsList(name) lbryApi.getClaimList(name)
// find the smallest possible unique url for this claim // find the smallest possible unique url for this claim
.then(({ claims }) => { .then(({ claims }) => {
const shortId = determineShortClaimId(claimId, height, 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, type : STRING,
default: null, default: null,
}, },
certificateId: {
type : STRING,
default: null,
},
author: { author: {
type : STRING, type : STRING,
default: null, default: null,
}, },
description: { description: {
type : STRING, type : TEXT('long'),
default: null, default: null,
}, },
language: { language: {
type : STRING, type : STRING,
default: null, default: null,
}, },
license: {
type : STRING,
default: null,
},
licenseUrl: { licenseUrl: {
type : STRING, type : STRING,
default: null, default: null,

View file

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