commit
5a342371b5
10 changed files with 57 additions and 45 deletions
|
@ -13,9 +13,9 @@ spee.ch is a single-serving site that reads and publishes images to and from the
|
||||||
* clone this repo
|
* clone this repo
|
||||||
* customize `config/develpment.json` by replacing the value of `Database.DownloadDirectory` with a string representing the local path where you want uploaded files to be stored.
|
* customize `config/develpment.json` by replacing the value of `Database.DownloadDirectory` with a string representing the local path where you want uploaded files to be stored.
|
||||||
* run `npm install`
|
* run `npm install`
|
||||||
* to start the server, from your command line run `node server.js` while passing three environmental variables: your lbry wallet address (`LBRY_CLAIM_ADDRESS`), your mysql connection uri (`MYSQL_CONNECTION_STRING`), and the environment to run (`NODE_ENV`).
|
* to start the server, from your command line run `node speech.js` while passing three environmental variables: your lbry wallet address (`LBRY_CLAIM_ADDRESS`), your mysql connection uri (`MYSQL_CONNECTION_STRING`), and the environment to run (`NODE_ENV`).
|
||||||
* i.e. `LBRY_CLAIM_ADDRESS=<your wallet address here> MYSQL_CONNECTION_STRING=<your connection uri here> NODE_ENV=development node server.js`
|
* i.e. `LBRY_CLAIM_ADDRESS=<your wallet address here> MYSQL_CONNECTION_STRING=<your connection uri here> NODE_ENV=development node speech.js`
|
||||||
* e.g. `LBRY_CLAIM_ADDRESS=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX MYSQL_CONNECTION_STRING=mysql://root:XXXXXX@localhost:3306/lbry NODE_ENV=development node server.js`
|
* e.g. `LBRY_CLAIM_ADDRESS=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX MYSQL_CONNECTION_STRING=mysql://root:XXXXXX@localhost:3306/lbry NODE_ENV=development node speech.js`
|
||||||
* To run hot, use `nodemon` instead of `node`
|
* To run hot, use `nodemon` instead of `node`
|
||||||
* visit [localhost:3000](http://localhost:3000)
|
* visit [localhost:3000](http://localhost:3000)
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
"GoogleId": "none"
|
"GoogleId": "none"
|
||||||
},
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"MySqlConnectionUri": "none",
|
"MySqlConnectionUri": "none"
|
||||||
"DownloadDirectory": "none"
|
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "none"
|
"LogLevel": "none"
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
"GoogleId": "UA-100747990-1"
|
"GoogleId": "UA-100747990-1"
|
||||||
},
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"MySqlConnectionUri": "none",
|
"MySqlConnectionUri": "none"
|
||||||
"DownloadDirectory": "/home/ubuntu/Downloads/"
|
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "silly"
|
"LogLevel": "silly"
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
"GoogleId": "UA-60403362-3"
|
"GoogleId": "UA-60403362-3"
|
||||||
},
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"MySqlConnectionUri": "none",
|
"MySqlConnectionUri": "none"
|
||||||
"DownloadDirectory": "/home/lbry/Downloads/"
|
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "verbose"
|
"LogLevel": "verbose"
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
"GoogleId": "UA-100747990-1"
|
"GoogleId": "UA-100747990-1"
|
||||||
},
|
},
|
||||||
"Database": {
|
"Database": {
|
||||||
"MySqlConnectionUri": "none",
|
"MySqlConnectionUri": "none"
|
||||||
"DownloadDirectory": "/home/ubuntu/Downloads/"
|
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": "debug"
|
"LogLevel": "debug"
|
||||||
|
|
|
@ -192,8 +192,10 @@ module.exports = {
|
||||||
getClaimByClaimId (name, claimId) {
|
getClaimByClaimId (name, claimId) {
|
||||||
const deferred = new Promise((resolve, reject) => {
|
const deferred = new Promise((resolve, reject) => {
|
||||||
let uri;
|
let uri;
|
||||||
validateClaimId(name, claimId) // 1. validate the claim id & retrieve the full claim id if needed
|
// 1. validate the claim id & retrieve the full claim id if needed
|
||||||
.then(validClaimId => { // 2. check locally for the claim
|
validateClaimId(name, claimId)
|
||||||
|
.then(validClaimId => {
|
||||||
|
// 2. check locally for the claim
|
||||||
logger.debug('valid claim id:', validClaimId);
|
logger.debug('valid claim id:', validClaimId);
|
||||||
uri = `${name}#${validClaimId}`;
|
uri = `${name}#${validClaimId}`;
|
||||||
return db.File.findOne({ where: { name, claimId: validClaimId } });
|
return db.File.findOne({ where: { name, claimId: validClaimId } });
|
||||||
|
@ -206,7 +208,7 @@ module.exports = {
|
||||||
resolve(result.dataValues);
|
resolve(result.dataValues);
|
||||||
// update the file, as needed
|
// update the file, as needed
|
||||||
updateFileIfNeeded(uri, name, claimId, result.dataValues.outpoint, result.dataValues.outpoint);
|
updateFileIfNeeded(uri, name, claimId, result.dataValues.outpoint, result.dataValues.outpoint);
|
||||||
// 3. if a match was not found use the daemon to retrieve the claim & return the db data once it is created
|
// 3. if a match was not found locally, use the daemon to retrieve the claim & return the db data once it is created
|
||||||
} else {
|
} else {
|
||||||
logger.debug('No result found in File table');
|
logger.debug('No result found in File table');
|
||||||
lbryApi
|
lbryApi
|
||||||
|
|
|
@ -103,4 +103,24 @@ module.exports = {
|
||||||
});
|
});
|
||||||
return deferred;
|
return deferred;
|
||||||
},
|
},
|
||||||
|
getDownloadDirectory () {
|
||||||
|
logger.debug('Retrieving the download directory path from lbry daemon...');
|
||||||
|
const deferred = new Promise((resolve, reject) => {
|
||||||
|
axios
|
||||||
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
method: 'settings_get',
|
||||||
|
})
|
||||||
|
.then(({ data }) => {
|
||||||
|
if (data.result) {
|
||||||
|
resolve(data.result.download_directory);
|
||||||
|
} else {
|
||||||
|
reject(new Error('Successfully connected to lbry daemon, but unable to retrieve the download directory.'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return deferred;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
"name": "spee.ch",
|
"name": "spee.ch",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "a single-serving site that reads and publishes images to and from the LBRY blockchain",
|
"description": "a single-serving site that reads and publishes images to and from the LBRY blockchain",
|
||||||
"main": "server.js",
|
"main": "speech.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node server.js",
|
"start": "node speech.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"fix": "eslint . --fix",
|
"fix": "eslint . --fix",
|
||||||
"precommit": "eslint ."
|
"precommit": "eslint ."
|
||||||
|
|
|
@ -7,13 +7,10 @@ const { createPublishParams, validateFile } = require('../helpers/libraries/publ
|
||||||
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
||||||
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||||
|
|
||||||
const config = require('config');
|
module.exports = (app, hostedContentPath) => {
|
||||||
const hostedContentPath = config.get('Database.DownloadDirectory');
|
|
||||||
|
|
||||||
module.exports = app => {
|
|
||||||
// route to return a file directly
|
// route to return a file directly
|
||||||
app.get('/api/streamFile/:name', ({ params }, res) => {
|
app.get('/api/streamFile/:name', ({ params }, res) => {
|
||||||
const filePath = `${hostedContentPath}${params.name}`;
|
const filePath = `${hostedContentPath}/${params.name}`;
|
||||||
res.status(200).sendFile(filePath);
|
res.status(200).sendFile(filePath);
|
||||||
});
|
});
|
||||||
// route to run a claim_list request on the daemon
|
// route to run a claim_list request on the daemon
|
||||||
|
|
|
@ -6,20 +6,16 @@ const expressHandlebars = require('express-handlebars');
|
||||||
const Handlebars = require('handlebars');
|
const Handlebars = require('handlebars');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
|
const { getDownloadDirectory } = require('./helpers/libraries/lbryApi');
|
||||||
|
|
||||||
const hostedContentPath = config.get('Database.DownloadDirectory');
|
const PORT = 3000; // set port
|
||||||
|
const app = express(); // create an Express application
|
||||||
|
const db = require('./models'); // require our models for syncing
|
||||||
|
|
||||||
// configure logging
|
// configure logging
|
||||||
const logLevel = config.get('Logging.LogLevel');
|
const logLevel = config.get('Logging.LogLevel');
|
||||||
require('./config/loggerSetup.js')(logger, logLevel);
|
require('./config/loggerSetup.js')(logger, logLevel);
|
||||||
|
|
||||||
// set port
|
|
||||||
const PORT = 3000;
|
|
||||||
// create an Express application
|
|
||||||
const app = express();
|
|
||||||
// require our models for syncing
|
|
||||||
const db = require('./models');
|
|
||||||
|
|
||||||
// serve static files from public directory (css/js/img)
|
// serve static files from public directory (css/js/img)
|
||||||
app.use(express.static(`${__dirname}/public`));
|
app.use(express.static(`${__dirname}/public`));
|
||||||
|
|
||||||
|
@ -33,7 +29,7 @@ app.use((req, res, next) => { // logging middleware
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// configure handlebars & register it with Express app
|
// configure handlebars & register it with express app
|
||||||
const hbs = expressHandlebars.create({
|
const hbs = expressHandlebars.create({
|
||||||
defaultLayout: 'main', // sets the default layout
|
defaultLayout: 'main', // sets the default layout
|
||||||
handlebars : Handlebars, // includes basic handlebars for access to that library
|
handlebars : Handlebars, // includes basic handlebars for access to that library
|
||||||
|
@ -82,25 +78,26 @@ const hbs = expressHandlebars.create({
|
||||||
app.engine('handlebars', hbs.engine);
|
app.engine('handlebars', hbs.engine);
|
||||||
app.set('view engine', 'handlebars');
|
app.set('view engine', 'handlebars');
|
||||||
|
|
||||||
// require express routes
|
// start the server
|
||||||
require('./routes/api-routes.js')(app);
|
db.sequelize
|
||||||
require('./routes/show-routes.js')(app);
|
.sync() // sync sequelize
|
||||||
require('./routes/serve-routes.js')(app);
|
.then(() => { // get the download directory from the daemon
|
||||||
require('./routes/home-routes.js')(app);
|
logger.info('Retrieving daemon download directory');
|
||||||
|
return getDownloadDirectory();
|
||||||
// require socket.io routes
|
})
|
||||||
const server = require('./routes/sockets-routes.js')(app, siofu, hostedContentPath);
|
.then(hostedContentPath => { // require routes & wrap in socket.io
|
||||||
|
require('./routes/api-routes.js')(app, hostedContentPath);
|
||||||
// sync sequelize
|
require('./routes/show-routes.js')(app);
|
||||||
// wrap the server in socket.io to intercept incoming sockets requests
|
require('./routes/serve-routes.js')(app);
|
||||||
// start server
|
require('./routes/home-routes.js')(app);
|
||||||
db.sequelize.sync()
|
return require('./routes/sockets-routes.js')(app, siofu, hostedContentPath);
|
||||||
.then(() => {
|
})
|
||||||
|
.then(server => { // start the server
|
||||||
server.listen(PORT, () => {
|
server.listen(PORT, () => {
|
||||||
logger.info('Trusting proxy?', app.get('trust proxy'));
|
logger.info('Trusting proxy?', app.get('trust proxy'));
|
||||||
logger.info(`Server is listening on PORT ${PORT}`);
|
logger.info(`Server is listening on PORT ${PORT}`);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.log('Error syncing sequelize db:', error);
|
logger.error('Startup Error >>', error);
|
||||||
});
|
});
|
Loading…
Reference in a new issue