Compare commits

...

15 commits

Author SHA1 Message Date
jessop
604a74dc19 makes changes for better logging and removes an unnecessary resolve when bots visit 2019-04-18 16:55:48 -04:00
jessopb
d84c964ae0
Merge pull request #1002 from jessopb/changelogging
adds timestamp to logging
2019-04-18 15:04:00 -04:00
jessop
8d98fc13fc adds timestamp to logging 2019-04-18 11:58:36 -04:00
jessopb
4d596c6b32
Merge pull request #1001 from lbryio/revert-983-localclaimdb
Revert "removing dependency on localdb claim table"
2019-04-18 11:53:53 -04:00
jessopb
59ce387262
Revert "removing dependency on localdb claim table" 2019-04-18 11:53:27 -04:00
jessopb
a1d3d1546c
Merge pull request #1000 from lbryio/revert-990-norequire
Revert "ES5 require to ES6 import"
2019-04-18 11:51:53 -04:00
jessopb
4733264f0e
Revert "ES5 require to ES6 import" 2019-04-18 11:51:21 -04:00
jessopb
4ced80f4bb
Merge pull request #999 from lbryio/revert-994-changelogging
Revert "adds timestamp and relevance to logs"
2019-04-18 11:46:59 -04:00
jessopb
9e4cc9dabb
Revert "adds timestamp and relevance to logs" 2019-04-18 11:46:44 -04:00
jessopb
c7ba68ca79
Merge pull request #994 from jessopb/changelogging
adds timestamp and relevance to logs
2019-04-17 11:52:23 -04:00
jessop
656b159fce adds timestamp and relevance to logs 2019-04-17 11:33:34 -04:00
jessopb
5e92393f48
Merge pull request #990 from jessopb/norequire
ES5 require to ES6 import
2019-04-16 15:40:51 -04:00
jessop
dd0886baf4 replaces most require with es6 import/export 2019-04-12 10:25:06 -04:00
jessopb
042069f759
Merge pull request #983 from jessopb/localclaimdb
removing dependency on localdb claim table
2019-04-09 08:20:02 -04:00
jessop
cf24a39d0b WIP removing dependency on localdb claim table 2019-04-03 11:05:53 -04:00
8 changed files with 469 additions and 428 deletions

View file

