Merge branch 'master' into dhk-1
This commit is contained in:
commit
85aa242fd5
48 files changed
+1818
-207
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { apiFetch } from "@/core/api";
|
||||
import { getBackendBaseURL } from "@/core/config";
|
||||
import { OptType, writeYLog } from "@/core/log/y-log";
|
||||
|
||||
import type {
|
||||
HtmlPageFavorite,
|
||||
@@ -51,9 +52,17 @@ export async function listScheduledTasks(params: ListScheduledTasksParams = {})
|
||||
if (params.search) qs.set("search", params.search);
|
||||
for (const id of params.tagIds ?? []) qs.append("tag_ids", id);
|
||||
const query = qs.toString();
|
||||
return parseResponse<ScheduledTask[]>(
|
||||
const result = await parseResponse<ScheduledTask[]>(
|
||||
await apiFetch(`${baseUrl()}${query ? `?${query}` : ""}`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.search,
|
||||
optDetail: "B1-CM助手-定时任务-列表",
|
||||
url: `${baseUrl()}${query ? `?${query}` : ""}`,
|
||||
reqParam: params,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function createScheduledTask(data: {
|
||||
@@ -66,13 +75,21 @@ export async function createScheduledTask(data: {
|
||||
require_markdown?: boolean;
|
||||
execution_context?: ScheduledTaskExecutionContext | null;
|
||||
}) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(baseUrl(), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.create,
|
||||
optDetail: "B1-CM助手-定时任务-新建",
|
||||
url: baseUrl(),
|
||||
reqParam: data,
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function listScheduledTaskRuns(taskId: string) {
|
||||
@@ -82,9 +99,17 @@ export async function listScheduledTaskRuns(taskId: string) {
|
||||
}
|
||||
|
||||
export async function getScheduledTaskRun(runId: string) {
|
||||
return parseResponse<ScheduledTaskRun>(
|
||||
const result = await parseResponse<ScheduledTaskRun>(
|
||||
await apiFetch(`${baseUrl()}/runs/${encodeURIComponent(runId)}`),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.view,
|
||||
optDetail: "B1-CM助手-定时任务-运行详情",
|
||||
url: `${baseUrl()}/runs/${encodeURIComponent(runId)}`,
|
||||
reqParam: { runId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteScheduledTaskRun(runId: string) {
|
||||
@@ -228,45 +253,85 @@ export async function updateScheduledTask(
|
||||
execution_context: ScheduledTaskExecutionContext | null;
|
||||
}>,
|
||||
) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(data),
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.edit,
|
||||
optDetail: "B1-CM助手-定时任务-修改",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}`,
|
||||
reqParam: { taskId, data },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function deleteScheduledTask(taskId: string) {
|
||||
return parseResponse<{ success: boolean }>(
|
||||
const result = await parseResponse<{ success: boolean }>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.delete,
|
||||
optDetail: "B1-CM助手-定时任务-删除",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function pauseScheduledTask(taskId: string) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/pause`, {
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.disabled,
|
||||
optDetail: "B1-CM助手-定时任务-暂停",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/pause`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function resumeScheduledTask(taskId: string) {
|
||||
return parseResponse<ScheduledTask>(
|
||||
const result = await parseResponse<ScheduledTask>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/resume`, {
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.enabled,
|
||||
optDetail: "B1-CM助手-定时任务-恢复",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/resume`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function triggerScheduledTask(taskId: string) {
|
||||
return parseResponse<{ success: boolean; task: ScheduledTask }>(
|
||||
const result = await parseResponse<{ success: boolean; task: ScheduledTask }>(
|
||||
await apiFetch(`${baseUrl()}/${encodeURIComponent(taskId)}/trigger`, {
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
writeYLog({
|
||||
optType: OptType.other,
|
||||
optDetail: "B1-CM助手-定时任务-手动运行",
|
||||
url: `${baseUrl()}/${encodeURIComponent(taskId)}/trigger`,
|
||||
reqParam: { taskId },
|
||||
returnParam: result,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function listPublishedScheduledTasks(params: { limit?: number; offset?: number } = {}) {
|
||||
|
||||
@@ -42,6 +42,8 @@ import {
|
||||
type IRunOptions,
|
||||
} from "docx";
|
||||
|
||||
import { OptType, writeYLog } from "@/core/log/y-log";
|
||||
|
||||
const BLACK = "000000";
|
||||
const BODY_FONT = { ascii: "Calibri", eastAsia: "Microsoft YaHei" };
|
||||
const MONO_FONT = { ascii: "Consolas", eastAsia: "Microsoft YaHei" };
|
||||
@@ -484,6 +486,12 @@ export async function downloadMarkdownAsDocx(
|
||||
title?: string,
|
||||
): Promise<void> {
|
||||
const blob = await markdownToDocxBlob(markdown, title);
|
||||
writeYLog({
|
||||
optType: OptType.export,
|
||||
optDetail: "B1-CM助手-定时任务-导出",
|
||||
url: "/scheduled-tasks/export/docx",
|
||||
reqParam: { fileName, title },
|
||||
});
|
||||
const safeName = fileName.replace(/\.(md|markdown)$/i, "") || "document";
|
||||
const url = URL.createObjectURL(blob);
|
||||
const anchor = document.createElement("a");
|
||||
|
||||
Reference in new issue
Block a user