Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/app/api/projects/[projectId]/artifacts/[artifactId]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getArtifactService } from "../../../../../../server/evidence";
import { handleApiError, notFound, ok } from "../../../../_shared/http";

export const dynamic = "force-dynamic";

type Params = {
params: Promise<{ projectId: string; artifactId: string }>;
};

export async function GET(request: Request, context: Params) {
try {
const { projectId, artifactId } = await context.params;
const service = getArtifactService();
if (!service.readArtifactDetail) {
throw new Error("Artifact detail reads are unavailable.");
}

const previewBytes = new URL(request.url).searchParams.get("previewBytes");
const artifact = await service.readArtifactDetail({
projectId,
artifactId,
...(previewBytes ? { previewBytes: Number(previewBytes) } : {}),
});
if (!artifact) return notFound("Artifact not found.");

return ok(
{ artifact },
{ headers: { "cache-control": "private, no-store" } },
);
} catch (error) {
return handleApiError(error, { request, route: "artifact-detail" });
}
}
25 changes: 25 additions & 0 deletions src/app/api/projects/[projectId]/targets/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getProjectOverview } from "../../../../../server/chat/service";
import { listProjectTargetInventory } from "../../../../../server/targets/inventory";
import { handleApiError, notFound, ok } from "../../../_shared/http";

export const dynamic = "force-dynamic";

type Context = {
params: Promise<{ projectId: string }>;
};

export async function GET(_request: Request, context: Context) {
try {
const { projectId } = await context.params;
const project = await getProjectOverview(projectId);
if (!project) {
return notFound(`Project ${projectId} was not found.`);
}
return ok(
{ targets: await listProjectTargetInventory(projectId) },
{ headers: { "Cache-Control": "no-store" } },
);
} catch (error) {
return handleApiError(error);
}
}
Loading
Loading