@ -7,7 +7,6 @@ import Img from 'react-image';
const AssetPreview = ({ defaultThumbnail, claimData }) => {
const {name, fileExt, contentType, thumbnail, title, blocked, transactionTime = 0} = claimData;
const showUrl = createCanonicalLink({asset: {...claimData}});
console.log(transactionTime)
const embedUrl = `${showUrl}.${fileExt}`;
const ago = Date.now() / 1000 - transactionTime;
const dayInSeconds = 60 * 60 * 24;

816
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@ const claimGet = async ({ ip, originalUrl, params, headers }, res) => {
try {
let claimInfo = await chainquery.claim.queries.resolveClaim(name, claimId).catch(() => {});
if (claimInfo) {
logger.info('claim/get: claim resolved in chainquery');
logger.debug(`claim/get: claim resolved in chainquery`);
}
if (!claimInfo) {
claimInfo = await db.Claim.resolveClaim(name, claimId);
@ -30,15 +30,15 @@ const claimGet = async ({ ip, originalUrl, params, headers }, res) => {
throw new Error('claim/get: resolveClaim: No matching uri found in Claim table');
}
if (headers && headers['user-agent'] && isBot(headers['user-agent'])) {
let lbrynetResolveResult = await resolveUri(`${name}#${claimId}`);
const { message, completed } = lbrynetResolveResult;
logger.info(`Bot GetClaim: claimId: ${claimId}`);
res.status(200).json({
success: true,
message,
message: 'bot',
completed: false,
});
return true;
}
logger.info(`GetClaim: ${claimId} UA: ${headers['user-agent']}`);
let lbrynetResult = await getClaim(`${name}#${claimId}`);
if (!lbrynetResult) {
throw new Error(`claim/get: getClaim Unable to Get ${name}#${claimId}`);

View file

@ -141,12 +141,12 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
return publish(publishParams, fileName, fileType, filePath);
})
.then(publishResults => {
logger.info('Publish success >', publishResults);
logger.debug('Publish success >', publishResults);
claimData = publishResults;
({ claimId } = claimData);
if (channelName) {
logger.info(`api/claim/publish: claimData.certificateId ${claimData.certificateId}`);
logger.debug(`api/claim/publish: claimData.certificateId ${claimData.certificateId}`);
return chainquery.claim.queries.getShortClaimIdFromLongClaimId(
claimData.certificateId,
channelName

View file

@ -1,8 +1,12 @@
const logger = require('winston');
const db = require('../../../../models');
const { publishClaim } = require('../../../../lbrynet');
const { createFileRecordDataAfterPublish } = require('../../../../models/utils/createFileRecordData.js');
const { createClaimRecordDataAfterPublish } = require('../../../../models/utils/createClaimRecordData.js');
const {
createFileRecordDataAfterPublish,
} = require('../../../../models/utils/createFileRecordData.js');
const {
createClaimRecordDataAfterPublish,
} = require('../../../../models/utils/createClaimRecordData.js');
const deleteFile = require('./deleteFile.js');
const publish = async (publishParams, fileName, fileType) => {
@ -13,7 +17,7 @@ const publish = async (publishParams, fileName, fileType) => {
try {
publishResults = await publishClaim(publishParams);
logger.info(`Successfully published ${publishParams.name} ${fileName}`, publishResults);
logger.verbose(`Successfully published ${publishParams.name} ${fileName}`, publishResults);
const outpoint = `${publishResults.output.txid}:${publishResults.output.nout}`;
// get the channel information
if (publishParams.channel_name) {
@ -29,39 +33,49 @@ const publish = async (publishParams, fileName, fileType) => {
const certificateId = channel ? channel.channelClaimId : null;
const channelName = channel ? channel.channelName : null;
const claimRecord = await createClaimRecordDataAfterPublish(certificateId, channelName, fileName, fileType, publishParams, publishResults);
const {claimId} = claimRecord;
const upsertCriteria = {name: publishParams.name, claimId};
const claimRecord = await createClaimRecordDataAfterPublish(
certificateId,
channelName,
fileName,
fileType,
publishParams,
publishResults
);
const { claimId } = claimRecord;
const upsertCriteria = { name: publishParams.name, claimId };
if (newFile) {
// this is the problem
//
fileRecord = await createFileRecordDataAfterPublish(fileName, fileType, publishParams, publishResults);
fileRecord = await createFileRecordDataAfterPublish(
fileName,
fileType,
publishParams,
publishResults
);
} else {
fileRecord = await db.File.findOne({where: {claimId}}).then(result => result.dataValues);
fileRecord = await db.File.findOne({ where: { claimId } }).then(result => result.dataValues);
}
const [file, claim] = await Promise.all([
db.upsert(db.File, fileRecord, upsertCriteria, 'File'),
db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim'),
]);
logger.info(`File and Claim records successfully created (${publishParams.name})`);
logger.debug(`File and Claim records successfully created (${publishParams.name})`);
await Promise.all([
file.setClaim(claim),
claim.setFile(file),
]);
logger.info(`File and Claim records successfully associated (${publishParams.name})`);
await Promise.all([file.setClaim(claim), claim.setFile(file)]);
logger.debug(`File and Claim records successfully associated (${publishParams.name})`);
return Object.assign({}, claimRecord, {outpoint});
return Object.assign({}, claimRecord, { outpoint });
} catch (err) {
// parse daemon response when err is a string
// this needs work
logger.info('publish/publish err:', err);
logger.error('publish/publish err:', err);
const error = typeof err === 'string' ? JSON.parse(err) : err;
if (publishParams.file_path) {
await deleteFile(publishParams.file_path);
}
const message = error.error && error.error.message ? error.error.message : 'Unknown publish error';
const message =
error.error && error.error.message ? error.error.message : 'Unknown publish error';
return {
error: true,
message,

View file

@ -38,7 +38,7 @@ const rando = () => {
const claimUpdate = ({ body, files, headers, ip, originalUrl, user, tor }, res) => {
// logging
logger.info('Claim update request:', {
logger.debug('Claim update request:', {
ip,
headers,
body,

View file

@ -388,7 +388,9 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
return new Promise((resolve, reject) => {
this.fetchClaim(name, claimId)
.then(claim => {
logger.info('resolveClaim claims:', claim);
logger.debug(
`resolveClaim: ${name}, ${claimId}, -> certificateId: ${claim && claim.certificateId}`
);
if (
serveOnlyApproved &&
!isApprovedChannel({ longId: claim.certificateId }, approvedChannels)

View file

@ -3,7 +3,7 @@ const logger = require('winston');
const config = require('@config/loggerConfig');
const { logLevel } = config;
function configureLogging () {
function configureLogging() {
logger.info('configuring winston logger...');
if (!config) {
return logger.warn('No logger config found');
@ -14,12 +14,12 @@ function configureLogging () {
// configure the winston logger
logger.configure({
transports: [
new (logger.transports.Console)({
level : logLevel || 'debug',
timestamp : false,
colorize : true,
prettyPrint : true,
handleExceptions : true,
new logger.transports.Console({
level: logLevel || 'debug',
timestamp: true,
colorize: true,
prettyPrint: true,
handleExceptions: true,
humanReadableUnhandledException: true,
}),
],