Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit a2c3d60

Browse files
committed
feat: add metadata
1 parent 87f23cc commit a2c3d60

File tree

13 files changed

+190
-105
lines changed

13 files changed

+190
-105
lines changed

docker-compose.yml

+22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
version: '3'
22

3+
volumes:
4+
db:
5+
6+
37
services:
48
redis:
59
image: redis:7-alpine
610
ports:
711
- 6379:6379
12+
db:
13+
image: postgres:alpine
14+
restart: unless-stopped
15+
healthcheck:
16+
test: [ "CMD-SHELL", "pg_isready -U kaizoku" ]
17+
interval: 5s
18+
timeout: 5s
19+
retries: 5
20+
env_file:
21+
- .env
22+
environment:
23+
POSTGRES_USER: ${DATABASE_USER}
24+
POSTGRES_DB: ${DATABASE_SCHEMA}
25+
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
26+
volumes:
27+
- db:/var/lib/postgresql/data
28+
ports:
29+
- "${DATABASE_PORT}:5432"

prisma/migrations/20221015132249_init/migration.sql

-32
This file was deleted.

prisma/migrations/20221015165819_add_dates/migration.sql

-39
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- CreateTable
2+
CREATE TABLE "Library" (
3+
"id" SERIAL NOT NULL,
4+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
5+
"path" TEXT NOT NULL,
6+
7+
CONSTRAINT "Library_pkey" PRIMARY KEY ("id")
8+
);
9+
10+
-- CreateTable
11+
CREATE TABLE "Manga" (
12+
"id" SERIAL NOT NULL,
13+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
14+
"title" TEXT NOT NULL,
15+
"interval" TEXT NOT NULL,
16+
"source" TEXT NOT NULL,
17+
"libraryId" INTEGER NOT NULL,
18+
"metadataId" INTEGER NOT NULL,
19+
20+
CONSTRAINT "Manga_pkey" PRIMARY KEY ("id")
21+
);
22+
23+
-- CreateTable
24+
CREATE TABLE "Chapter" (
25+
"id" SERIAL NOT NULL,
26+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
27+
"index" INTEGER NOT NULL,
28+
"fileName" TEXT NOT NULL,
29+
"size" INTEGER NOT NULL,
30+
"mangaId" INTEGER NOT NULL,
31+
32+
CONSTRAINT "Chapter_pkey" PRIMARY KEY ("id")
33+
);
34+
35+
-- CreateTable
36+
CREATE TABLE "Metadata" (
37+
"id" SERIAL NOT NULL,
38+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
39+
"genres" TEXT[] DEFAULT ARRAY[]::TEXT[],
40+
"summary" TEXT NOT NULL DEFAULT '',
41+
"authors" TEXT[] DEFAULT ARRAY[]::TEXT[],
42+
"cover" TEXT NOT NULL DEFAULT '/cover-not-found.jpg',
43+
"tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
44+
"characters" TEXT[] DEFAULT ARRAY[]::TEXT[],
45+
"status" TEXT NOT NULL DEFAULT 'UNKNOWN',
46+
"startDate" TIMESTAMP(3),
47+
"endDate" TIMESTAMP(3),
48+
"synonyms" TEXT[] DEFAULT ARRAY[]::TEXT[],
49+
"urls" TEXT[] DEFAULT ARRAY[]::TEXT[],
50+
51+
CONSTRAINT "Metadata_pkey" PRIMARY KEY ("id")
52+
);
53+
54+
-- CreateIndex
55+
CREATE UNIQUE INDEX "Library_path_key" ON "Library"("path");
56+
57+
-- CreateIndex
58+
CREATE UNIQUE INDEX "Manga_title_key" ON "Manga"("title");
59+
60+
-- CreateIndex
61+
CREATE UNIQUE INDEX "Manga_metadataId_key" ON "Manga"("metadataId");
62+
63+
-- AddForeignKey
64+
ALTER TABLE "Manga" ADD CONSTRAINT "Manga_libraryId_fkey" FOREIGN KEY ("libraryId") REFERENCES "Library"("id") ON DELETE CASCADE ON UPDATE CASCADE;
65+
66+
-- AddForeignKey
67+
ALTER TABLE "Manga" ADD CONSTRAINT "Manga_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "Metadata"("id") ON DELETE CASCADE ON UPDATE CASCADE;
68+
69+
-- AddForeignKey
70+
ALTER TABLE "Chapter" ADD CONSTRAINT "Chapter_mangaId_fkey" FOREIGN KEY ("mangaId") REFERENCES "Manga"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/migrations/migration_lock.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
22
# It should be added in your version-control system (i.e. Git)
3-
provider = "sqlite"
3+
provider = "postgresql"

prisma/schema.prisma

+29-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ generator client {
77
}
88

99
datasource db {
10-
provider = "sqlite"
11-
url = "file:./kaizoku.db"
10+
provider = "postgresql"
11+
url = env("DATABASE_URL")
1212
}
1313

