diff --git a/package-lock.json b/package-lock.json index 5140802..d437f65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "minio": "^8.0.0", "mongodb": "6.8", "podcast": "^2.0.1", + "slugify": "^1.6.6", "translitit-cyrillic-ukrainian-to-latin": "^0.1.0" }, "devDependencies": { @@ -4292,6 +4293,15 @@ "node": ">=10" } }, + "node_modules/slugify": { + "version": "1.6.6", + "resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.6.tgz", + "integrity": "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", diff --git a/package.json b/package.json index 3474248..5f15b32 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "minio": "^8.0.0", "mongodb": "6.8", "podcast": "^2.0.1", + "slugify": "^1.6.6", "translitit-cyrillic-ukrainian-to-latin": "^0.1.0" }, "devDependencies": { diff --git a/src/core/episodeRepo.js b/src/core/episodeRepo.js index 93f4633..915e809 100644 --- a/src/core/episodeRepo.js +++ b/src/core/episodeRepo.js @@ -72,7 +72,7 @@ export function updateTimeCodeBySlug(showSlug, episodeSlug, index, time, descrip ); } -export function updateLinkBySlug(showSlug, episodeSlug, index, link, title) { +export function updateLinkBySlug(showSlug, episodeSlug, index, link, text) { return Database.collection('posts').updateOne( { showSlug: showSlug, @@ -81,7 +81,7 @@ export function updateLinkBySlug(showSlug, episodeSlug, index, link, title) { { $set: { [`links.${index}.link`]: link, - [`links.${index}.title`]: title + [`links.${index}.text`]: text, } } ); @@ -107,3 +107,17 @@ export function unpublishPodcast(showSlug, episodeSlug) { return Database.collection('posts').updateOne({ showSlug: showSlug, slug: episodeSlug }, { $set: { visibility: 'private' } }); } +export function createPodcast(showSlug, name, slug, links) { + return Database.collection('posts').insertOne({ + showSlug: showSlug, + title: name, + slug: slug, + links: links, + charters: [], + visibility: 'private', + publish_date: new Date(), + type: 'public', + }); +} + + diff --git a/src/core/generator.js b/src/core/generator.js index 817af6f..e92c25e 100644 --- a/src/core/generator.js +++ b/src/core/generator.js @@ -145,7 +145,7 @@ function buildRssDescription(post) { description += '

Згадано в випуску

'; description += '' diff --git a/src/core/podcastRepo.js b/src/core/podcastRepo.js index 709ec1f..99b0fdc 100644 --- a/src/core/podcastRepo.js +++ b/src/core/podcastRepo.js @@ -7,3 +7,4 @@ export async function getShowInfo(podcastDomain) { export async function getShowBySlug(showSlug) { return Database.collection('shows').findOne({ slug: showSlug }); } + diff --git a/src/core/showRepo.js b/src/core/showRepo.js index 4afdda0..59fa077 100644 --- a/src/core/showRepo.js +++ b/src/core/showRepo.js @@ -5,7 +5,7 @@ export async function getAllShows() { } export async function getShowBySlug(slug) { - return Database.collection('shows').findOne({ slug }); + return Database.collection('shows').findOne({ slug: slug }); } export async function getShowInfo(podcastDomain) { diff --git a/src/minio/utils.js b/src/minio/utils.js index 289784f..c706249 100644 --- a/src/minio/utils.js +++ b/src/minio/utils.js @@ -2,6 +2,7 @@ import { S3Client, GetObjectCommand, PutObjectCommand, HeadObjectCommand } from import dotenv from 'dotenv'; import Fs from 'fs' +import url from 'url'; dotenv.config(); @@ -20,7 +21,10 @@ const client = new S3Client({ }); export function buildObjectURL(path) { - return `${startUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}`; + if (!path) { + return undefined; + } + return url.resolve(startUrl, path); } export async function getFileSizeInByte(key) { diff --git a/src/routers/admin/dashboard.js b/src/routers/admin/dashboard.js index 17083d8..358616a 100644 --- a/src/routers/admin/dashboard.js +++ b/src/routers/admin/dashboard.js @@ -1,5 +1,6 @@ -import { getAllPosts } from "../../core/episodeRepo.js"; +import { getAllPosts, createPodcast } from "../../core/episodeRepo.js"; import { getAllShows, getShowBySlug } from "../../core/showRepo.js"; +import slugify from 'slugify'; import dotenv from 'dotenv'; dotenv.config(); @@ -26,9 +27,7 @@ async function dashboardView(request, h) { ) } -async function adminPodcastList(request, h) { - const showSlug = request.params.showSlug; - +async function adminPodcastListBySlug(showSlug, h, layout) { const show = await getShowBySlug(showSlug); const posts = await getAllPosts(showSlug); @@ -46,14 +45,32 @@ async function adminPodcastList(request, h) { posts: uiPosts, createPodcastButton: { title: 'Create Podcast', + showSlug: showSlug, } }, { - layout: 'admin' + layout: layout } ) } +async function createPodcastHandler(request, h) { + const { episodeName } = request.payload; + const showSlug = request.params.showSlug; + const show = await getShowBySlug(showSlug); + + const slug = slugify(episodeName); + + await createPodcast(show.slug, episodeName, slug, show.links); + + return adminPodcastListBySlug(showSlug, h, false); +} + +async function adminPodcastList(request, h) { + const showSlug = request.params.showSlug; + return adminPodcastListBySlug(showSlug, h, "admin"); +} + export function adminDashboard(server) { server.route({ method: 'GET', @@ -72,5 +89,13 @@ export function adminDashboard(server) { auth: 'adminSession', } }) + server.route({ + method: 'POST', + path: '/admin/show/{showSlug}/episode', + handler: createPodcastHandler, + options: { + auth: 'adminSession', + } + }) } diff --git a/src/routers/admin/detail/getDetails.js b/src/routers/admin/detail/getDetails.js index 8b22748..66c361e 100644 --- a/src/routers/admin/detail/getDetails.js +++ b/src/routers/admin/detail/getDetails.js @@ -38,7 +38,7 @@ async function getPodcastDetails(request, h) { episodeSlug: podcast.slug, index: index, link: link.link, - text: link.title, + text: link.text, } }), isAudioBuildInProgress: podcast.montage_status === 'in_progress', diff --git a/src/routers/admin/preview.js b/src/routers/admin/preview.js index 9f1fb8a..1402139 100644 --- a/src/routers/admin/preview.js +++ b/src/routers/admin/preview.js @@ -34,7 +34,7 @@ async function podcastDetailsHandler(request, h) { .map(link => { return { link: link.link, - title: link.title, + text: link.text, } }), }, diff --git a/src/routers/details.js b/src/routers/details.js index 1df5228..f21521d 100644 --- a/src/routers/details.js +++ b/src/routers/details.js @@ -37,7 +37,7 @@ async function podcastDetailsHandler(request, h) { .map(link => { return { link: link.link, - title: link.title, + text: link.text, } }), }, diff --git a/src/templates/layouts/admin.html b/src/templates/layouts/admin.html index c328771..0131ed8 100644 --- a/src/templates/layouts/admin.html +++ b/src/templates/layouts/admin.html @@ -8,18 +8,18 @@ - - {{> admin_head}} + +
+ {{> admin_head}} -
- {{{ content }}} -
- -
+
+ {{{ content }}} +
- + +
diff --git a/src/templates/pages/admin/admin_podcast_list.html b/src/templates/pages/admin/admin_podcast_list.html index d75ee23..1765e04 100644 --- a/src/templates/pages/admin/admin_podcast_list.html +++ b/src/templates/pages/admin/admin_podcast_list.html @@ -1,9 +1,11 @@ -{{> btn_create_podcast createPodcastButton}} +
+ {{> btn_create_podcast createPodcastButton}} -
- {{#each posts}} - -

{{title}}

-
- {{/each}} +
+ {{#each posts}} + +

{{title}}

+
+ {{/each}} +
diff --git a/src/templates/pages/podcastDetails.html b/src/templates/pages/podcastDetails.html index 79ccb8c..6932577 100644 --- a/src/templates/pages/podcastDetails.html +++ b/src/templates/pages/podcastDetails.html @@ -1,57 +1,57 @@
-
- -
-

{{ title }}

-
    - {{#each chapters}} -
  • - -

    {{title}}

    -
  • - {{/each}} -
-
+
+ +
+

{{ title }}

+
    + {{#each chapters}} +
  • + +

    {{title}}

    +
  • + {{/each}} +
+
+
-
-
- -
+
+
+ +
-
-

Корисні посилання з цього випуску

- -
+
+

Корисні посилання з цього випуску

+
+
- + }); +
diff --git a/src/templates/widgets/btn_create_podcast.html b/src/templates/widgets/btn_create_podcast.html index 9c6e88d..365bd6c 100644 --- a/src/templates/widgets/btn_create_podcast.html +++ b/src/templates/widgets/btn_create_podcast.html @@ -1,4 +1,8 @@ - +
+ + +