Intelligence

Artifacts

Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.

Repository
globals.csslayout.tsxnot-found.tsxpage.tsx
.gitignoreDockerfilenext-env.d.tsnext.config.mjspackage-lock.jsonpackage.jsonpostcss.config.mjsREADME.mdtailwind.config.tstsconfig.jsontsconfig.tsbuildinfo
README.md
CONSTITUTION_COMPLIANCE_AUDIT_V1.mdREADME.md
repositories/aaf-holdings/hq01/app/api/files/folder/route.ts
1.8 KB
import { NextResponse } from "next/server";
import { createFolder, deleteFolder, FileOpError } from "@/lib/files/manager";

/**
 * Folder operations for the document file-manager.
 *
 *   POST   /api/files/folder   { parent, name }  → create a sub-folder
 *   DELETE /api/files/folder   { path }          → delete a folder (recursive)
 *
 * Both are confined to the managed governance roots; a top-level root can never
 * be deleted.
 */

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

export async function POST(request: Request) {
  let body: { parent?: string; name?: string };
  try {
    body = await request.json();
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  if (!body.parent || !body.name) {
    return NextResponse.json(
      { error: "Both parent and name are required." },
      { status: 400 },
    );
  }
  try {
    const path = createFolder(body.parent, body.name);
    return NextResponse.json({ ok: true, path }, { status: 201 });
  } catch (err) {
    return errorResponse(err);
  }
}

export async function DELETE(request: Request) {
  let body: { path?: string };
  try {
    body = await request.json();
  } catch {
    return NextResponse.json({ error: "Invalid JSON." }, { status: 400 });
  }
  if (!body.path) {
    return NextResponse.json({ error: "A path is required." }, { status: 400 });
  }
  try {
    const removed = deleteFolder(body.path);
    return NextResponse.json({ ok: true, removed });
  } catch (err) {
    return errorResponse(err);
  }
}

function errorResponse(err: unknown) {
  if (err instanceof FileOpError) {
    return NextResponse.json({ error: err.message }, { status: err.status });
  }
  const message = err instanceof Error ? err.message : "Operation failed.";
  return NextResponse.json({ error: message }, { status: 500 });
}

root · /srv/aaf