From 4cf9309ee180f33efc2f2d47a36e95fd74aba816 Mon Sep 17 00:00:00 2001 From: jessopb <36554050+jessopb@users.noreply.github.com> Date: Wed, 17 Nov 2021 13:28:36 -0500 Subject: [PATCH] facilitate admin temp files (#313) --- web/src/routes.js | 8 ++++++++ web/src/tempfile.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 web/src/tempfile.js diff --git a/web/src/routes.js b/web/src/routes.js index 38f1ceb38..fe88fe5b0 100644 --- a/web/src/routes.js +++ b/web/src/routes.js @@ -1,5 +1,6 @@ const { getHtml } = require('./html'); const { getRss } = require('./rss'); +const { getTempFile } = require('./tempfile'); const { getHomepageJSON } = require('./getHomepageJSON'); const { generateStreamUrl } = require('../../ui/util/web'); const fetch = require('node-fetch'); @@ -26,6 +27,11 @@ const rssMiddleware = async (ctx) => { ctx.body = rss; }; +const tempfileMiddleware = async (ctx) => { + const temp = await getTempFile(ctx); + ctx.body = temp; +}; + router.get(`/$/api/content/v1/get`, async (ctx) => { if (!CUSTOM_HOMEPAGE) { ctx.status = 404; @@ -64,6 +70,8 @@ router.get(`/$/stream/:claimName/:claimId`, async (ctx) => { router.get(`/$/activate`, async (ctx) => { 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); diff --git a/web/src/tempfile.js b/web/src/tempfile.js new file mode 100644 index 000000000..4d3bae64c --- /dev/null +++ b/web/src/tempfile.js @@ -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 };