ework-web 0.10.128 → 0.10.129
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 +20 -0
- package/src/static/app.js +17 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -83,6 +83,8 @@ import {
|
|
|
83
83
|
type ProjectRole,
|
|
84
84
|
type UserRow,
|
|
85
85
|
getIssueAiStatusByNumber,
|
|
86
|
+
getIssue,
|
|
87
|
+
getComment,
|
|
86
88
|
} from "./store";
|
|
87
89
|
import { startUpstreamSyncPoller } from "./upstream-sync";
|
|
88
90
|
import {
|
|
@@ -989,6 +991,24 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
989
991
|
}
|
|
990
992
|
}
|
|
991
993
|
|
|
994
|
+
if (req.method === "GET" && url.pathname === "/api/raw") {
|
|
995
|
+
const commentId = Number(url.searchParams.get("comment") ?? "");
|
|
996
|
+
const issueRef = url.searchParams.get("issue") ?? "";
|
|
997
|
+
if (Number.isInteger(commentId) && commentId > 0) {
|
|
998
|
+
const c = await getComment(commentId);
|
|
999
|
+
if (!c) return json({ error: "not found" }, 404);
|
|
1000
|
+
return json({ body: c.body });
|
|
1001
|
+
}
|
|
1002
|
+
const m = issueRef.match(/^([\w.-]+)\/([\w.-]+)\/(\d+)$/);
|
|
1003
|
+
if (m) {
|
|
1004
|
+
const project = await getProject(m[1] ?? "", m[2] ?? "");
|
|
1005
|
+
if (!project) return json({ error: "not found" }, 404);
|
|
1006
|
+
const issue = await getIssue(project.id, Number(m[3] ?? ""));
|
|
1007
|
+
if (!issue) return json({ error: "not found" }, 404);
|
|
1008
|
+
return json({ body: issue.body ?? "" });
|
|
1009
|
+
}
|
|
1010
|
+
return json({ error: "comment or issue required" }, 400);
|
|
1011
|
+
}
|
|
992
1012
|
if (req.method === "POST" && url.pathname === "/api/translate") {
|
|
993
1013
|
if (!rateLimit(`translate:${ip}`, 10, 10 / 60)) return json({ error: "rate limited" }, 429);
|
|
994
1014
|
try {
|
package/src/static/app.js
CHANGED
|
@@ -319,11 +319,27 @@
|
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
// Raw markdown beats innerText as translation source: the rendered DOM has
|
|
323
|
+
// lost fences/emphasis/list markers, so translating it flattens formatting.
|
|
324
|
+
async function rawSource(btn, root) {
|
|
325
|
+
const item = btn.closest(".item");
|
|
326
|
+
if (item && item.dataset.id) {
|
|
327
|
+
const r = await fetch("/api/raw?comment=" + encodeURIComponent(item.dataset.id));
|
|
328
|
+
if (r.ok) return ((await r.json())?.body ?? "").trim();
|
|
329
|
+
}
|
|
330
|
+
const m = location.pathname.match(/^\/([^/]+)\/([^/]+)\/issues\/(\d+)/);
|
|
331
|
+
if (m) {
|
|
332
|
+
const r = await fetch("/api/raw?issue=" + encodeURIComponent(m[1] + "/" + m[2] + "/" + m[3]));
|
|
333
|
+
if (r.ok) return ((await r.json())?.body ?? "").trim();
|
|
334
|
+
}
|
|
335
|
+
return root.innerText.trim();
|
|
336
|
+
}
|
|
337
|
+
|
|
322
338
|
async function doTranslate(btn) {
|
|
323
339
|
const root = actionRoot(btn);
|
|
324
340
|
if (!root) return;
|
|
325
341
|
if (btn.dataset.tr === "1") { btn.dataset.tr = "0"; btn.textContent = "翻译"; root.innerHTML = btn.dataset.orig; return; }
|
|
326
|
-
const text = root
|
|
342
|
+
const text = await rawSource(btn, root);
|
|
327
343
|
if (!text) return;
|
|
328
344
|
if (!btn.dataset.orig) btn.dataset.orig = root.innerHTML;
|
|
329
345
|
btn.textContent = "⏳";
|