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
|
||||
* 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`
|
||||
* 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`).
|
||||
* i.e. `LBRY_CLAIM_ADDRESS=<your wallet address here> MYSQL_CONNECTION_STRING=<your connection uri here> 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 server.js`
|
||||
* 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 speech.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`
|
||||
* visit [localhost:3000](http://localhost:3000)
|
||||
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
"GoogleId": "none"
|
||||
},
|
||||
"Database": {
|
||||
"MySqlConnectionUri": "none",
|
||||
"DownloadDirectory": "none"
|
||||
"MySqlConnectionUri": "none"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": "none"
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
"GoogleId": "UA-100747990-1"
|
||||
},
|
||||
"Database": {
|
||||
"MySqlConnectionUri": "none",
|
||||
"DownloadDirectory": "/home/ubuntu/Downloads/"
|
||||
"MySqlConnectionUri": "none"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": "silly"
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
"GoogleId": "UA-60403362-3"
|
||||
},
|
||||
"Database": {
|
||||
"MySqlConnectionUri": "none",
|
||||
"DownloadDirectory": "/home/lbry/Downloads/"
|
||||
"MySqlConnectionUri": "none"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": "verbose"
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
"GoogleId": "UA-100747990-1"
|
||||
},
|
||||
"Database": {
|
||||
"MySqlConnectionUri": "none",
|
||||
"DownloadDirectory": "/home/ubuntu/Downloads/"
|
||||
"MySqlConnectionUri": "none"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": "debug"
|
||||
|
|
|
@ -192,8 +192,10 @@ module.exports = {
|
|||
getClaimByClaimId (name, claimId) {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
let uri;
|
||||
validateClaimId(name, claimId) // 1. validate the claim id & retrieve the full claim id if needed
|
||||
.then(validClaimId => { // 2. check locally for the claim
|
||||
// 1. validate the claim id & retrieve the full claim id if needed
|
||||
validateClaimId(name, claimId)
|
||||
.then(validClaimId => {
|
||||
// 2. check locally for the claim
|
||||
logger.debug('valid claim id:', validClaimId);
|
||||
uri = `${name}#${validClaimId}`;
|
||||
return db.File.findOne({ where: { name, claimId: validClaimId } });
|
||||
|
@ -206,7 +208,7 @@ module.exports = {
|
|||
resolve(result.dataValues);
|
||||
// update the file, as needed
|
||||
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 {
|
||||
logger.debug('No result found in File table');
|
||||
lbryApi
|
||||
|
|
|
@ -103,4 +103,24 @@ module.exports = {
|
|||
});
|
||||
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",
|
||||
"version": "0.0.1",
|
||||
"description": "a single-serving site that reads and publishes images to and from the LBRY blockchain",
|
||||
"main": "server.js",
|
||||
"main": "speech.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js",
|
||||
"start": "node speech.js",
|
||||
"lint": "eslint .",
|
||||
"fix": "eslint . --fix",
|
||||
"precommit": "eslint ."
|
||||
|
|
|
@ -7,13 +7,10 @@ const { createPublishParams, validateFile } = require('../helpers/libraries/publ
|
|||
const errorHandlers = require('../helpers/libraries/errorHandlers.js');
|
||||
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||
|
||||
const config = require('config');
|
||||
const hostedContentPath = config.get('Database.DownloadDirectory');
|
||||
|
||||
module.exports = app => {
|
||||
module.exports = (app, hostedContentPath) => {
|
||||
// route to return a file directly
|
||||
app.get('/api/streamFile/:name', ({ params }, res) => {
|
||||
const filePath = `${hostedContentPath}${params.name}`;
|
||||
const filePath = `${hostedContentPath}/${params.name}`;
|
||||
res.status(200).sendFile(filePath);
|
||||
});
|
||||
// route to run a claim_list request on the daemon
|
||||
|
|
|
@ -6,20 +6,16 @@ const expressHandlebars = require('express-handlebars');
|
|||
const Handlebars = require('handlebars');
|
||||
const config = require('config');
|
||||
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
|
||||
const logLevel = config.get('Logging.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)
|
||||
app.use(express.static(`${__dirname}/public`));
|
||||
|
||||
|
@ -33,7 +29,7 @@ app.use((req, res, next) => { // logging middleware
|
|||
next();
|
||||
});
|
||||
|
||||
// configure handlebars & register it with Express app
|
||||
// configure handlebars & register it with express app
|
||||
const hbs = expressHandlebars.create({
|
||||
defaultLayout: 'main', // sets the default layout
|
||||
handlebars : Handlebars, // includes basic handlebars for access to that library
|
||||
|
@ -82,25 +78,26 @@ const hbs = expressHandlebars.create({
|
|||
app.engine('handlebars', hbs.engine);
|
||||
app.set('view engine', 'handlebars');
|
||||
|
||||
// require express routes
|
||||
require('./routes/api-routes.js')(app);
|
||||
require('./routes/show-routes.js')(app);
|
||||
require('./routes/serve-routes.js')(app);
|
||||
require('./routes/home-routes.js')(app);
|
||||
|
||||
// require socket.io routes
|
||||
const server = require('./routes/sockets-routes.js')(app, siofu, hostedContentPath);
|
||||
|
||||
// sync sequelize
|
||||
// wrap the server in socket.io to intercept incoming sockets requests
|
||||
// start server
|
||||
db.sequelize.sync()
|
||||
.then(() => {
|
||||
// start the server
|
||||
db.sequelize
|
||||
.sync() // sync sequelize
|
||||
.then(() => { // get the download directory from the daemon
|
||||
logger.info('Retrieving daemon download directory');
|
||||
return getDownloadDirectory();
|
||||
})
|
||||
.then(hostedContentPath => { // require routes & wrap in socket.io
|
||||
require('./routes/api-routes.js')(app, hostedContentPath);
|
||||
require('./routes/show-routes.js')(app);
|
||||
require('./routes/serve-routes.js')(app);
|
||||
require('./routes/home-routes.js')(app);
|
||||
return require('./routes/sockets-routes.js')(app, siofu, hostedContentPath);
|
||||
})
|
||||
.then(server => { // start the server
|
||||
server.listen(PORT, () => {
|
||||
logger.info('Trusting proxy?', app.get('trust proxy'));
|
||||
logger.info(`Server is listening on PORT ${PORT}`);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.log('Error syncing sequelize db:', error);
|
||||
logger.error('Startup Error >>', error);
|
||||
});
|
Loading…
Reference in a new issue