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
NEXT_PUBLIC_CONTENT_URL=http://127.0.0.1:8000/content/torrent
NEXT_PUBLIC_FRAGMENT_URL=http://127.0.0.1:8000/content/audio
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
BACKEND_PROTOCOL=http
BACKEND_DOMAIN=127.0.0.1
BACKEND_PORT=8000
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} */
const nextConfig = {
async rewrites() {
return process.env.NODE_ENV == "development"
? [
{
source: "/api/:path*",
destination: "http://127.0.0.1:8000/:path*",
},
]
: [];
return [
{
source: "/api/:path*",
destination: `${process.env.BACKEND_PROTOCOL}://`+
`${process.env.BACKEND_DOMAIN}:${process.env.BACKEND_PORT}/:path*`,
}
]
},
images: {
remotePatterns: [
{
protocol: "http",
hostname: "127.0.0.1",
port: "8000",
protocol: process.env.BASE_PROTOCOL,
hostname: process.env.BASE_DOMAIN,
port: process.env.BASE_PORT,
},
],
},

View File

@@ -11,39 +11,47 @@ export const metadata: Metadata = {
};
export default async function Home() {
const cards: { [k in SectionType]?: ItemCardType[] | null } = {};
await Promise.all(
SectionService.sections.map(async (section) => {
cards[section] = await ItemService.itemsConfiguration[
SectionService.sectionsConfiguration[section].itemType
].service.GetCards();
})
const requests = SectionService.sections.map((section) =>
ItemService.itemsConfiguration[
SectionService.sectionsConfiguration[section].itemType
].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 (
<>
{SectionService.sections.map((section) => (
<section key={section}>
{cards[section] && cards[section].length > 0 && (
<Section
name={
SectionService.sectionsConfiguration[section]
.popularSubsectionName
}
link={
SectionService.isSection(section) ? `/${section}` : undefined
}
invite_text={
SectionService.sectionsConfiguration[section].sectionInviteText
}
>
{cards[section].map((card) => (
<ItemCard key={card.id} card={card} />
))}
</Section>
)}
</section>
))}
{cards &&
SectionService.sections.map((section, i) => (
<section key={section}>
{cards[section] && (
<Section
name={
SectionService.sectionsConfiguration[section]
.popularSubsectionName
}
link={
SectionService.isSection(section) ? `/${section}` : undefined
}
invite_text={
SectionService.sectionsConfiguration[section]
.sectionInviteText
}
>
{cards[section]?.map((card) => (
<ItemCard key={card.id} card={card} />
))}
</Section>
)}
</section>
))}
</>
);
}

View File

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

View File

@@ -34,25 +34,31 @@ export abstract class HTTPService {
schema: Z,
options?: RequestOptions
) {
return await fetch(process.env.NEXT_PUBLIC_BASE_URL + url, {
method: method,
headers: {
accept: "application/json",
...((options?.stringify ?? true) != true
? {}
: { "Content-Type": "application/json" }),
Authorization: "Bearer " + UserService.GetToken(),
...options?.headers,
},
body:
(options?.stringify ?? true) != true
? (options?.body as BodyInit)
: JSON.stringify(
this.deepUndefinedToNull(options?.body as object | undefined)
),
cache: options?.cache ?? options?.next ? undefined : "no-cache",
next: options?.next ?? {},
})
return await fetch(
"" +
process.env.NEXT_PUBLIC_BASE_URL +
process.env.NEXT_PUBLIC_API_PATTERN +
url,
{
method: method,
headers: {
accept: "application/json",
...((options?.stringify ?? true) != true
? {}
: { "Content-Type": "application/json" }),
Authorization: "Bearer " + UserService.GetToken(),
...options?.headers,
},
body:
(options?.stringify ?? true) != true
? (options?.body as BodyInit)
: JSON.stringify(
this.deepUndefinedToNull(options?.body as object | undefined)
),
cache: options?.cache ?? options?.next ? undefined : "no-cache",
next: options?.next ?? {},
}
)
.then((r) => {
if (r && r.ok) return r;
else throw Error("Response ok = false");

View File

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

View File

@@ -67,7 +67,12 @@ export const ItemTorrent = ({
<div className="flex flex-col items-center">
<Link
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(
"p-4 bg-ac0 text-fg1 text-2xl rounded-lg",