1414
model Library {
@@ -19,15 +19,16 @@ model Library {
1919
}
2020

2121
model Manga {
22-
id Int @id @default(autoincrement())
23-
createdAt DateTime @default(now())
24-
title String @unique
25-
cover String
26-
interval String
27-
source String
28-
library Library @relation(fields: [libraryId], references: [id], onDelete: Cascade)
29-
libraryId Int
30-
chapter Chapter[]
22+
id Int @id @default(autoincrement())
23+
createdAt DateTime @default(now())
24+
title String @unique
25+
interval String
26+
source String
27+
library Library @relation(fields: [libraryId], references: [id], onDelete: Cascade)
28+
libraryId Int
29+
chapter Chapter[]
30+
metadata Metadata @relation(fields: [metadataId], references: [id], onDelete: Cascade)
31+
metadataId Int @unique
3132
}
3233

3334
model Chapter {
@@ -39,3 +40,20 @@ model Chapter {
3940
manga Manga @relation(fields: [mangaId], references: [id], onDelete: Cascade)
4041
mangaId Int
4142
}
43+
44+
model Metadata {
45+
id Int @id @default(autoincrement())
46+
createdAt DateTime @default(now())
47+
manga Manga?
48+
genres String[] @default([])
49+
summary String @default("")
50+
authors String[] @default([])
51+
cover String @default("/cover-not-found.jpg")
52+
tags String[] @default([])
53+
characters String[] @default([])
54+
status String @default("UNKNOWN")
55+
startDate DateTime?
56+
endDate DateTime?
57+
synonyms String[] @default([])
58+
urls String[] @default([])
59+
}

src/components/addManga/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function AddManga({ onAdd }: { onAdd: () => void }) {
3232
trapFocus: true,
3333
size: 'xl',
3434
closeOnClickOutside: false,
35+
closeOnEscape: true,
3536
title: 'Add a new manga',
3637
centered: true,
3738
children: (

src/components/addManga/steps/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ export default function AddMangaSteps({
5050
<Stepper.Step
5151
label="Source"
5252
description={form.values.source || 'Select a source'}
53-
allowStepSelect={active > 0}
53+
allowStepSelect={false}
5454
color={active > 0 ? 'teal' : 'blue'}
5555
>
5656
<SourceStep form={form} />
5757
</Stepper.Step>
5858
<Stepper.Step
5959
label="Manga"
6060
description={form.values.mangaTitle || 'Search for manga'}
61-
allowStepSelect={active > 1}
61+
allowStepSelect={false}
6262
color={active > 1 ? 'teal' : 'blue'}
6363
>
6464
<SearchStep form={form} />
6565
</Stepper.Step>
6666
<Stepper.Step
6767
label="Download"
6868
description={form.values.interval || 'Select an interval'}
69-
allowStepSelect={active > 2}
69+
allowStepSelect={false}
7070
color={active > 2 ? 'teal' : 'blue'}
7171
>
7272
<DownloadStep form={form} />

src/components/headerSearch.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export function SearchControl() {
3131
setActions(
3232
mangaQuery.data.map((m) => ({
3333
title: m.title,
34-
description: m.title,
34+
description: `${m.metadata.summary.split(' ').slice(0, 50).join(' ')}...`,
3535
group: m.source,
3636
icon: (
3737
<Image
3838
withPlaceholder
39-
placeholder={<Image src="/cover-not-found.jpg" alt={m.title} width={63} height={96} />}
40-
src={m.cover}
41-
width={42}
42-
height={64}
39+
placeholder={<Image src="/cover-not-found.jpg" alt={m.title} width={60} height={100} />}
40+
src={m.metadata.cover}
41+
width={60}
42+
height={100}
4343
/>
4444
),
4545
closeOnTrigger: true,
@@ -54,6 +54,7 @@ export function SearchControl() {
5454
actions={actions}
5555
searchIcon={<IconSearch size={18} />}
5656
highlightQuery
57+
limit={5}
5758
disabled={isDisabled}
5859
searchPlaceholder="Search..."
5960
shortcut="ctrl + p"

src/components/navbar.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function History({ data }: { data: HistoryType }) {
140140
<Timeline.Item
141141
key={chapter.id}
142142
lineVariant="dotted"
143-
bullet={<Image mt={20} alt="header" src={chapter.manga.cover} height={40} width={26} />}
143+
bullet={<Image mt={20} alt="header" src={chapter.manga.metadata.cover} height={40} width={26} />}
144144
title={<HistoryItemTitle chapter={chapter} />}
145145
>
146146
<HistoryItem chapter={chapter} />
@@ -235,6 +235,11 @@ export function KaizokuNavbar() {
235235

236236
const historyQuery = trpc.manga.history.useQuery();
237237
const activityQuery = trpc.manga.activity.useQuery();
238+
const libraryQuery = trpc.library.query.useQuery();
239+
240+
if (!libraryQuery.data) {
241+
return null;
242+
}
238243

239244
return (
240245
<Navbar width={{ sm: 300 }} p="md" className={classes.navbar} fixed>

src/pages/index.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Code, Grid, Text } from '@mantine/core';
1+
import { Code, Grid, LoadingOverlay, Text } from '@mantine/core';
22
import { showNotification } from '@mantine/notifications';
33
import { IconCheck, IconX } from '@tabler/icons';
44
import { useRouter } from 'next/router';
@@ -15,6 +15,10 @@ export default function IndexPage() {
1515

1616
const mangaQuery = trpc.manga.query.useQuery();
1717

18+
if (libraryQuery.isLoading) {
19+
return <LoadingOverlay visible />;
20+
}
21+
1822
if (mangaQuery.isLoading || libraryQuery.isLoading) {
1923
return (
2024
<Grid justify="flex-start">
@@ -90,7 +94,7 @@ export default function IndexPage() {
9094
<MangaCard
9195
badge={manga.source}
9296
title={manga.title}
93-
cover={manga.cover}
97+
cover={manga.metadata.cover}
9498
onRemove={() => handleRemove(manga.id, manga.title)}
9599
onClick={() => router.push(`/manga/${manga.id}`)}
96100
/>

0 commit comments

Comments
 (0)