添加删除分享画廊的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

48
api.yml
View File

@@ -2531,6 +2531,54 @@ paths:
schema:
$ref: "#/components/schemas/ApiResponseTrue"
/shared_token:
delete:
operationId: deleteSharedToken
summary: Delete shared token
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
type:
type: string
enum: [gallery]
description: Shared token type
token:
type: string
description: Token to identify the shared token to delete.
default: ''
required: [token, type]
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/ApiResponseTrue"
"400":
description: Bad request
content:
application/json:
schema:
$ref: "#/components/schemas/ApiResponseError"
example:
{ "ok": false, "status": 1, "error": "token not specfied." }
"401":
description: Authorization information is missing or invalid
content:
application/json:
schema:
$ref: "#/components/schemas/ApiResponseError"
example: { "ok": false, "status": 401, "error": "Unauthorized" }
"403":
description: Permission denied
content:
application/json:
schema:
$ref: "#/components/schemas/ApiResponseError"
example:
{ "ok": false, "status": 403, "error": "Permission denied." }
get:
operationId: getSharedToken
summary: Get information for shared token

3
db.ts
View File

@@ -1046,6 +1046,9 @@ export class EhDb {
if (count === 0 || count === 0n) this.delete_files(token);
}
}
delete_shared_token(token: string) {
this.db.query("DELETE FROM shared_token WHERE token = ?;", [token]);
}
delete_task(task: Task) {
return this.transaction(() => {
this.db.query("DELETE FROM task WHERE id = ?;", [task.id]);

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.");