Configuration

This commit is contained in:
2024-07-07 11:33:59 +04:00
parent de7f3ec141
commit 37ddc4b4ab
8 changed files with 99 additions and 65 deletions

6
.env Normal file
View File

@@ -0,0 +1,6 @@
NEXT_PUBLIC_API_PATTERN=/api
NEXT_PUBLIC_CONTENT_URL=/content/torrent
NEXT_PUBLIC_FRAGMENT_URL=/content/audio
NEXT_PUBLIC_COVER_FULL_URL=/content/images/cover/full_size
NEXT_PUBLIC_COVER_PREVIEW_URL=/content/images/cover/preview

View File

@@ -1,5 +1,9 @@
NEXT_PUBLIC_BASE_URL=http://127.0.0.1:3000/api BACKEND_PROTOCOL=http
NEXT_PUBLIC_CONTENT_URL=http://127.0.0.1:8000/content/torrent BACKEND_DOMAIN=127.0.0.1
NEXT_PUBLIC_FRAGMENT_URL=http://127.0.0.1:8000/content/audio BACKEND_PORT=8000
NEXT_PUBLIC_COVER_FULL_URL=http://127.0.0.1:8000/content/images/cover/full_size
NEXT_PUBLIC_COVER_PREVIEW_URL=http://127.0.0.1:8000/content/images/cover/preview BASE_PROTOCOL=http
BASE_DOMAIN=127.0.0.1
BASE_PORT=3000
NEXT_PUBLIC_BASE_URL=http://127.0.0.1:3000

View File

@@ -1,21 +1,20 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
async rewrites() { async rewrites() {
return process.env.NODE_ENV == "development" return [
? [
{ {
source: "/api/:path*", source: "/api/:path*",
destination: "http://127.0.0.1:8000/:path*", destination: `${process.env.BACKEND_PROTOCOL}://`+
}, `${process.env.BACKEND_DOMAIN}:${process.env.BACKEND_PORT}/:path*`,
}
] ]
: [];
}, },
images: { images: {
remotePatterns: [ remotePatterns: [
{ {
protocol: "http", protocol: process.env.BASE_PROTOCOL,
hostname: "127.0.0.1", hostname: process.env.BASE_DOMAIN,
port: "8000", port: process.env.BASE_PORT,
}, },
], ],
}, },

View File

@@ -11,20 +11,27 @@ export const metadata: Metadata = {
}; };
export default async function Home() { export default async function Home() {
const cards: { [k in SectionType]?: ItemCardType[] | null } = {}; const requests = SectionService.sections.map((section) =>
await Promise.all( ItemService.itemsConfiguration[
SectionService.sections.map(async (section) => {
cards[section] = await ItemService.itemsConfiguration[
SectionService.sectionsConfiguration[section].itemType SectionService.sectionsConfiguration[section].itemType
].service.GetCards(); ].service.GetCards()
}) );
const data = await Promise.all(requests);
const cards = await SectionService.sections.reduce(
(cards, section, i) => ({
...cards,
[section]: data[i],
}),
{} as { [k in SectionType]: ItemCardType[] | null }
); );
return ( return (
<> <>
{SectionService.sections.map((section) => ( {cards &&
SectionService.sections.map((section, i) => (
<section key={section}> <section key={section}>
{cards[section] && cards[section].length > 0 && ( {cards[section] && (
<Section <Section
name={ name={
SectionService.sectionsConfiguration[section] SectionService.sectionsConfiguration[section]
@@ -34,10 +41,11 @@ export default async function Home() {
SectionService.isSection(section) ? `/${section}` : undefined SectionService.isSection(section) ? `/${section}` : undefined
} }
invite_text={ invite_text={
SectionService.sectionsConfiguration[section].sectionInviteText SectionService.sectionsConfiguration[section]
.sectionInviteText
} }
> >
{cards[section].map((card) => ( {cards[section]?.map((card) => (
<ItemCard key={card.id} card={card} /> <ItemCard key={card.id} card={card} />
))} ))}
</Section> </Section>

View File

@@ -21,6 +21,9 @@ export const Img = ({
<Image <Image
className={className} className={className}
src={ src={
"" +
process.env.NEXT_PUBLIC_BASE_URL +
process.env.NEXT_PUBLIC_API_PATTERN +
(preview (preview
? process.env.NEXT_PUBLIC_COVER_PREVIEW_URL ? process.env.NEXT_PUBLIC_COVER_PREVIEW_URL
: process.env.NEXT_PUBLIC_COVER_FULL_URL) + : process.env.NEXT_PUBLIC_COVER_FULL_URL) +

View File

@@ -34,7 +34,12 @@ export abstract class HTTPService {
schema: Z, schema: Z,
options?: RequestOptions options?: RequestOptions
) { ) {
return await fetch(process.env.NEXT_PUBLIC_BASE_URL + url, { return await fetch(
"" +
process.env.NEXT_PUBLIC_BASE_URL +
process.env.NEXT_PUBLIC_API_PATTERN +
url,
{
method: method, method: method,
headers: { headers: {
accept: "application/json", accept: "application/json",
@@ -52,7 +57,8 @@ export abstract class HTTPService {
), ),
cache: options?.cache ?? options?.next ? undefined : "no-cache", cache: options?.cache ?? options?.next ? undefined : "no-cache",
next: options?.next ?? {}, next: options?.next ?? {},
}) }
)
.then((r) => { .then((r) => {
if (r && r.ok) return r; if (r && r.ok) return r;
else throw Error("Response ok = false"); else throw Error("Response ok = false");

View File

@@ -62,6 +62,9 @@ export const ItemFragment = ({
controlsList="nodownload" controlsList="nodownload"
typeof="audio/mpeg" typeof="audio/mpeg"
src={ src={
"" +
process.env.NEXT_PUBLIC_BASE_URL +
process.env.NEXT_PUBLIC_API_PATTERN +
process.env.NEXT_PUBLIC_FRAGMENT_URL + process.env.NEXT_PUBLIC_FRAGMENT_URL +
"/" + "/" +
(watched_fragment ?? "") (watched_fragment ?? "")

View File

@@ -67,7 +67,12 @@ export const ItemTorrent = ({
<div className="flex flex-col items-center"> <div className="flex flex-col items-center">
<Link <Link
href={ href={
process.env.NEXT_PUBLIC_CONTENT_URL + "/" + watched_torrent_file "" +
process.env.NEXT_PUBLIC_BASE_URL +
process.env.NEXT_PUBLIC_API_PATTERN +
process.env.NEXT_PUBLIC_CONTENT_URL +
"/" +
watched_torrent_file
} }
className={clsx( className={clsx(
"p-4 bg-ac0 text-fg1 text-2xl rounded-lg", "p-4 bg-ac0 text-fg1 text-2xl rounded-lg",