mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
feat: Add log deletion API endpoint with filtering options
This commit is contained in:
62
api.yml
62
api.yml
@@ -2603,6 +2603,68 @@ paths:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ApiResponseTrue"
|
||||
/log:
|
||||
delete:
|
||||
operationId: clearLog
|
||||
summary: Clear log
|
||||
parameters:
|
||||
- name: type
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
description: Log type filter
|
||||
- name: min_level
|
||||
in: query
|
||||
schema:
|
||||
$ref: "#/components/schemas/LogLevel"
|
||||
description: Minimum log level filter
|
||||
- name: max_level
|
||||
in: query
|
||||
schema:
|
||||
$ref: "#/components/schemas/LogLevel"
|
||||
description: Maximum log level filter
|
||||
- name: deleted_level
|
||||
in: query
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
description: List of log levels to delete
|
||||
- name: end_time
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
format: date-time
|
||||
description: End time for log deletion
|
||||
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": "Failed to parse end_time." }
|
||||
"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: queryLog
|
||||
summary: Query log
|
||||
|
||||
@@ -1,10 +1,41 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { return_data, return_error } from "../../server/utils.ts";
|
||||
import { User, UserPermission } from "../../db.ts";
|
||||
import { parse_int } from "../../server/parse_form.ts";
|
||||
import { get_string, parse_int } from "../../server/parse_form.ts";
|
||||
import { base_logger, LogLevel } from "../../utils/logger.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async DELETE(req, ctx) {
|
||||
const user = <User | undefined> ctx.state.user;
|
||||
if (
|
||||
user && !user.is_admin &&
|
||||
!(Number(user.permissions) & UserPermission.QueryLog)
|
||||
) {
|
||||
return return_error(403, "Permission denied.");
|
||||
}
|
||||
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 min_level = await parse_int(form.get("min_level"), null);
|
||||
const max_level = await parse_int(form.get("max_level"), null);
|
||||
const deleted_level = (await get_string(form.get("deleted_level")))
|
||||
?.split(",")?.map((x) => parseInt(x))?.filter((x) => !isNaN(x));
|
||||
const end = await get_string(form.get("end_time"));
|
||||
const endt = parseInt(end ?? "");
|
||||
let end_time: Date | null;
|
||||
try {
|
||||
end_time = end === null ? null : new Date(isNaN(endt) ? end : endt);
|
||||
} catch (e) {
|
||||
base_logger.log("Failed to parse end_time:", e);
|
||||
return return_error(1, "Failed to parse end_time.");
|
||||
}
|
||||
base_logger.clear(typ, min_level, max_level, deleted_level, end_time);
|
||||
return return_data(true);
|
||||
},
|
||||
async GET(req, ctx) {
|
||||
const user = <User | undefined> ctx.state.user;
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user