ework-web 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +29 -0
- package/src/remote-file.ts +206 -0
- package/src/views/users.ts +1 -0
- package/src/views/webhookDeliveries.ts +92 -0
- package/src/webhooks.ts +17 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -82,10 +82,13 @@ import {
|
|
|
82
82
|
setWebhookActive,
|
|
83
83
|
getWebhook,
|
|
84
84
|
listDeliveries,
|
|
85
|
+
listAllRecentDeliveries,
|
|
85
86
|
type WebhookEventName,
|
|
86
87
|
} from "./webhooks";
|
|
87
88
|
import { classifyActor, type CommentView } from "./render/components";
|
|
88
89
|
import { buildWebhooksPage } from "./views/webhooks";
|
|
90
|
+
import { buildWebhookDeliveriesPage } from "./views/webhookDeliveries";
|
|
91
|
+
import { browseRemoteFile, proxyFileSince, RemoteFileError } from "./remote-file";
|
|
89
92
|
import { buildProjectMembersPage } from "./views/projectMembers";
|
|
90
93
|
import { buildProjectUpstreamsPage, trySetUpstreamUrls } from "./views/projectUpstreams";
|
|
91
94
|
import { buildProjectModelPage } from "./views/projectModel";
|
|
@@ -597,6 +600,18 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
597
600
|
|
|
598
601
|
if (url.pathname === "/file") {
|
|
599
602
|
const rawPath = url.searchParams.get("path") ?? "";
|
|
603
|
+
const daemonParam = url.searchParams.get("daemon");
|
|
604
|
+
if (daemonParam && !isLocalhost(daemonParam)) {
|
|
605
|
+
try {
|
|
606
|
+
const mode = url.searchParams.get("mode") ?? "tail";
|
|
607
|
+
const order = url.searchParams.get("order") ?? "desc";
|
|
608
|
+
const { html: body } = await browseRemoteFile(daemonParam, rawPath, mode, order, ctx.user?.login);
|
|
609
|
+
return html(body);
|
|
610
|
+
} catch (e) {
|
|
611
|
+
const status = e instanceof RemoteFileError ? e.status : 500;
|
|
612
|
+
return html(errorPage(status === 404 ? "文件不存在" : "远程访问失败", errMsg(e)), status);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
600
615
|
const mode = url.searchParams.get("mode") ?? undefined;
|
|
601
616
|
const order = url.searchParams.get("order") ?? undefined;
|
|
602
617
|
try {
|
|
@@ -626,6 +641,15 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
626
641
|
const rawPath = url.searchParams.get("path") ?? "";
|
|
627
642
|
const after = Number(url.searchParams.get("after") ?? "0");
|
|
628
643
|
if (!Number.isFinite(after) || after < 0) return json({ error: "bad after" }, 400);
|
|
644
|
+
const daemonParam = url.searchParams.get("daemon");
|
|
645
|
+
if (daemonParam && !isLocalhost(daemonParam)) {
|
|
646
|
+
try {
|
|
647
|
+
return json(await proxyFileSince(daemonParam, rawPath, after));
|
|
648
|
+
} catch (e) {
|
|
649
|
+
const status = e instanceof RemoteFileError ? e.status : 500;
|
|
650
|
+
return json({ error: errMsg(e) }, status);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
629
653
|
try {
|
|
630
654
|
const delta = readFileSince(cfg, rawPath, after);
|
|
631
655
|
return json(delta);
|
|
@@ -939,6 +963,11 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
939
963
|
return html(buildAdminTokensPage(ctx.user!, await listAllPatsWithUsers(), flash));
|
|
940
964
|
}
|
|
941
965
|
|
|
966
|
+
if (url.pathname === "/admin/deliveries") {
|
|
967
|
+
const deliveries = await listAllRecentDeliveries(100);
|
|
968
|
+
return html(buildWebhookDeliveriesPage(ctx.user!, deliveries));
|
|
969
|
+
}
|
|
970
|
+
|
|
942
971
|
const adminPatRevoke = url.pathname.match(/^\/admin\/tokens\/(\d+)\/revoke$/);
|
|
943
972
|
if (adminPatRevoke && req.method === "POST") {
|
|
944
973
|
const id = Number(adminPatRevoke[1]);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { THEME_CSS, escapeHtml, tabNavHTML } from "./render/layout";
|
|
2
|
+
|
|
3
|
+
export class RemoteFileError extends Error {
|
|
4
|
+
status: number;
|
|
5
|
+
constructor(message: string, status: number) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "RemoteFileError";
|
|
8
|
+
this.status = status;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DirEntry {
|
|
13
|
+
name: string;
|
|
14
|
+
isDir: boolean;
|
|
15
|
+
size: number;
|
|
16
|
+
mtime: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface DirListing {
|
|
20
|
+
path: string;
|
|
21
|
+
entries: DirEntry[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface FileContent {
|
|
25
|
+
path: string;
|
|
26
|
+
size: number;
|
|
27
|
+
rows: { n: number; t: string }[];
|
|
28
|
+
mode: string;
|
|
29
|
+
byteCapped: boolean;
|
|
30
|
+
note: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function fmtSize(n: number): string {
|
|
34
|
+
if (n < 1024) return `${n}B`;
|
|
35
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)}KB`;
|
|
36
|
+
return `${(n / (1024 * 1024)).toFixed(1)}MB`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function fmtMtime(ms: number): string {
|
|
40
|
+
if (!ms) return "";
|
|
41
|
+
const diff = Date.now() - ms;
|
|
42
|
+
if (diff < 60000) return "刚刚";
|
|
43
|
+
if (diff < 3600000) return `${Math.floor(diff / 60000)}分前`;
|
|
44
|
+
if (diff < 86400000) return `${Math.floor(diff / 3600000)}时前`;
|
|
45
|
+
return new Date(ms).toISOString().slice(5, 16);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function fetchDaemon(
|
|
49
|
+
endpoint: string,
|
|
50
|
+
apiPath: string,
|
|
51
|
+
params: Record<string, string>
|
|
52
|
+
): Promise<Response> {
|
|
53
|
+
const url = new URL(`${endpoint}${apiPath}`);
|
|
54
|
+
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
55
|
+
const resp = await fetch(url.toString(), { signal: AbortSignal.timeout(10_000) });
|
|
56
|
+
return resp;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function browseRemoteFile(
|
|
60
|
+
endpoint: string,
|
|
61
|
+
rawPath: string,
|
|
62
|
+
mode: string,
|
|
63
|
+
order: string,
|
|
64
|
+
viewerLogin?: string
|
|
65
|
+
): Promise<{ html: string }> {
|
|
66
|
+
const daemonLabel = escapeHtml(endpoint);
|
|
67
|
+
|
|
68
|
+
const listResp = await fetchDaemon(endpoint, "/api/files/list", { path: rawPath });
|
|
69
|
+
if (listResp.ok) {
|
|
70
|
+
const data = (await listResp.json()) as DirListing;
|
|
71
|
+
return { html: renderDirListing(data, endpoint, daemonLabel, viewerLogin) };
|
|
72
|
+
}
|
|
73
|
+
if (listResp.status !== 400) {
|
|
74
|
+
const err = await listResp.json().catch(() => ({ error: "unknown" })) as { error?: string };
|
|
75
|
+
throw new RemoteFileError(err.error ?? `daemon returned ${listResp.status}`, listResp.status);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const readResp = await fetchDaemon(endpoint, "/api/files/read", {
|
|
79
|
+
path: rawPath,
|
|
80
|
+
mode: mode === "head" ? "head" : "tail",
|
|
81
|
+
order: order === "asc" ? "asc" : "desc",
|
|
82
|
+
});
|
|
83
|
+
if (!readResp.ok) {
|
|
84
|
+
const err = await readResp.json().catch(() => ({ error: "unknown" })) as { error?: string };
|
|
85
|
+
throw new RemoteFileError(err.error ?? `daemon returned ${readResp.status}`, readResp.status);
|
|
86
|
+
}
|
|
87
|
+
const data = (await readResp.json()) as FileContent;
|
|
88
|
+
return { html: renderFileContent(data, endpoint, daemonLabel, viewerLogin) };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function renderDirListing(
|
|
92
|
+
data: DirListing,
|
|
93
|
+
endpoint: string,
|
|
94
|
+
daemonLabel: string,
|
|
95
|
+
viewerLogin?: string
|
|
96
|
+
): string {
|
|
97
|
+
const enc = encodeURIComponent;
|
|
98
|
+
const daemonParam = `&daemon=${enc(endpoint)}`;
|
|
99
|
+
const parentPath = data.path.split("/").slice(0, -1).join("/") || "/";
|
|
100
|
+
const rows = data.entries.map((e) => {
|
|
101
|
+
const childPath = `${data.path.replace(/\/$/, "")}/${e.name}`;
|
|
102
|
+
const icon = e.isDir ? "📁" : "📄";
|
|
103
|
+
const size = e.isDir ? "—" : fmtSize(e.size);
|
|
104
|
+
return `<tr>
|
|
105
|
+
<td><a href="/file?path=${enc(childPath)}${daemonParam}">${icon} ${escapeHtml(e.name)}</a></td>
|
|
106
|
+
<td class="ms">${size}</td>
|
|
107
|
+
<td class="ts">${fmtMtime(e.mtime)}</td>
|
|
108
|
+
</tr>`;
|
|
109
|
+
}).join("") || `<tr><td colspan="3" class="empty">空目录</td></tr>`;
|
|
110
|
+
|
|
111
|
+
const user = viewerLogin ? { login: viewerLogin, is_admin: 0 } : undefined;
|
|
112
|
+
return `<!doctype html>
|
|
113
|
+
<html lang="zh"><head><meta charset="utf-8">
|
|
114
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
115
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
116
|
+
<title>ework-web · ${escapeHtml(data.path)}</title>
|
|
117
|
+
<style>${THEME_CSS}
|
|
118
|
+
.nav{display:flex;align-items:center;gap:.5rem;padding:.55rem 1rem;background:var(--header-bg);color:var(--header-text);font-size:13px}
|
|
119
|
+
.nav a{color:var(--header-text);opacity:.95}
|
|
120
|
+
.wrap{max-width:900px;margin:0 auto;padding:1rem}
|
|
121
|
+
h1{font-size:15px;margin:0 0 .3rem;font-family:ui-monospace,monospace;word-break:break-all}
|
|
122
|
+
.remote-badge{display:inline-block;background:#1f6feb33;color:#58a6ff;padding:2px 8px;border-radius:10px;font-size:11px;font-weight:600;margin-left:.5rem}
|
|
123
|
+
.dtable{width:100%;border-collapse:collapse;font-size:13px;margin-top:.6rem}
|
|
124
|
+
.dtable th,.dtable td{border:1px solid var(--border);padding:.3rem .5rem;text-align:left}
|
|
125
|
+
.dtable th{background:var(--bg);color:var(--text-muted);font-weight:600}
|
|
126
|
+
.dtable a{color:var(--accent);text-decoration:none}
|
|
127
|
+
.dtable a:hover{text-decoration:underline}
|
|
128
|
+
.dtable .ms,.dtable .ts{color:var(--text-muted);white-space:nowrap;font-size:12px}
|
|
129
|
+
.empty{color:var(--text-muted);text-align:center;padding:.6rem}
|
|
130
|
+
.parent-link{font-size:13px;margin-bottom:.4rem}
|
|
131
|
+
.parent-link a{color:var(--text-muted)}
|
|
132
|
+
.tabs{display:flex;gap:.3rem;padding:.5rem 1rem;border-bottom:1px solid var(--border);font-size:13px}
|
|
133
|
+
.tab{padding:.3rem .7rem;border-radius:6px 6px 0 0;text-decoration:none;color:var(--text-muted)}
|
|
134
|
+
.tab.active{background:var(--accent);color:#fff}
|
|
135
|
+
</style></head><body>
|
|
136
|
+
<header class="nav"><a href="/" style="color:var(--header-text)">🏠 ework-web</a></header>
|
|
137
|
+
${tabNavHTML("sessions", user)}
|
|
138
|
+
<main class="wrap">
|
|
139
|
+
<div class="parent-link">📁 <a href="/file?path=${enc(parentPath)}${daemonParam}">..</a></div>
|
|
140
|
+
<h1>${escapeHtml(data.path)}<span class="remote-badge">远程 ${daemonLabel}</span></h1>
|
|
141
|
+
<table class="dtable"><thead><tr>
|
|
142
|
+
<th>名称</th><th>大小</th><th>修改时间</th>
|
|
143
|
+
</tr></thead><tbody>${rows}</tbody></table>
|
|
144
|
+
</main></body></html>`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function renderFileContent(
|
|
148
|
+
data: FileContent,
|
|
149
|
+
endpoint: string,
|
|
150
|
+
daemonLabel: string,
|
|
151
|
+
viewerLogin?: string
|
|
152
|
+
): string {
|
|
153
|
+
const enc = encodeURIComponent;
|
|
154
|
+
const daemonParam = `&daemon=${enc(endpoint)}`;
|
|
155
|
+
const user = viewerLogin ? { login: viewerLogin, is_admin: 0 } : undefined;
|
|
156
|
+
const lines = data.rows.map((r) =>
|
|
157
|
+
`<div class="l"><span class="ln">${r.n}</span><span class="lt">${escapeHtml(r.t)}</span></div>`
|
|
158
|
+
).join("");
|
|
159
|
+
|
|
160
|
+
return `<!doctype html>
|
|
161
|
+
<html lang="zh"><head><meta charset="utf-8">
|
|
162
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
163
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
164
|
+
<title>ework-web · ${escapeHtml(data.path)}</title>
|
|
165
|
+
<style>${THEME_CSS}
|
|
166
|
+
.nav{display:flex;align-items:center;gap:.5rem;padding:.55rem 1rem;background:var(--header-bg);color:var(--header-text);font-size:13px}
|
|
167
|
+
.nav a{color:var(--header-text);opacity:.95}
|
|
168
|
+
.wrap{max-width:1000px;margin:0 auto;padding:1rem}
|
|
169
|
+
h1{font-size:14px;margin:0 0 .3rem;font-family:ui-monospace,monospace;word-break:break-all}
|
|
170
|
+
.remote-badge{display:inline-block;background:#1f6feb33;color:#58a6ff;padding:2px 8px;border-radius:10px;font-size:11px;font-weight:600;margin-left:.5rem}
|
|
171
|
+
.note{color:var(--text-muted);font-size:12px;margin:0 0 .5rem}
|
|
172
|
+
.parent-link{font-size:13px;margin-bottom:.4rem}
|
|
173
|
+
.parent-link a{color:var(--text-muted)}
|
|
174
|
+
.fview{background:var(--bg-elev);border:1px solid var(--border);border-radius:6px;overflow:auto;max-height:80vh;font-size:12.5px;font-family:ui-monospace,monospace}
|
|
175
|
+
.l{display:flex}
|
|
176
|
+
.ln{color:var(--text-muted);min-width:3.5rem;text-align:right;padding:0 .5rem;user-select:none;border-right:1px solid var(--border)}
|
|
177
|
+
.lt{padding:0 .5rem;white-space:pre-wrap;word-break:break-all;flex:1}
|
|
178
|
+
.tabs{display:flex;gap:.3rem;padding:.5rem 1rem;border-bottom:1px solid var(--border);font-size:13px}
|
|
179
|
+
.tab{padding:.3rem .7rem;border-radius:6px 6px 0 0;text-decoration:none;color:var(--text-muted)}
|
|
180
|
+
.tab.active{background:var(--accent);color:#fff}
|
|
181
|
+
</style></head><body>
|
|
182
|
+
<header class="nav"><a href="/" style="color:var(--header-text)">🏠 ework-web</a></header>
|
|
183
|
+
${tabNavHTML("sessions", user)}
|
|
184
|
+
<main class="wrap">
|
|
185
|
+
<div class="parent-link">📁 <a href="/file?path=${enc(data.path.split("/").slice(0, -1).join("/") || "/")}${daemonParam}">..</a></div>
|
|
186
|
+
<h1>${escapeHtml(data.path)}<span class="remote-badge">远程 ${daemonLabel}</span></h1>
|
|
187
|
+
${data.note ? `<p class="note">${escapeHtml(data.note)}</p>` : ""}
|
|
188
|
+
<div class="fview">${lines}</div>
|
|
189
|
+
</main></body></html>`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function proxyFileSince(
|
|
193
|
+
endpoint: string,
|
|
194
|
+
rawPath: string,
|
|
195
|
+
after: number
|
|
196
|
+
): Promise<{ rows: { n: number; t: string }[]; size: number; rotated: boolean; capped: boolean }> {
|
|
197
|
+
const resp = await fetchDaemon(endpoint, "/api/files/since", {
|
|
198
|
+
path: rawPath,
|
|
199
|
+
after: String(after),
|
|
200
|
+
});
|
|
201
|
+
if (!resp.ok) {
|
|
202
|
+
const err = await resp.json().catch(() => ({ error: "unknown" })) as { error?: string };
|
|
203
|
+
throw new RemoteFileError(err.error ?? `daemon returned ${resp.status}`, resp.status);
|
|
204
|
+
}
|
|
205
|
+
return await resp.json();
|
|
206
|
+
}
|
package/src/views/users.ts
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type DeliveryWithWebhookRow } from "../webhooks";
|
|
2
|
+
import { type UserRow } from "../store";
|
|
3
|
+
import { THEME_CSS, escapeHtml, escapeAttr, tabNavHTML } from "../render/layout";
|
|
4
|
+
|
|
5
|
+
function statusClass(status: number | null): string {
|
|
6
|
+
if (status === null) return "err";
|
|
7
|
+
if (status >= 200 && status < 300) return "ok";
|
|
8
|
+
if (status >= 400 && status < 500) return "warn";
|
|
9
|
+
return "err";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function deliveryRowHtml(d: DeliveryWithWebhookRow): string {
|
|
13
|
+
const status = d.response_status === null ? "—" : String(d.response_status);
|
|
14
|
+
const cls = statusClass(d.response_status);
|
|
15
|
+
const project = d.project_owner
|
|
16
|
+
? `<a href="/${escapeAttr(d.project_owner)}/${escapeAttr(d.project_name ?? "")}">${escapeHtml(d.project_owner + "/" + (d.project_name ?? ""))}</a>`
|
|
17
|
+
: "<em>(deleted)</em>";
|
|
18
|
+
const url = d.webhook_url ? `<code class="url">${escapeHtml(d.webhook_url)}</code>` : "<em>(deleted)</em>";
|
|
19
|
+
const err = d.error ? `<div class="derr">${escapeHtml(d.error)}</div>` : "";
|
|
20
|
+
const body = d.response_body
|
|
21
|
+
? `<details class="dbody"><summary>响应</summary><pre>${escapeHtml(d.response_body)}</pre></details>`
|
|
22
|
+
: "";
|
|
23
|
+
const payload = `<details class="dpl"><summary>payload</summary><pre>${escapeHtml(d.payload)}</pre></details>`;
|
|
24
|
+
return `<tr>
|
|
25
|
+
<td class="ts">${escapeHtml(d.created_at)}</td>
|
|
26
|
+
<td class="proj">${project}</td>
|
|
27
|
+
<td class="ev">${escapeHtml(d.event)}</td>
|
|
28
|
+
<td class="url">${url}</td>
|
|
29
|
+
<td class="st ${cls}">${status}</td>
|
|
30
|
+
<td class="ms">${d.duration_ms === null ? "—" : d.duration_ms + "ms"}</td>
|
|
31
|
+
<td class="act">${payload}${body}${err}</td>
|
|
32
|
+
</tr>`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildWebhookDeliveriesPage(viewer: UserRow, deliveries: DeliveryWithWebhookRow[]): string {
|
|
36
|
+
const rows = deliveries.length > 0
|
|
37
|
+
? deliveries.map(deliveryRowHtml).join("")
|
|
38
|
+
: `<tr><td colspan="7" class="empty">暂无投递记录</td></tr>`;
|
|
39
|
+
|
|
40
|
+
const ok = deliveries.filter((d) => d.response_status !== null && d.response_status >= 200 && d.response_status < 300).length;
|
|
41
|
+
const fail = deliveries.filter((d) => d.response_status === null || d.response_status >= 400).length;
|
|
42
|
+
const summary = deliveries.length > 0
|
|
43
|
+
? `<div class="summary"><span class="badge ok">${ok} 成功</span> <span class="badge ${fail > 0 ? "err" : ""}">${fail} 失败</span> <span class="muted">最近 ${deliveries.length} 条</span></div>`
|
|
44
|
+
: "";
|
|
45
|
+
|
|
46
|
+
return `<!doctype html>
|
|
47
|
+
<html lang="zh"><head><meta charset="utf-8">
|
|
48
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
49
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
50
|
+
<title>ework-web · Webhook 投递记录</title>
|
|
51
|
+
<style>${THEME_CSS}
|
|
52
|
+
.nav{display:flex;align-items:center;gap:.5rem;padding:.55rem 1rem;background:var(--header-bg);color:var(--header-text);font-size:13px}
|
|
53
|
+
.nav a{color:var(--header-text);opacity:.95}
|
|
54
|
+
.wrap{max-width:1100px;margin:0 auto;padding:1rem}
|
|
55
|
+
h1{font-size:18px;margin:0 0 .3rem}
|
|
56
|
+
.hint{color:var(--text-muted);font-size:13px;margin:0 0 1rem}
|
|
57
|
+
.summary{margin-bottom:.8rem;display:flex;gap:.5rem;align-items:center}
|
|
58
|
+
.badge{padding:2px 8px;border-radius:10px;font-size:12px;font-weight:600}
|
|
59
|
+
.badge.ok{background:#3fb95033;color:#3fb950}
|
|
60
|
+
.badge.err{background:#f8514933;color:#f85149}
|
|
61
|
+
.muted{color:var(--text-muted);font-size:12px}
|
|
62
|
+
.dtable{width:100%;border-collapse:collapse;font-size:12px}
|
|
63
|
+
.dtable th,.dtable td{border:1px solid var(--border);padding:.3rem .4rem;text-align:left;vertical-align:top}
|
|
64
|
+
.dtable th{background:var(--bg);color:var(--text-muted);font-weight:600;position:sticky;top:0}
|
|
65
|
+
.dtable .ts{white-space:nowrap;font-family:ui-monospace,monospace}
|
|
66
|
+
.dtable .proj{white-space:nowrap}
|
|
67
|
+
.dtable .proj a{color:var(--accent)}
|
|
68
|
+
.dtable .ev{white-space:nowrap;font-family:ui-monospace,monospace}
|
|
69
|
+
.dtable .url{max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
70
|
+
.dtable .url code{font-family:ui-monospace,monospace;font-size:11px;color:var(--text-muted)}
|
|
71
|
+
.dtable .st.ok{color:#3fb950;font-weight:600}
|
|
72
|
+
.dtable .st.warn{color:#d29922;font-weight:600}
|
|
73
|
+
.dtable .st.err{color:#f85149;font-weight:600}
|
|
74
|
+
.dtable .ms{color:var(--text-muted);white-space:nowrap}
|
|
75
|
+
.dbody pre,.dpl pre{font-size:11px;max-height:240px;overflow:auto;background:var(--bg);padding:.4rem;border-radius:5px;border:1px solid var(--border);white-space:pre-wrap;word-break:break-all}
|
|
76
|
+
.derr{color:#f85149;font-size:11px;margin-top:.2rem}
|
|
77
|
+
.empty{color:var(--text-muted);text-align:center;padding:.6rem}
|
|
78
|
+
.tabs{display:flex;gap:.3rem;padding:.5rem 1rem;border-bottom:1px solid var(--border);font-size:13px}
|
|
79
|
+
.tab{padding:.3rem .7rem;border-radius:6px 6px 0 0;text-decoration:none;color:var(--text-muted)}
|
|
80
|
+
.tab.active{background:var(--accent);color:#fff}
|
|
81
|
+
</style></head><body>
|
|
82
|
+
<header class="nav"><a href="/" style="color:var(--header-text)">🏠 ework-web</a></header>
|
|
83
|
+
${tabNavHTML("projects", viewer)}
|
|
84
|
+
<main class="wrap">
|
|
85
|
+
<h1>Webhook 投递记录</h1>
|
|
86
|
+
<p class="hint">所有项目的 webhook 投递历史。用于排查 "AI 没回应" 类问题 — 如果投递失败(红色状态码),daemon 根本没收到事件。</p>
|
|
87
|
+
${summary}
|
|
88
|
+
<table class="dtable"><thead><tr>
|
|
89
|
+
<th>时间</th><th>项目</th><th>事件</th><th>目标 URL</th><th>状态</th><th>耗时</th><th>详情</th>
|
|
90
|
+
</tr></thead><tbody>${rows}</tbody></table>
|
|
91
|
+
</main></body></html>`;
|
|
92
|
+
}
|
package/src/webhooks.ts
CHANGED
|
@@ -177,6 +177,23 @@ export async function listDeliveries(webhookId: number, limit = 50): Promise<Web
|
|
|
177
177
|
);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
export interface DeliveryWithWebhookRow extends WebhookDeliveryRow {
|
|
181
|
+
webhook_url: string;
|
|
182
|
+
project_owner: string;
|
|
183
|
+
project_name: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function listAllRecentDeliveries(limit = 100): Promise<DeliveryWithWebhookRow[]> {
|
|
187
|
+
return await getDB().all<DeliveryWithWebhookRow>(
|
|
188
|
+
`SELECT d.*, w.url AS webhook_url, p.owner AS project_owner, p.name AS project_name
|
|
189
|
+
FROM {{webhook_deliveries}} d
|
|
190
|
+
LEFT JOIN {{webhooks}} w ON w.id = d.webhook_id
|
|
191
|
+
LEFT JOIN {{projects}} p ON p.id = w.project_id
|
|
192
|
+
ORDER BY d.id DESC LIMIT ?`,
|
|
193
|
+
[limit]
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
180
197
|
// ─── Payload builders (Gitea-compatible shape) ───────────────
|
|
181
198
|
//
|
|
182
199
|
// We populate the fields downstream consumers actually read (see Gitea's
|