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