From c7d9605d8129c2cec2b28b4d8362ff16e5e093ec Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Sun, 6 Apr 2025 19:17:12 -0600 Subject: [PATCH 1/5] Fix download link creation in album edit --- src/pages/api/album/edit.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/pages/api/album/edit.ts b/src/pages/api/album/edit.ts index b168d82..5927808 100644 --- a/src/pages/api/album/edit.ts +++ b/src/pages/api/album/edit.ts @@ -66,13 +66,17 @@ export const POST: APIRoute = async ({ request, locals }) => { await Promise.all([ cover ? handleCover(cover, 'album', albumId, tx) : undefined, downloads - ? tx.downloads.createMany({ - data: downloads.map((d) => ({ - title: d.title, - albumId: albumId, - links: { create: d.links } - })) - }) + ? Promise.all( + downloads.map((d) => + tx.downloads.create({ + data: { + title: d.title, + albumId: albumId, + links: { create: d.links } + } + }) + ) + ) : undefined ]) }) From 80742fffdbadf8fd22b89229c8289a3be6020ff7 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Sun, 6 Apr 2025 19:23:34 -0600 Subject: [PATCH 2/5] Only handle cover on album edit when image is uploaded --- src/pages/api/album/edit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/api/album/edit.ts b/src/pages/api/album/edit.ts index 5927808..14fed7a 100644 --- a/src/pages/api/album/edit.ts +++ b/src/pages/api/album/edit.ts @@ -64,7 +64,7 @@ export const POST: APIRoute = async ({ request, locals }) => { }) await Promise.all([ - cover ? handleCover(cover, 'album', albumId, tx) : undefined, + cover && cover.size > 0 ? handleCover(cover, 'album', albumId, tx) : undefined, downloads ? Promise.all( downloads.map((d) => From cfc3d291358fe52b468b0ecd8b2a698088fd4db1 Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Sun, 6 Apr 2025 23:36:35 -0600 Subject: [PATCH 3/5] Message when previewing a hidden album --- src/pages/admin/album/[id].astro | 2 +- src/pages/album/[id].astro | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pages/admin/album/[id].astro b/src/pages/admin/album/[id].astro index c5e8bce..b72350a 100644 --- a/src/pages/admin/album/[id].astro +++ b/src/pages/admin/album/[id].astro @@ -81,7 +81,7 @@ if (!album) { - + diff --git a/src/pages/album/[id].astro b/src/pages/album/[id].astro index 7b09f8e..9734563 100644 --- a/src/pages/album/[id].astro +++ b/src/pages/album/[id].astro @@ -86,6 +86,14 @@ const coverImage = await getImage({ meta: [{ name: 'theme-color', content: album?.headerColor }] }} /> + +{album?.status === AlbumStatus.HIDDEN ? ( + +) : null} +
Date: Sun, 6 Apr 2025 23:37:37 -0600 Subject: [PATCH 4/5] Delete downloads before editing album --- src/pages/api/album/edit.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/api/album/edit.ts b/src/pages/api/album/edit.ts index 14fed7a..e3d9de2 100644 --- a/src/pages/api/album/edit.ts +++ b/src/pages/api/album/edit.ts @@ -59,7 +59,8 @@ export const POST: APIRoute = async ({ request, locals }) => { games: { deleteMany: {}, create: games?.map((slug) => ({ game: { connect: { slug } } })) }, platforms: { deleteMany: {}, create: platforms?.map((id) => ({ platform: { connect: { id } } })) }, discs: { deleteMany: {}, createMany: { data: body.discs ?? [] } }, - relatedAlbums: { deleteMany: {}, create: related?.map((id) => ({ relatedAlbum: { connect: { id } } })) } + relatedAlbums: { deleteMany: {}, create: related?.map((id) => ({ relatedAlbum: { connect: { id } } })) }, + downloads: { deleteMany: {} } } }) From deb47c52e1e41b3165b5fa299496b37162ca3b8f Mon Sep 17 00:00:00 2001 From: Jorge Vargas Date: Sun, 6 Apr 2025 23:47:45 -0600 Subject: [PATCH 5/5] Add referential actions to schema --- .../migration.sql | 44 +++++++++++++++++++ prisma/schema.prisma | 12 ++--- 2 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 prisma/migrations/20250407054739_add_referencial_actions/migration.sql diff --git a/prisma/migrations/20250407054739_add_referencial_actions/migration.sql b/prisma/migrations/20250407054739_add_referencial_actions/migration.sql new file mode 100644 index 0000000..a976dd9 --- /dev/null +++ b/prisma/migrations/20250407054739_add_referencial_actions/migration.sql @@ -0,0 +1,44 @@ +-- DropForeignKey +ALTER TABLE `comments` DROP FOREIGN KEY `comments_ibfk_1`; + +-- DropForeignKey +ALTER TABLE `discs` DROP FOREIGN KEY `discs_ibfk_1`; + +-- DropForeignKey +ALTER TABLE `favorites` DROP FOREIGN KEY `favorites_ibfk_1`; + +-- DropForeignKey +ALTER TABLE `links` DROP FOREIGN KEY `links_ibfk_1`; + +-- DropForeignKey +ALTER TABLE `ratings` DROP FOREIGN KEY `ratings_ibfk_1`; + +-- DropIndex +DROP INDEX `ostId` ON `comments`; + +-- DropIndex +DROP INDEX `discs_ibfk_1` ON `discs`; + +-- DropIndex +DROP INDEX `favorites_ibfk_1` ON `favorites`; + +-- DropIndex +DROP INDEX `links_ibfk_1` ON `links`; + +-- DropIndex +DROP INDEX `ratings_ibfk_1` ON `ratings`; + +-- AddForeignKey +ALTER TABLE `comments` ADD CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `discs` ADD CONSTRAINT `discs_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `favorites` ADD CONSTRAINT `favorites_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `links` ADD CONSTRAINT `links_ibfk_1` FOREIGN KEY (`downloadId`) REFERENCES `downloads`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `ratings` ADD CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f909414..18b492e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -199,8 +199,8 @@ model comments { updatedAt DateTime @db.DateTime(0) albumId Int? username String? @db.VarChar(255) - album albums? @relation(fields: [albumId], references: [id], map: "comments_ibfk_1") - user users? @relation(fields: [username], references: [id], map: "comments_ibfk_2") + album albums? @relation(fields: [albumId], references: [id], map: "comments_ibfk_1", onDelete: Cascade) + user users? @relation(fields: [username], references: [id], map: "comments_ibfk_2", onDelete: SetNull) } model config { @@ -215,7 +215,7 @@ model discs { number Int? body String? @db.Text albumId Int - album albums? @relation(fields: [albumId], references: [id], map: "discs_ibfk_1") + album albums? @relation(fields: [albumId], references: [id], map: "discs_ibfk_1", onDelete: Cascade) } model downloads { @@ -232,7 +232,7 @@ model favorites { updatedAt DateTime @db.DateTime(0) albumId Int username String? @db.VarChar(255) - album albums? @relation(fields: [albumId], references: [id], map: "favorites_ibfk_1") + album albums? @relation(fields: [albumId], references: [id], map: "favorites_ibfk_1", onDelete: Cascade) users users? @relation(fields: [username], references: [id], map: "favorites_ibfk_2") } @@ -277,7 +277,7 @@ model links { provider String? @db.VarChar(255) downloadId Int url2 String? @db.VarChar(255) - download downloads? @relation(fields: [downloadId], references: [id], map: "links_ibfk_1") + download downloads? @relation(fields: [downloadId], references: [id], map: "links_ibfk_1", onDelete: Cascade) } model logs { @@ -321,7 +321,7 @@ model ratings { updatedAt DateTime @db.DateTime(0) albumId Int username String @db.VarChar(255) - album albums? @relation(fields: [albumId], references: [id], map: "ratings_ibfk_1") + album albums? @relation(fields: [albumId], references: [id], map: "ratings_ibfk_1", onDelete: Cascade) user users? @relation(fields: [username], references: [id], map: "ratings_ibfk_2") }