feat: add aliyun oss storage config

This commit is contained in:
kris
2026-03-29 16:05:25 +08:00
parent de23a6e921
commit 3307f79162
9 changed files with 1717 additions and 28 deletions

View File

@@ -0,0 +1,53 @@
import { NextRequest, NextResponse } from "next/server";
import { requireRequestSession } from "@/lib/boss-auth";
import {
getAttachmentStorageConfig,
upsertAttachmentStorageConfig,
} from "@/lib/boss-data";
import {
type AttachmentStorageConfigPatch,
applyAttachmentStorageConfigPatch,
} from "@/lib/boss-storage-config";
import {
normalizeStorageError,
sanitizeAttachmentStorageConfig,
} from "@/lib/boss-storage";
export const runtime = "nodejs";
export async function GET(request: NextRequest) {
const session = await requireRequestSession(request);
if (!session) {
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
}
const config = await getAttachmentStorageConfig(session.account);
return NextResponse.json({
ok: true,
config: sanitizeAttachmentStorageConfig(config),
});
}
export async function PATCH(request: NextRequest) {
const session = await requireRequestSession(request);
if (!session) {
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
}
const body = (await request.json()) as AttachmentStorageConfigPatch;
try {
const existing = await getAttachmentStorageConfig(session.account);
const nextConfig = await applyAttachmentStorageConfigPatch(existing, body);
const saved = await upsertAttachmentStorageConfig(nextConfig);
return NextResponse.json({
ok: true,
config: sanitizeAttachmentStorageConfig(saved),
});
} catch (error) {
return NextResponse.json(
{ ok: false, message: normalizeStorageError(error) },
{ status: 400 },
);
}
}

View File

@@ -0,0 +1,49 @@
import { NextRequest, NextResponse } from "next/server";
import { requireRequestSession } from "@/lib/boss-auth";
import {
getAttachmentStorageConfig,
upsertAttachmentStorageConfig,
} from "@/lib/boss-data";
import {
type AttachmentStorageConfigPatch,
applyAttachmentStorageConfigPatch,
} from "@/lib/boss-storage-config";
import {
normalizeStorageError,
sanitizeAttachmentStorageConfig,
validateAttachmentStorageConfig,
} from "@/lib/boss-storage";
export const runtime = "nodejs";
export async function POST(request: NextRequest) {
const session = await requireRequestSession(request);
if (!session) {
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
}
const body = (await request.json().catch(() => ({}))) as AttachmentStorageConfigPatch;
try {
const existing = await getAttachmentStorageConfig(session.account);
const draft = await applyAttachmentStorageConfigPatch(existing, body);
const result = await validateAttachmentStorageConfig(draft);
const saved = await upsertAttachmentStorageConfig({
...draft,
validatedAt: new Date().toISOString(),
});
return NextResponse.json({
ok: true,
provider: result.provider,
bucket: result.bucket,
endpoint: result.endpoint,
region: result.region,
config: sanitizeAttachmentStorageConfig(saved),
});
} catch (error) {
return NextResponse.json(
{ ok: false, message: normalizeStorageError(error) },
{ status: 400 },
);
}
}