switched api/streamFile to static /media

This commit is contained in:
bill bittner 2017-07-27 14:18:55 -07:00
parent 032066260b
commit 0de27c0b1b
6 changed files with 20 additions and 22 deletions

View file

@ -8,11 +8,6 @@ const errorHandlers = require('../helpers/libraries/errorHandlers.js');
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
module.exports = (app, hostedContentPath) => { module.exports = (app, hostedContentPath) => {
// route to return a file directly
app.get('/api/streamFile/:name', ({ params }, res) => {
const filePath = `${hostedContentPath}/${params.name}`;
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
app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => { app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => {
// google analytics // google analytics

View file

@ -16,15 +16,15 @@ const db = require('./models'); // require our models for syncing
const logLevel = config.get('Logging.LogLevel'); const logLevel = config.get('Logging.LogLevel');
require('./config/loggerSetup.js')(logger, logLevel); require('./config/loggerSetup.js')(logger, logLevel);
// serve static files from public directory (css/js/img) // trust the proxy to get ip address for us
app.use(express.static(`${__dirname}/public`)); app.enable('trust proxy');
// add middleware
// configure express app app.use(express.static(`${__dirname}/public`)); // 'express.static' to serve static files from public directory
app.enable('trust proxy'); // trust the proxy to get ip address for us app.use(express.static(`${__dirname}/public`)); // 'express.static' to serve static files from public directory
app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.json()); // 'body parser' for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: true })); // 'body parser' for parsing application/x-www-form-urlencoded
app.use(siofu.router); app.use(siofu.router); // 'socketio-file-upload' router for uploading with socket.io
app.use((req, res, next) => { // logging middleware app.use((req, res, next) => { // custom logging middleware to log all incomming http requests
logger.verbose(`Request on ${req.originalUrl} from ${req.ip}`); logger.verbose(`Request on ${req.originalUrl} from ${req.ip}`);
next(); next();
}); });
@ -84,7 +84,10 @@ db.sequelize
logger.info('Retrieving daemon download directory'); logger.info('Retrieving daemon download directory');
return getDownloadDirectory(); return getDownloadDirectory();
}) })
.then(hostedContentPath => { // require routes & wrap in socket.io .then(hostedContentPath => {
// add the hosted content folder at a static path
app.use('/media', express.static(hostedContentPath));
// require routes & wrap in socket.io
require('./routes/api-routes.js')(app, hostedContentPath); require('./routes/api-routes.js')(app, hostedContentPath);
require('./routes/show-routes.js')(app); require('./routes/show-routes.js')(app);
require('./routes/serve-routes.js')(app); require('./routes/serve-routes.js')(app);

View file

@ -13,7 +13,7 @@
<meta name="twitter:creator" content="@spee.ch"> <meta name="twitter:creator" content="@spee.ch">
<meta name="twitter:title" content="{{fileInfo.name}}"> <meta name="twitter:title" content="{{fileInfo.name}}">
<meta name="twitter:description" content="An image hosted via Spee.ch"> <meta name="twitter:description" content="An image hosted via Spee.ch">
<meta name="twitter:image" content="https://spee.ch/api/streamFile/{{fileInfo.fileName}}"> <meta name="twitter:image" content="https://spee.ch/media/{{fileInfo.fileName}}">
</head> </head>
<body> <body>
{{{ body }}} {{{ body }}}

View file

@ -2,12 +2,12 @@
<div id="asset-placeholder"> <div id="asset-placeholder">
{{#ifConditional fileInfo.fileType '===' 'video/mp4'}} {{#ifConditional fileInfo.fileType '===' 'video/mp4'}}
<video class="show-asset" autoplay loop controls> <video class="show-asset" autoplay loop controls>
<source src="/api/streamFile/{{fileInfo.fileName}}"> <source src="/media/{{fileInfo.fileName}}">
{{!--fallback--}} {{!--fallback--}}
Your browser does not support the <code>video</code> element. Your browser does not support the <code>video</code> element.
</video> </video>
{{else}} {{else}}
<img class="show-asset" src="/api/streamFile/{{fileInfo.fileName}}" /> <img class="show-asset" src="/media/{{fileInfo.fileName}}" />
{{/ifConditional}} {{/ifConditional}}
</div> </div>
</div> </div>

View file

@ -8,12 +8,12 @@
<a href="/{{this.name}}/{{this.claimId}}"> <a href="/{{this.name}}/{{this.claimId}}">
{{#ifConditional this.fileType '===' 'video/mp4'}} {{#ifConditional this.fileType '===' 'video/mp4'}}
<video class="grid-item trending-video" controls> <video class="grid-item trending-video" controls>
<source src="/api/streamFile/{{this.fileName}}"> <source src="/media/{{this.fileName}}">
{{!--fallback--}} {{!--fallback--}}
Your browser does not support the <code>video</code> element. Your browser does not support the <code>video</code> element.
</video> </video>
{{else}} {{else}}
<img class="grid-item trending-image" src="/api/streamFile/{{this.fileName}}" /> <img class="grid-item trending-image" src="/media/{{this.fileName}}" />
{{/ifConditional}} {{/ifConditional}}
</a> </a>
{{/unless}} {{/unless}}

View file

@ -2,13 +2,13 @@
<a href="/{{fileInfo.name}}/{{fileInfo.claimId}}"> <a href="/{{fileInfo.name}}/{{fileInfo.claimId}}">
{{#ifConditional fileInfo.fileType '===' 'video/mp4'}} {{#ifConditional fileInfo.fileType '===' 'video/mp4'}}
<video class="show-asset-lite" autoplay loop controls> <video class="show-asset-lite" autoplay loop controls>
<source src="/api/streamFile/{{fileInfo.fileName}}"> <source src="/media/{{fileInfo.fileName}}">
{{!--fallback--}} {{!--fallback--}}
Your browser does not support the <code>video</code> element. Your browser does not support the <code>video</code> element.
</video> </video>
{{else}} {{else}}
<img class="show-asset-lite" src="/api/streamFile/{{fileInfo.fileName}}" alt="{{fileInfo.fileName}}"/> <img class="show-asset-lite" src="/media/{{fileInfo.fileName}}" alt="{{fileInfo.fileName}}"/>
{{/ifConditional}} {{/ifConditional}}
</a> </a>
</div> </div>