Files
Kaname/src/app/api/models/[id]/files/route.ts
T
Pascal LinxweilerandClaude Opus 5.5 5becfc47a0
Release / release (push) Successful in 4m33s
Release 0.16.0: new look, search, remove files, easier deploy
- Dot-matrix "Creation of Adam" page banners behind a floating menu,
  glass cards and tables, library header with live stats, table toolbar
  with pagination, Cmd/Ctrl+K search across models, endpoints, runs,
  tags, settings and actions.
- Remove single files from a model (selection + disk, via a worker job).
- Containers start as root to prepare folders and drop to PUID:PGID;
  AUTH_SECRET is generated when unset; sandbox runs as nobody;
  KANAME_IMAGE and image docs in the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 14:06:46 +01:00

34 lines
1.4 KiB
TypeScript

import { NextResponse } from "next/server";
import { z } from "zod";
import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { addFilesToModel, ModelError, removeFilesFromModel } from "@/lib/models";
const Body = z.object({ add: z.array(z.string().min(1).max(1024)).min(1).max(10_000) });
/** Add files to a model's selection and queue their download. */
export const POST = withAuth<RouteContext<"/api/models/[id]/files">>(async (req, { params }) => {
const { id } = await params;
try {
const { add } = Body.parse(await req.json());
return NextResponse.json(await addFilesToModel(id, add), { status: 201 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
return handleApiError(err);
}
});
const RemoveBody = z.object({ remove: z.array(z.string().min(1).max(1024)).min(1).max(10_000) });
/** Remove files from a model's selection and queue deleting them from disk. */
export const DELETE = withAuth<RouteContext<"/api/models/[id]/files">>(async (req, { params }) => {
const { id } = await params;
try {
const { remove } = RemoveBody.parse(await req.json());
return NextResponse.json(await removeFilesFromModel(id, remove), { status: 202 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
return handleApiError(err);
}
});