feat: add admin accounts and image templates
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { createAsset } from "@/lib/server/data-store";
|
||||
import { jsonOk, readJsonBody } from "@/lib/server/api";
|
||||
import { authenticatePublicApiRequest } from "@/lib/server/public-api-auth";
|
||||
import { authenticatePublicApiRequest, publicApiOwnerId } from "@/lib/server/public-api-auth";
|
||||
import { listPublicApiAssets } from "@/lib/server/public-api-assets";
|
||||
import { publicApiError } from "@/lib/server/public-api-response";
|
||||
import { DEFAULT_OWNER_ID, requestOrigin } from "@/lib/server/runtime";
|
||||
import { requestOrigin } from "@/lib/server/runtime";
|
||||
import { saveUploadAsset } from "@/lib/server/storage";
|
||||
import type { AssetKind } from "@/lib/types";
|
||||
|
||||
@@ -21,13 +21,14 @@ export async function GET(request: Request) {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const client = authenticatePublicApiRequest(request);
|
||||
const ownerId = publicApiOwnerId(client);
|
||||
const contentType = request.headers.get("content-type") || "";
|
||||
if (contentType.includes("multipart/form-data")) {
|
||||
const form = await request.formData();
|
||||
const files = form.getAll("files").filter((item): item is File => item instanceof File);
|
||||
if (!files.length) throw new Error("No files uploaded.");
|
||||
const assets = await Promise.all(files.map(async (file) => saveUploadAsset({
|
||||
ownerId: DEFAULT_OWNER_ID,
|
||||
ownerId,
|
||||
bytes: await awaitFileBytes(file),
|
||||
fileName: file.name,
|
||||
contentType: file.type || "application/octet-stream",
|
||||
@@ -45,7 +46,7 @@ export async function POST(request: Request) {
|
||||
}>(request);
|
||||
if (!body.url) throw new Error("url is required");
|
||||
const asset = await createAsset({
|
||||
ownerId: DEFAULT_OWNER_ID,
|
||||
ownerId,
|
||||
kind: body.kind || "image",
|
||||
name: body.name || "外部素材",
|
||||
url: body.url,
|
||||
|
||||
Reference in New Issue
Block a user