Add OpenShell Control auth and installer

This commit is contained in:
Codex
2026-04-24 20:52:44 +00:00
parent 8e3b5332d4
commit ad8e25c056
27 changed files with 2057 additions and 298 deletions
@@ -0,0 +1,34 @@
import { NextResponse } from "next/server"
import { downloadSandboxFile } from "@/app/lib/sandboxFiles"
function contentDisposition(fileName: string) {
const fallback = fileName.replace(/[^\w.-]/g, "_") || "download.bin"
return `attachment; filename="${fallback}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
}
export async function GET(
request: Request,
{ params }: { params: Promise<{ sandboxId: string }> }
) {
try {
const { sandboxId } = await params
const requestUrl = new URL(request.url)
const sourcePath = requestUrl.searchParams.get("path") || ""
const downloaded = await downloadSandboxFile(sandboxId, sourcePath)
return new NextResponse(new Uint8Array(downloaded.bytes), {
status: 200,
headers: {
"cache-control": "no-store",
"content-disposition": contentDisposition(downloaded.fileName),
"content-length": String(downloaded.bytes.byteLength),
"content-type": "application/octet-stream",
"x-sandbox-name": downloaded.sandboxName,
"x-sandbox-path": downloaded.path,
},
})
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to download file"
return NextResponse.json({ ok: false, error: message }, { status: /required|path|large|exist/.test(message) ? 400 : 500 })
}
}
@@ -0,0 +1,29 @@
import { NextResponse } from "next/server"
import { uploadSandboxFile } from "@/app/lib/sandboxFiles"
export async function POST(
request: Request,
{ params }: { params: Promise<{ sandboxId: string }> }
) {
try {
const { sandboxId } = await params
const form = await request.formData()
const file = form.get("file")
const rawPath = form.get("path")
if (!(file instanceof File)) throw new Error("file is required")
const destinationPath = typeof rawPath === "string" && rawPath.trim()
? rawPath.trim()
: `/sandbox/${file.name}`
const payload = Buffer.from(await file.arrayBuffer())
const uploaded = await uploadSandboxFile(sandboxId, destinationPath, file.name, payload)
return NextResponse.json({
ok: true,
uploaded,
note: `Uploaded ${file.name} to ${uploaded.path}.`,
})
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to upload file"
return NextResponse.json({ ok: false, error: message }, { status: /required|path|large|exist/.test(message) ? 400 : 500 })
}
}