Skip to content

Commit

Permalink
Add new api
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc committed May 26, 2024
1 parent bdc320d commit 0918684
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import * as $api_status from "./routes/api/status.ts";
import * as $api_tag_id_ from "./routes/api/tag/[id].ts";
import * as $api_tag_rows from "./routes/api/tag/rows.ts";
import * as $api_task from "./routes/api/task.ts";
import * as $api_task_download_cfg from "./routes/api/task/download_cfg.ts";
import * as $api_task_export_zip_cfg from "./routes/api/task/export_zip_cfg.ts";
import * as $api_thumbnail_id_ from "./routes/api/thumbnail/[id].ts";
import * as $api_token from "./routes/api/token.ts";
import * as $api_user from "./routes/api/user.ts";
Expand Down Expand Up @@ -62,6 +64,8 @@ const manifest = {
"./routes/api/tag/[id].ts": $api_tag_id_,
"./routes/api/tag/rows.ts": $api_tag_rows,
"./routes/api/task.ts": $api_task,
"./routes/api/task/download_cfg.ts": $api_task_download_cfg,
"./routes/api/task/export_zip_cfg.ts": $api_task_export_zip_cfg,
"./routes/api/thumbnail/[id].ts": $api_thumbnail_id_,
"./routes/api/token.ts": $api_token,
"./routes/api/user.ts": $api_user,
Expand Down
6 changes: 5 additions & 1 deletion routes/api/_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export async function handler(req: Request, ctx: FreshContext) {
"Set-Cookie",
`token=${t.token}; Expires=${t.expired.toUTCString()}${
t.http_only ? "; HttpOnly" : ""
}${t.secure ? "; SameSite=None; Secure" : ""}; Path=/api`,
}${
t.secure
? "; SameSite=None; Secure"
: ""
}; Path=/api`,
);
} catch {
null;
Expand Down
25 changes: 25 additions & 0 deletions routes/api/task/download_cfg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Handlers } from "$fresh/server.ts";
import { User, UserPermission } from "../../../db.ts";
import { get_task_manager } from "../../../server.ts";
import { return_data, return_error } from "../../../server/utils.ts";
import type { DownloadConfig } from "../../../tasks/download.ts";

export const handler: Handlers = {
GET(_req, ctx) {
const user = <User | undefined> ctx.state.user;
if (
user && !user.is_admin &&
!(user.permissions & UserPermission.ManageTasks)
) {
return return_error(403, "Permission denied.");
}
const m = get_task_manager();
return return_data<DownloadConfig>({
download_original_img: m.cfg.download_original_img,
max_download_img_count: m.cfg.max_download_img_count,
max_retry_count: m.cfg.max_retry_count,
mpv: m.cfg.mpv,
remove_previous_gallery: m.cfg.remove_previous_gallery,
});
},
};
21 changes: 21 additions & 0 deletions routes/api/task/export_zip_cfg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Handlers } from "$fresh/server.ts";
import { User, UserPermission } from "../../../db.ts";
import { get_task_manager } from "../../../server.ts";
import { return_data, return_error } from "../../../server/utils.ts";
import type { ExportZipConfig } from "../../../tasks/export_zip.ts";

export const handler: Handlers = {
GET(_req, ctx) {
const user = <User | undefined> ctx.state.user;
if (
user && !user.is_admin &&
!(user.permissions & UserPermission.ManageTasks)
) {
return return_error(403, "Permission denied.");
}
const m = get_task_manager();
return return_data<ExportZipConfig>({
jpn_title: m.cfg.export_zip_jpn_title,
});
},
};

0 comments on commit 0918684

Please sign in to comment.