Files
dragonsstash/src/app/api/zips/[id]/images/route.ts
admin ab558e00f5 feat: add preview management, channel controls, invite polish, and recovery
- Auto-extract preview images from ZIP/RAR/7z archives during ingestion
- Upload custom preview images via package drawer
- Select preview from archive contents with on-demand extraction UI
- Manually add Telegram channels by t.me link, username, or invite link
- Invite code UX: bulk create, copy link, usage tracking, delete confirm
- Incomplete upload recovery: verify dest messages on worker startup
- Rebuild package DB by scanning destination channel with live progress

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 00:09:59 +01:00

57 lines
1.4 KiB
TypeScript

import { NextResponse } from "next/server";
import { authenticateApiRequest } from "@/lib/telegram/api-auth";
import { prisma } from "@/lib/prisma";
export const dynamic = "force-dynamic";
const IMAGE_EXTENSIONS = ["jpg", "jpeg", "png", "webp", "gif", "bmp"];
/**
* GET /api/zips/:id/images
* Lists image files inside a package's archive (from PackageFile records).
* Returns a list of image file paths that can be used as preview candidates.
*/
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const authResult = await authenticateApiRequest(request);
if ("error" in authResult) return authResult.error;
const { id } = await params;
const pkg = await prisma.package.findUnique({
where: { id },
select: { id: true, archiveType: true },
});
if (!pkg) {
return NextResponse.json({ error: "Package not found" }, { status: 404 });
}
const images = await prisma.packageFile.findMany({
where: {
packageId: id,
extension: { in: IMAGE_EXTENSIONS },
},
orderBy: { path: "asc" },
select: {
id: true,
path: true,
fileName: true,
extension: true,
uncompressedSize: true,
},
});
const mapped = images.map((img) => ({
id: img.id,
path: img.path,
fileName: img.fileName,
extension: img.extension,
size: img.uncompressedSize.toString(),
}));
return NextResponse.json({ images: mapped });
}