You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
741 B
20 lines
741 B
import { EXPORT_MASK_POLICIES, type ExportMaskPolicy } from "../constants/export";
|
|
import { createError } from "h3";
|
|
|
|
type MeExportRequestBody = {
|
|
maskPolicy?: unknown;
|
|
};
|
|
|
|
export function parseMeExportRequestBody(body: unknown): { maskPolicy: ExportMaskPolicy } {
|
|
const payload = (body && typeof body === "object" ? body : {}) as MeExportRequestBody;
|
|
const raw = payload.maskPolicy;
|
|
if (raw === undefined || raw === null || raw === "") {
|
|
return { maskPolicy: "masked" };
|
|
}
|
|
|
|
if (typeof raw !== "string" || !EXPORT_MASK_POLICIES.includes(raw as ExportMaskPolicy)) {
|
|
throw createError({ statusCode: 400, statusMessage: "maskPolicy 非法,仅支持 masked|raw" });
|
|
}
|
|
|
|
return { maskPolicy: raw as ExportMaskPolicy };
|
|
}
|
|
|