From ed54a8c5c86307bf5824cbc1eed4118441604859 Mon Sep 17 00:00:00 2001 From: vovastelmashchuk Date: Sat, 4 Jan 2025 22:48:50 +0200 Subject: [PATCH] change rss saves to db --- .gitignore | 1 + README.md | 15 +++++++++++++++ src/core/generator.js | 19 ++++++++++--------- src/routers/rss/rss.js | 8 +------- 4 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 1180b77..2767b07 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ node_modules .tmp .DS_Store .tmp +compose.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..5dcdd39 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# YourPod + +The platform for build podcast from yourtube playlist. + +## Development + +```bash +npm run dev +``` + +## Deploy + +```bash +docker stack deploy -c docker-compose.yml stack-your-pod +``` diff --git a/src/core/generator.js b/src/core/generator.js index 35141ac..1e32fac 100644 --- a/src/core/generator.js +++ b/src/core/generator.js @@ -1,25 +1,23 @@ import { Podcast } from "podcast"; -import { - buildObjectURL, - getFileSizeInByte, - uploadFile, -} from "../minio/utils.js"; +import { buildObjectURL, getFileSizeInByte } from "../minio/utils.js"; import { getShowBySlug } from "../core/podcastRepo.js"; +import { Database } from "./client.js"; + import dotenv from "dotenv"; dotenv.config(); const startUrl = process.env.S3_START_URL; -const host = process.env.BASE_URL; -const rssFileName = process.env.PODCAST_RSS_FILE_NAME; const currentYear = new Date().getFullYear(); export async function updateRss(showSlug) { const showInfo = await getShowBySlug(showSlug); + const host = `https://${showInfo.mainDomain}`; + const logoUrl = `${startUrl}${showInfo.showLogoUrl}`; const description = showInfo.about; @@ -30,7 +28,7 @@ export async function updateRss(showSlug) { const feed = new Podcast({ title: showInfo.showName, description: description, - feedUrl: `${startUrl}/v2/${showSlug}/${rssFileName}`, + feedUrl: `${startUrl}/v2/${showSlug}/rss.xml`, siteUrl: host, webMaster: host, generator: "YourPod", @@ -109,5 +107,8 @@ export async function updateRss(showSlug) { const xml = feed.buildXml(); - await uploadFile(`v2/${showSlug}/${rssFileName}`, xml, "application/rss+xml"); + await Database.collection("shows").updateOne( + { slug: showSlug }, + { $set: { rss: xml } } + ); } diff --git a/src/routers/rss/rss.js b/src/routers/rss/rss.js index 424e1f7..7978412 100644 --- a/src/routers/rss/rss.js +++ b/src/routers/rss/rss.js @@ -1,16 +1,10 @@ import { getShowInfo } from "../../core/podcastRepo.js"; -import { getFileContent } from "../../minio/utils.js"; -import dotenv from "dotenv"; - -dotenv.config(); - -const rssFileName = process.env.PODCAST_RSS_FILE_NAME; async function rssHandler(request, h) { const host = request.headers.host; const showInfo = await getShowInfo(host); - const rss = await getFileContent(`v2/${showInfo.slug}/${rssFileName}`); + const rss = showInfo.rss; return h.response(rss).type("application/rss+xml"); }