feat: bootstrap auto virtual tryon admin frontend
This commit is contained in:
45
app/api/libraries/[libraryType]/route.ts
Normal file
45
app/api/libraries/[libraryType]/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
GARMENT_LIBRARY_FIXTURES,
|
||||
MODEL_LIBRARY_FIXTURES,
|
||||
SCENE_LIBRARY_FIXTURES,
|
||||
} from "@/lib/mock/libraries";
|
||||
import { RouteError, jsonSuccess, withErrorHandling } from "@/lib/http/response";
|
||||
import type { LibraryItemVM, LibraryType } from "@/lib/types/view-models";
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{
|
||||
libraryType: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
const LIBRARY_FIXTURE_MAP: Record<LibraryType, LibraryItemVM[]> = {
|
||||
models: MODEL_LIBRARY_FIXTURES,
|
||||
scenes: SCENE_LIBRARY_FIXTURES,
|
||||
garments: GARMENT_LIBRARY_FIXTURES,
|
||||
};
|
||||
|
||||
const MESSAGE = "资源库当前使用占位数据,真实后端接口尚未提供。";
|
||||
|
||||
function isLibraryType(value: string): value is LibraryType {
|
||||
return Object.hasOwn(LIBRARY_FIXTURE_MAP, value);
|
||||
}
|
||||
|
||||
export async function GET(_request: Request, context: RouteContext) {
|
||||
return withErrorHandling(async () => {
|
||||
const { libraryType } = await context.params;
|
||||
|
||||
if (!isLibraryType(libraryType)) {
|
||||
throw new RouteError(404, "NOT_FOUND", "不支持的资源库类型。");
|
||||
}
|
||||
|
||||
return jsonSuccess(
|
||||
{
|
||||
items: LIBRARY_FIXTURE_MAP[libraryType],
|
||||
},
|
||||
{
|
||||
mode: "placeholder",
|
||||
message: MESSAGE,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user