makes changes for better logging and removes an unnecessary resolve when bots visit
This commit is contained in:
parent
d84c964ae0
commit
604a74dc19
7 changed files with 462 additions and 421 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,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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue