added logging to controller files
This commit is contained in:
parent
14fc367c15
commit
5881c36986
6 changed files with 26 additions and 27 deletions
|
@ -10,6 +10,6 @@
|
||||||
"PublishUploadPath": "C:\\lbry\\speech\\hosted_content"
|
"PublishUploadPath": "C:\\lbry\\speech\\hosted_content"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "silly"
|
"LogLevel": "debug"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const logger = require('winston');
|
||||||
const lbryApi = require('../helpers/libraries/lbryApi.js');
|
const lbryApi = require('../helpers/libraries/lbryApi.js');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
const walledAddress = config.get('WalletConfig.lbryAddress');
|
||||||
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
||||||
|
|
||||||
const walledAddress = config.get('WalletConfig.lbryAddress');
|
|
||||||
|
|
||||||
function createPublishParams (claim, filePath, license, nsfw) {
|
function createPublishParams (claim, filePath, license, nsfw) {
|
||||||
console.log('nsfw:', nsfw, typeof nsfw);
|
logger.debug(`createPublishParams for ${claim}`);
|
||||||
const publishParams = {
|
const publishParams = {
|
||||||
name : claim,
|
name : claim,
|
||||||
file_path: filePath,
|
file_path: filePath,
|
||||||
|
@ -28,12 +28,13 @@ function createPublishParams (claim, filePath, license, nsfw) {
|
||||||
function deleteTemporaryFile (filePath) {
|
function deleteTemporaryFile (filePath) {
|
||||||
fs.unlink(filePath, err => {
|
fs.unlink(filePath, err => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(`successfully deleted ${filePath}`);
|
logger.info(`successfully deleted ${filePath}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish (claim, fileName, filePath, fileType, license, nsfw, socket, visitor) {
|
publish (claim, fileName, filePath, fileType, license, nsfw, socket, visitor) {
|
||||||
|
logger.debug(`publish start for ${claim}`);
|
||||||
// update the client
|
// update the client
|
||||||
socket.emit('publish-status', 'Your image is being published (this might take a second)...');
|
socket.emit('publish-status', 'Your image is being published (this might take a second)...');
|
||||||
// send to analytics
|
// send to analytics
|
||||||
|
@ -45,12 +46,10 @@ module.exports = {
|
||||||
.publishClaim(publishParams, fileName, fileType)
|
.publishClaim(publishParams, fileName, fileType)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
visitor.event('Publish Route', 'Publish Success', filePath).send();
|
visitor.event('Publish Route', 'Publish Success', filePath).send();
|
||||||
console.log('publish promise success. Tx info:', result);
|
|
||||||
socket.emit('publish-complete', { name: claim, result });
|
socket.emit('publish-complete', { name: claim, result });
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
visitor.event('Publish Route', 'Publish Failure', filePath).send();
|
visitor.event('Publish Route', 'Publish Failure', filePath).send();
|
||||||
console.log('error:', error);
|
|
||||||
socket.emit('publish-failure', errorHandlers.handlePublishError(error));
|
socket.emit('publish-failure', errorHandlers.handlePublishError(error));
|
||||||
deleteTemporaryFile(filePath);
|
deleteTemporaryFile(filePath);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
const lbryApi = require('../helpers/libraries/lbryApi.js');
|
const lbryApi = require('../helpers/libraries/lbryApi.js');
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
|
const logger = require('winston');
|
||||||
const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js');
|
const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js');
|
||||||
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
|
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
|
||||||
|
|
||||||
function getClaimAndHandleResponse (claimUri, resolve, reject) {
|
function getClaimAndHandleResponse (claimUri, resolve, reject) {
|
||||||
|
logger.debug(`getClaimAndHandleResponse start for ${claimUri}`);
|
||||||
lbryApi
|
lbryApi
|
||||||
.getClaim(claimUri)
|
.getClaim(claimUri)
|
||||||
.then(({ file_name, download_path, mime_type }) => {
|
.then(({ file_name, download_path, mime_type }) => {
|
||||||
|
@ -15,64 +16,62 @@ function getClaimAndHandleResponse (claimUri, resolve, reject) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
logger.error(`getClaimAndHandleResponse error for ${claimUri}`);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getClaimByName (claimName) {
|
getClaimByName (claimName) {
|
||||||
|
logger.debug(`getClaimByName start for ${claimName}`);
|
||||||
const deferred = new Promise((resolve, reject) => {
|
const deferred = new Promise((resolve, reject) => {
|
||||||
console.log('>> lbryHelpers >> getClaim BasedOnNameOnly:', claimName);
|
|
||||||
// get all free public claims
|
// get all free public claims
|
||||||
getAllFreePublicClaims(claimName)
|
getAllFreePublicClaims(claimName)
|
||||||
.then(freePublicClaimList => {
|
.then(freePublicClaimList => {
|
||||||
const claimId = freePublicClaimList[0].claim_id;
|
const claimId = freePublicClaimList[0].claim_id;
|
||||||
const name = freePublicClaimList[0].name;
|
const name = freePublicClaimList[0].name;
|
||||||
const freePublicClaimOutpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`;
|
const freePublicClaimOutpoint = `${freePublicClaimList[0].txid}:${freePublicClaimList[0].nout}`;
|
||||||
const freePublicClaimUri = name + '#' + claimId;
|
const freePublicClaimUri = `${name}#${claimId}`;
|
||||||
console.log('>> Decided on public claim id:', claimId);
|
|
||||||
// check to see if the file is available locally
|
// check to see if the file is available locally
|
||||||
db.File
|
db.File
|
||||||
.findOne({ where: { name: name, claimId: claimId } })
|
.findOne({ where: { name: name, claimId: claimId } })
|
||||||
.then(claim => {
|
.then(claim => {
|
||||||
// if a matching claim is found locally...
|
// if a matching claim is found locally...
|
||||||
if (claim) {
|
if (claim) {
|
||||||
console.log('>> A matching claim_id was found locally');
|
|
||||||
// if the outpoint's match return it
|
// if the outpoint's match return it
|
||||||
if (claim.dataValues.outpoint === freePublicClaimOutpoint) {
|
if (claim.dataValues.outpoint === freePublicClaimOutpoint) {
|
||||||
console.log('>> Local outpoint matched');
|
logger.debug(`local outpoint matched for ${name} ${claimId} `);
|
||||||
resolve(claim.dataValues);
|
resolve(claim.dataValues);
|
||||||
// if the outpoint's don't match, fetch updated claim
|
// if the outpoint's don't match, fetch updated claim
|
||||||
} else {
|
} else {
|
||||||
console.log('>> local outpoint did not match');
|
logger.debug(`local outpoint did not match ${name} ${claimId}`);
|
||||||
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
||||||
}
|
}
|
||||||
// ... otherwise use daemon to retrieve it
|
// ... otherwise use daemon to retrieve it
|
||||||
} else {
|
} else {
|
||||||
// 'get' the claim
|
|
||||||
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
getClaimAndHandleResponse(freePublicClaimUri, resolve, reject);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
logger.error('Sequelize encountered an error', error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
logger.debug(`getClaimByName failure for ${claimName}`);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
getClaimByClaimId (claimName, claimId) {
|
getClaimByClaimId (claimName, claimId) {
|
||||||
|
logger.debug(`getClaimByClaimId start for ${claimName}`);
|
||||||
const deferred = new Promise((resolve, reject) => {
|
const deferred = new Promise((resolve, reject) => {
|
||||||
const uri = `${claimName}#${claimId}`;
|
const uri = `${claimName}#${claimId}`;
|
||||||
console.log('>> lbryHelpers >> getClaimBasedOnUri:', uri);
|
|
||||||
// resolve the Uri
|
// resolve the Uri
|
||||||
lbryApi
|
lbryApi
|
||||||
.resolveUri(uri) // note: use 'spread' and make parallel with db.File.findOne()
|
.resolveUri(uri) // note: use 'spread' and make parallel with db.File.findOne()
|
||||||
.then(result => {
|
.then(result => {
|
||||||
// note should just be 'result' returned.
|
|
||||||
// get the outpoint
|
|
||||||
const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`;
|
const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`;
|
||||||
// check locally for the claim
|
// check locally for the claim
|
||||||
db.File
|
db.File
|
||||||
|
@ -80,21 +79,19 @@ module.exports = {
|
||||||
.then(claim => {
|
.then(claim => {
|
||||||
// if a found locally...
|
// if a found locally...
|
||||||
if (claim) {
|
if (claim) {
|
||||||
console.log('>> A matching claim_id was found locally');
|
logger.debug(`A record was found for ${claimName} ${claimId}`);
|
||||||
// if the outpoint's match return it
|
// if the outpoint's match return it
|
||||||
if (claim.dataValues.outpoint === resolvedOutpoint) {
|
if (claim.dataValues.outpoint === resolvedOutpoint) {
|
||||||
console.log('>> Local outpoint matched');
|
logger.debug(`local outpoint matched for ${claimName} ${claimId}`);
|
||||||
resolve(claim.dataValues);
|
resolve(claim.dataValues);
|
||||||
// if the outpoint's don't match, fetch updated claim
|
// if the outpoint's don't match, fetch updated claim
|
||||||
} else {
|
} else {
|
||||||
console.log('>> Local outpoint did not match');
|
logger.debug(`local outpoint did not match ${claimName} ${claimId}`);
|
||||||
getClaimAndHandleResponse(uri, resolve, reject);
|
getClaimAndHandleResponse(uri, resolve, reject);
|
||||||
}
|
}
|
||||||
// ... otherwise use daemon to retrieve it
|
// ... otherwise use daemon to retrieve it
|
||||||
} else {
|
} else {
|
||||||
// check to make sure it is free and public (note: no need for another resolve?)
|
|
||||||
if (isFreePublicClaim(result[uri].claim)) {
|
if (isFreePublicClaim(result[uri].claim)) {
|
||||||
// 'get' the claim
|
|
||||||
getClaimAndHandleResponse(uri, resolve, reject);
|
getClaimAndHandleResponse(uri, resolve, reject);
|
||||||
} else {
|
} else {
|
||||||
reject('NO_FREE_PUBLIC_CLAIMS');
|
reject('NO_FREE_PUBLIC_CLAIMS');
|
||||||
|
@ -102,10 +99,12 @@ module.exports = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
logger.error('Sequelize encountered an error', error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
logger.debug(`getClaimByClaimId error for ${claimName}`);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js');
|
const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicClaims.js');
|
||||||
|
const logger = require('winston');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAllClaims (claimName) {
|
getAllClaims (claimName) {
|
||||||
|
logger.debug(`getAllClaims start for ${claimName}`);
|
||||||
return getAllFreePublicClaims(claimName);
|
return getAllFreePublicClaims(claimName);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,7 +42,7 @@ module.exports = {
|
||||||
params: { uri, timeout: 30 },
|
params: { uri, timeout: 30 },
|
||||||
})
|
})
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
logger.silly(`getClaim success for ${uri}`);
|
logger.silly(`getClaim success for ${uri}`, data);
|
||||||
// check to make sure the daemon didn't just time out
|
// check to make sure the daemon didn't just time out
|
||||||
if (!data.result) {
|
if (!data.result) {
|
||||||
reject(JSON.stringify(data));
|
reject(JSON.stringify(data));
|
||||||
|
|
|
@ -3,7 +3,6 @@ const logger = require('winston');
|
||||||
module.exports = app => {
|
module.exports = app => {
|
||||||
// route for the home page
|
// route for the home page
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
logger.debug(`Get request on /`);
|
|
||||||
res.status(200).render('index');
|
res.status(200).render('index');
|
||||||
});
|
});
|
||||||
// a catch-all route if someone visits a page that does not exist
|
// a catch-all route if someone visits a page that does not exist
|
||||||
|
|
Loading…
Reference in a new issue