improves quality and reduces noise in logs
This commit is contained in:
parent
b2e35c7e13
commit
b2624026bb
9 changed files with 473 additions and 432 deletions
|
@ -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
816
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -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}`);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
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 db = require('server/models');
|
||||
const { publishClaim } = require('server/lbrynet');
|
||||
const { createFileRecordDataAfterPublish } = require('server/models/utils/createFileRecordData.js');
|
||||
const {
|
||||
createClaimRecordDataAfterPublish,
|
||||
} = require('server/models/utils/createClaimRecordData.js');
|
||||
const deleteFile = require('./deleteFile.js');
|
||||
|
||||
const publish = async (publishParams, fileName, fileType) => {
|
||||
|
@ -13,7 +15,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,13 +31,25 @@ 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 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);
|
||||
}
|
||||
|
@ -44,24 +58,22 @@ const publish = async (publishParams, fileName, fileType) => {
|
|||
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 });
|
||||
} 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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -8,6 +8,7 @@ import createSagaMiddleware from 'redux-saga';
|
|||
import { call } from 'redux-saga/effects';
|
||||
import Helmet from 'react-helmet';
|
||||
import * as httpContext from 'express-http-context';
|
||||
import logger from 'winston';
|
||||
|
||||
import Reducers from '@reducers';
|
||||
import GAListener from '@components/GAListener';
|
||||
|
@ -92,6 +93,7 @@ export default (req, res) => {
|
|||
const preloadedState = store.getState();
|
||||
|
||||
// send the rendered page back to the client
|
||||
|
||||
res.send(renderFullPage(helmet, html, preloadedState));
|
||||
};
|
||||
|
||||
|
@ -121,8 +123,8 @@ export default (req, res) => {
|
|||
}
|
||||
|
||||
if (canonicalUrl && canonicalUrl !== req.originalUrl) {
|
||||
console.log(`redirecting ${req.originalUrl} to ${canonicalUrl}`);
|
||||
res.redirect(canonicalUrl);
|
||||
logger.verbose(`redirecting ${req.originalUrl} to ${canonicalUrl}`);
|
||||
return res.redirect(canonicalUrl);
|
||||
}
|
||||
|
||||
return renderPage(store);
|
||||
|
|
|
@ -14,9 +14,9 @@ function configureLogging () {
|
|||
// configure the winston logger
|
||||
logger.configure({
|
||||
transports: [
|
||||
new (logger.transports.Console)({
|
||||
new logger.transports.Console({
|
||||
level: logLevel || 'debug',
|
||||
timestamp : false,
|
||||
timestamp: true,
|
||||
colorize: true,
|
||||
prettyPrint: true,
|
||||
handleExceptions: true,
|
||||
|
|
Loading…
Reference in a new issue