添加删除分享画廊的API支持

This commit is contained in:
2024-12-24 19:13:05 +08:00
parent 53a9b59ce0
commit 6985235ab1
3 changed files with 78 additions and 0 deletions

View File

@@ -15,6 +15,33 @@ import {
import { get_host, return_data, return_error } from "../../server/utils.ts";
export const handler: Handlers = {
async DELETE(req, ctx) {
const user = <User | undefined> ctx.state.user;
let form: FormData | undefined;
try {
form = await req.formData();
} catch (_) {
return return_error(400, "Bad Request");
}
const typ = await get_string(form.get("type"));
const token = await get_string(form.get("token"));
if (!token) {
return return_error(2, "token not specfied.");
}
if (typ == "gallery") {
if (
user && !user.is_admin &&
!(Number(user.permissions) & UserPermission.ShareGallery)
) {
return return_error(403, "Permission denied.");
}
const m = get_task_manager();
m.db.delete_shared_token(token);
return return_data(true);
} else {
return return_error(1, "Unknown type");
}
},
GET(_req, ctx) {
const st = <SharedToken | undefined> ctx.state.shared_token;
if (!st) return return_error(1, "No token.");