Separated pay, claim, and change wallet addresses #44
10 changed files with 46 additions and 21 deletions
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"WalletConfig": {
|
"WalletConfig": {
|
||||||
"LbryAddress": "LBRY_WALLET_ADDRESS"
|
"LbryPayAddress": "LBRY_PAY_ADDRESS",
|
||||||
|
"LbryClaimAddress": "LBRY_CLAIM_ADDRESS",
|
||||||
|
"LbryChangeAddress": "LBRY_CHANGE_ADDRESS"
|
||||||
},
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"MySqlConnectionUri": "MYSQL_CONNECTION_STRING"
|
"MySqlConnectionUri": "MYSQL_CONNECTION_STRING"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"WalletConfig": {
|
"WalletConfig": {
|
||||||
"LbryAddress": "none"
|
"LbryPayAddress": "none",
|
||||||
|
"LbryClaimAddress": "none",
|
||||||
|
"LbryChangeAddress": "none"
|
||||||
},
|
},
|
||||||
"AnalyticsConfig":{
|
"AnalyticsConfig":{
|
||||||
"GoogleId": "none"
|
"GoogleId": "none"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"WalletConfig": {
|
"WalletConfig": {
|
||||||
"LbryAddress": "none"
|
"LbryPayAddress": "none",
|
||||||
|
"LbryClaimAddress": "none",
|
||||||
|
"LbryChangeAddress": "none"
|
||||||
},
|
},
|
||||||
"AnalyticsConfig":{
|
"AnalyticsConfig":{
|
||||||
"GoogleId": "UA-100747990-1"
|
"GoogleId": "UA-100747990-1"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"WalletConfig": {
|
"WalletConfig": {
|
||||||
"LbryAddress": "none"
|
"LbryPayAddress": "none",
|
||||||
|
"LbryClaimAddress": "none",
|
||||||
|
"LbryChangeAddress": "none"
|
||||||
},
|
},
|
||||||
"AnalyticsConfig":{
|
"AnalyticsConfig":{
|
||||||
"GoogleId": "UA-60403362-2"
|
"GoogleId": "UA-60403362-2"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"WalletConfig": {
|
"WalletConfig": {
|
||||||
"LbryAddress": "none"
|
"LbryPayAddress": "none",
|
||||||
|
"LbryClaimAddress": "none",
|
||||||
|
"LbryChangeAddress": "none"
|
||||||
},
|
},
|
||||||
"AnalyticsConfig":{
|
"AnalyticsConfig":{
|
||||||
"GoogleId": "UA-100747990-1"
|
"GoogleId": "UA-100747990-1"
|
||||||
|
|
|
@ -4,9 +4,15 @@ const logger = require('winston');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
postToAnalytics: (action, url, ipAddress, result) => {
|
postToAnalytics: (action, url, ipAddress, result) => {
|
||||||
logger.silly('creating record for analytics');
|
logger.silly('creating record for analytics');
|
||||||
|
// make sure the result is a string
|
||||||
if (result && (typeof result !== 'string')) {
|
if (result && (typeof result !== 'string')) {
|
||||||
result = result.toString();
|
result = result.toString();
|
||||||
}
|
}
|
||||||
|
// // make sure the ip address(es) are a string
|
||||||
|
if (ipAddress && (typeof ipAddress !== 'string')) {
|
||||||
|
ipAddress = ipAddress.toString();
|
||||||
|
}
|
||||||
|
// create record in the db
|
||||||
db.Analytics.create({
|
db.Analytics.create({
|
||||||
action,
|
action,
|
||||||
url,
|
url,
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const walletAddress = config.get('WalletConfig.LbryAddress');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createPublishParams: (name, filePath, license, nsfw) => {
|
createPublishParams: (name, filePath, license, nsfw) => {
|
||||||
logger.debug(`Creating Publish Parameters for "${name}"`);
|
logger.debug(`Creating Publish Parameters for "${name}"`);
|
||||||
// ensure nsfw is a boolean
|
// const payAddress = config.get('WalletConfig.LbryPayAddress');
|
||||||
|
const claimAddress = config.get('WalletConfig.LbryClaimAddress');
|
||||||
|
// const changeAddress = config.get('WalletConfig.LbryChangeAddress');
|
||||||
|
// filter nsfw and ensure it is a boolean
|
||||||
if (nsfw === false) {
|
if (nsfw === false) {
|
||||||
nsfw = false;
|
nsfw = false;
|
||||||
} else if (nsfw.toLowerCase === 'false') {
|
} else if (nsfw.toLowerCase === 'false') {
|
||||||
|
@ -32,8 +34,8 @@ module.exports = {
|
||||||
license,
|
license,
|
||||||
nsfw,
|
nsfw,
|
||||||
},
|
},
|
||||||
claim_address : walletAddress,
|
claim_address: claimAddress,
|
||||||
change_address: walletAddress,
|
// change_address: changeAddress,
|
||||||
};
|
};
|
||||||
logger.debug('publishParams:', publishParams);
|
logger.debug('publishParams:', publishParams);
|
||||||
return publishParams;
|
return publishParams;
|
||||||
|
|
|
@ -3,8 +3,9 @@ const { postToAnalytics } = require('../helpers/libraries/analytics');
|
||||||
|
|
||||||
module.exports = app => {
|
module.exports = app => {
|
||||||
// route for the home page
|
// route for the home page
|
||||||
app.get('/', ({ originalUrl, ip }, res) => {
|
app.get('/', ({ originalUrl, ip, headers }, res) => {
|
||||||
logger.debug(`GET request on ${originalUrl} from ${ip}`);
|
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
|
||||||
|
logger.debug(`headers ${JSON.stringify(headers)}`);
|
||||||
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
|
||||||
|
|
|
@ -34,31 +34,35 @@ function serveFile ({ fileName, fileType, filePath }, res) {
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to fetch one free public claim
|
// route to fetch one free public claim
|
||||||
app.get('/:name/:claim_id', ({ originalUrl, params, ip }, res) => {
|
app.get('/:name/:claim_id', ({ originalUrl, params, ip, ips, headers }, res) => {
|
||||||
logger.debug(`GET request on ${originalUrl} from ${ip}`);
|
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
|
||||||
|
logger.debug(`ips >> ${JSON.stringify(ips)}`);
|
||||||
|
logger.debug(`headers >> ${JSON.stringify(headers)}`);
|
||||||
// begin image-serve processes
|
// begin image-serve processes
|
||||||
serveController
|
serveController
|
||||||
.getClaimByClaimId(params.name, params.claim_id)
|
.getClaimByClaimId(params.name, params.claim_id)
|
||||||
.then(fileInfo => {
|
.then(fileInfo => {
|
||||||
postToAnalytics('serve', originalUrl, ip, 'success');
|
postToAnalytics('serve', originalUrl, ips, 'success');
|
||||||
serveFile(fileInfo, res);
|
serveFile(fileInfo, res);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError('serve', originalUrl, ip, error, res);
|
errorHandlers.handleRequestError('serve', originalUrl, ips, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to fetch one free public claim
|
// route to fetch one free public claim
|
||||||
app.get('/:name', ({ originalUrl, params, ip }, res) => {
|
app.get('/:name', ({ originalUrl, params, ip, ips, headers }, res) => {
|
||||||
logger.debug(`GET request on ${originalUrl} from ${ip}`);
|
logger.verbose(`GET request on ${originalUrl} from ${ip}`);
|
||||||
|
logger.debug(`ips >> ${JSON.stringify(ips)}`);
|
||||||
|
logger.debug(`headers >> ${JSON.stringify(headers)}`);
|
||||||
// begin image-serve processes
|
// begin image-serve processes
|
||||||
serveController
|
serveController
|
||||||
.getClaimByName(params.name)
|
.getClaimByName(params.name)
|
||||||
.then(fileInfo => {
|
.then(fileInfo => {
|
||||||
postToAnalytics('serve', originalUrl, ip, 'success');
|
postToAnalytics('serve', originalUrl, ips, 'success');
|
||||||
serveFile(fileInfo, res);
|
serveFile(fileInfo, res);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleRequestError('serve', originalUrl, ip, error, res);
|
errorHandlers.handleRequestError('serve', originalUrl, ips, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,15 +16,16 @@ require('./config/loggerSetup.js')(winston, logLevel, logDir);
|
||||||
|
|
||||||
// set port
|
// set port
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
// initialize express app
|
// create an Express application
|
||||||
const app = express();
|
const app = express();
|
||||||
// require our models for syncing
|
// require our models for syncing
|
||||||
const db = require('./models');
|
const db = require('./models');
|
||||||
|
|
||||||
// make express look in the public directory for assets (css/js/img)
|
// serve static files from public directory (css/js/img)
|
||||||
app.use(express.static(`${__dirname}/public`));
|
app.use(express.static(`${__dirname}/public`));
|
||||||
|
|
||||||
// configure express app
|
// configure express app
|
||||||
|
app.enable('trust proxy'); // trust the proxy to get ip address for us
|
||||||
app.use(bodyParser.json()); // for parsing application/json
|
app.use(bodyParser.json()); // for parsing application/json
|
||||||
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||||
app.use(siofu.router);
|
app.use(siofu.router);
|
||||||
|
@ -68,6 +69,7 @@ const http = require('./routes/sockets-routes.js')(app, siofu, hostedContentPath
|
||||||
// start server
|
// start server
|
||||||
db.sequelize.sync().then(() => {
|
db.sequelize.sync().then(() => {
|
||||||
http.listen(PORT, () => {
|
http.listen(PORT, () => {
|
||||||
|
winston.info('Trusting proxy?', app.get('trust proxy'));
|
||||||
winston.info(`Server is listening on PORT ${PORT}`);
|
winston.info(`Server is listening on PORT ${PORT}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue