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.
35 lines
1.1 KiB
35 lines
1.1 KiB
import { deleteMediaAssetsForUser } from "#server/service/media";
|
|
|
|
const MAX_BATCH = 50;
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await event.context.auth.requireUser();
|
|
const body = await readBody<{ ids?: unknown }>(event);
|
|
|
|
if (body === null || typeof body !== "object" || !("ids" in body)) {
|
|
throw createError({ statusCode: 400, statusMessage: "请求体须包含 ids 数组" });
|
|
}
|
|
|
|
const { ids } = body;
|
|
if (!Array.isArray(ids)) {
|
|
throw createError({ statusCode: 400, statusMessage: "ids 必须为数组" });
|
|
}
|
|
if (ids.length > MAX_BATCH) {
|
|
throw createError({ statusCode: 400, statusMessage: `单次最多删除 ${MAX_BATCH} 条` });
|
|
}
|
|
|
|
const numericIds: number[] = [];
|
|
for (const x of ids) {
|
|
if (typeof x !== "number" || !Number.isInteger(x) || x < 1) {
|
|
throw createError({ statusCode: 400, statusMessage: "ids 须均为正整数" });
|
|
}
|
|
numericIds.push(x);
|
|
}
|
|
|
|
if (numericIds.length === 0) {
|
|
return R.success({ deleted: 0 });
|
|
}
|
|
|
|
const deleted = await deleteMediaAssetsForUser(user.id, numericIds);
|
|
return R.success({ deleted });
|
|
});
|
|
|