feat(prototype): add upload manager and docker ci

- add prototype upload, list, view, and delete api routes
- add prototype manager ui with search, modal, and theme toggle
- add filesystem-backed zip extraction and serving logic
- switch project to pnpm with updated lockfile and tooling
- add multi-stage dockerfile with standalone next.js output
- add github actions to lint, build, and publish docker images
This commit is contained in:
siujamo committed 2026-08-31 13:43:59 +08:00
1 parent 0c592225e4
commit ed72045f5e
30 files changed
+5369 -6899

No files matched your search

@@ -0,0 +1,36 @@
import { NextResponse } from "next/server"
import { readPrototypeFile } from "@/lib/store"
export const runtime = "nodejs"
interface RouteContext {
params: Promise<{
id: string
path?: string[]
}>
}
function decodePathSegments(segments: string[] = []) {
return segments.map((segment) => decodeURIComponent(segment)).join("/")
}
export async function GET(_request: Request, context: RouteContext) {
const { id, path } = await context.params
const relativePath = decodePathSegments(path)
const file = await readPrototypeFile(id, relativePath || undefined)
if (!file) {
return NextResponse.json({ error: "文件不存在" }, { status: 404 })
}
return new NextResponse(file.content, {
headers: {
"content-type": file.mimeType,
"content-length": String(file.size),
"last-modified": file.lastModified,
"cache-control": "no-store",
"x-content-type-options": "nosniff",
},
})
}
+21
View File
@@ -0,0 +1,21 @@
import { NextResponse } from "next/server"
import { deletePrototype } from "@/lib/store"
export const runtime = "nodejs"
interface RouteContext {
params: Promise<{
id: string
}>
}
export async function DELETE(_request: Request, context: RouteContext) {
const { id } = await context.params
const deleted = await deletePrototype(id)
if (!deleted) {
return NextResponse.json({ error: "原型不存在" }, { status: 404 })
}
return NextResponse.json({ ok: true })
}
+44
View File
@@ -0,0 +1,44 @@
import { NextResponse } from "next/server"
import { createPrototypeFromZip, listPrototypes } from "@/lib/store"
export const runtime = "nodejs"
export async function GET() {
const prototypes = await listPrototypes()
return NextResponse.json({ data: prototypes })
}
export async function POST(request: Request) {
try {
const formData = await request.formData()
const name = `${formData.get("name") ?? ""}`
const description = `${formData.get("description") ?? ""}`
const file = formData.get("file")
if (!(file instanceof File)) {
return NextResponse.json({ error: "请上传 ZIP 文件" }, { status: 400 })
}
const buffer = Buffer.from(await file.arrayBuffer())
const created = await createPrototypeFromZip({
name,
description,
zipBuffer: buffer,
zipFileName: file.name,
})
return NextResponse.json({ data: created }, { status: 201 })
} catch (error) {
const message = error instanceof Error ? error.message : "上传失败"
const status =
message.includes("为空") ||
message.includes("不") ||
message.includes("非法") ||
message.includes("过大") ||
message.includes("未找到")
? 400
: 500
return NextResponse.json({ error: message }, { status })
}
}