feat : remove legacy feature
CI / Verify (push) Successful in 1m21s
CI / Build immutable images and deploy (push) Successful in 4m32s

This commit is contained in:
2026-09-10 19:45:06 +07:00 Unverified
parent cc0757d0a0
commit 249af29e9b
56 changed files with 5491 additions and 9393 deletions
+57 -7
View File
@@ -1,10 +1,16 @@
import "server-only";
import { and, eq, sql } from "drizzle-orm";
import { and, eq, isNull, sql } from "drizzle-orm";
import sharp from "sharp";
import { getDb } from "@/db";
import { media } from "@/db/schema";
import {
extraSectionRows,
guides,
guidePosterBleeding,
guideSections,
media,
} from "@/db/schema";
import { getMediaStorage, publicMediaUrl } from "@/lib/media/storage";
import {
hasValidImageSignature,
@@ -137,11 +143,7 @@ export async function completePendingMedia(mediaId: string) {
export async function discardUnreferencedMedia(mediaId: string): Promise<boolean> {
const [record] = await getDb().select().from(media).where(eq(media.id, mediaId)).limit(1);
if (
!record ||
record.currentReferenceCount > 0 ||
record.revisionReferenceCount > 0
) {
if (!record || record.currentReferenceCount > 0) {
return false;
}
await (await getMediaStorage()).delete(record.objectKey).catch(() => undefined);
@@ -157,3 +159,51 @@ export async function getReadyMedia(mediaId: string) {
.limit(1);
return record ?? null;
}
export async function getMediaVisibility(mediaId: string): Promise<{
public: boolean;
retained: boolean;
}> {
const db = getDb();
const [covers, posters, bleeding, extras, [record]] = await Promise.all([
db.select({ id: guides.id }).from(guides).where(and(
eq(guides.coverMediaId, mediaId),
eq(guides.isPublic, true),
isNull(guides.trashedAt),
)).limit(1),
db.select({ id: guides.id }).from(guides).where(and(
eq(guides.posterArtMediaId, mediaId),
eq(guides.isPublic, true),
isNull(guides.trashedAt),
)).limit(1),
db
.select({ id: guides.id })
.from(guidePosterBleeding)
.innerJoin(guides, eq(guides.id, guidePosterBleeding.guideId))
.where(and(
eq(guidePosterBleeding.mediaId, mediaId),
eq(guides.isPublic, true),
isNull(guides.trashedAt),
))
.limit(1),
db
.select({ id: guides.id })
.from(extraSectionRows)
.innerJoin(guideSections, eq(guideSections.id, extraSectionRows.sectionId))
.innerJoin(guides, eq(guides.id, guideSections.guideId))
.where(and(
eq(extraSectionRows.mediaId, mediaId),
eq(guideSections.enabled, true),
eq(guides.isPublic, true),
isNull(guides.trashedAt),
))
.limit(1),
db.select({
currentReferenceCount: media.currentReferenceCount,
}).from(media).where(eq(media.id, mediaId)).limit(1),
]);
return {
public: Boolean(covers.length || posters.length || bleeding.length || extras.length),
retained: Boolean(record && record.currentReferenceCount > 0),
};
}