facilitate admin temp files (#313)

This commit is contained in:
jessopb 2021-11-17 13:28:36 -05:00 committed by GitHub
parent e35069de1c
commit 4cf9309ee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -1,5 +1,6 @@
const { getHtml } = require('./html'); const { getHtml } = require('./html');
const { getRss } = require('./rss'); const { getRss } = require('./rss');
const { getTempFile } = require('./tempfile');
const { getHomepageJSON } = require('./getHomepageJSON'); const { getHomepageJSON } = require('./getHomepageJSON');
const { generateStreamUrl } = require('../../ui/util/web'); const { generateStreamUrl } = require('../../ui/util/web');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
@ -26,6 +27,11 @@ const rssMiddleware = async (ctx) => {
ctx.body = rss; ctx.body = rss;
}; };
const tempfileMiddleware = async (ctx) => {
const temp = await getTempFile(ctx);
ctx.body = temp;
};
router.get(`/$/api/content/v1/get`, async (ctx) => { router.get(`/$/api/content/v1/get`, async (ctx) => {
if (!CUSTOM_HOMEPAGE) { if (!CUSTOM_HOMEPAGE) {
ctx.status = 404; ctx.status = 404;
@ -64,6 +70,8 @@ router.get(`/$/stream/:claimName/:claimId`, async (ctx) => {
router.get(`/$/activate`, async (ctx) => { router.get(`/$/activate`, async (ctx) => {
ctx.redirect(`https://sso.odysee.com/auth/realms/Users/device`); ctx.redirect(`https://sso.odysee.com/auth/realms/Users/device`);
}); });
// to add a path for a temp file on the server, customize this path
router.get('/.well-known/:filename', tempfileMiddleware);
router.get(`/$/rss/:claimName/:claimId`, rssMiddleware); router.get(`/$/rss/:claimName/:claimId`, rssMiddleware);
router.get(`/$/rss/:claimName::claimId`, rssMiddleware); router.get(`/$/rss/:claimName::claimId`, rssMiddleware);

13
web/src/tempfile.js Normal file
View file

@ -0,0 +1,13 @@
const fs = require('fs');
const path = require('path');
let tempFile;
async function getTempFile(ctx) {
const filename = ctx.params.filename;
if (!tempFile) {
tempFile = fs.readFileSync(path.join(__dirname, `/../dist/${filename}`), 'utf8');
}
return tempFile;
}
module.exports = { getTempFile };