ework-web 0.10.18 → 0.10.19
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 +32 -32
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1386,6 +1386,38 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
1386
1386
|
}
|
|
1387
1387
|
}
|
|
1388
1388
|
|
|
1389
|
+
const issueLabelsApi = url.pathname.match(API_ISSUE_LABELS_RE);
|
|
1390
|
+
if (issueLabelsApi) {
|
|
1391
|
+
const [, owner, repo, numStr] = issueLabelsApi;
|
|
1392
|
+
if (!(owner && repo && numStr)) return html(errorPage("404", "bad path"), 404);
|
|
1393
|
+
const project = await getProject(owner, repo);
|
|
1394
|
+
if (!project) return json({ error: "project not found" }, 404);
|
|
1395
|
+
const issue = await getIssueWithMeta(project.id, Number(numStr));
|
|
1396
|
+
if (!issue) return json({ error: "issue not found" }, 404);
|
|
1397
|
+
if (req.method === "GET") {
|
|
1398
|
+
const [current, available] = await Promise.all([
|
|
1399
|
+
listLabelsForIssue(issue.id),
|
|
1400
|
+
listLabels(project.id),
|
|
1401
|
+
]);
|
|
1402
|
+
return json({ current, available });
|
|
1403
|
+
}
|
|
1404
|
+
if (req.method === "POST") {
|
|
1405
|
+
if (!ctx.user || !(await canWriteProject(project.id, ctx.user))) {
|
|
1406
|
+
return json({ error: "forbidden: needs writer role on project" }, 403);
|
|
1407
|
+
}
|
|
1408
|
+
const body = await req.json().catch(() => ({}));
|
|
1409
|
+
const labelIds = Array.isArray(body.labelIds) ? body.labelIds.map((n: unknown) => Number(n)).filter((n: number) => Number.isInteger(n) && n > 0) : [];
|
|
1410
|
+
try {
|
|
1411
|
+
await setIssueLabels(issue.id, labelIds);
|
|
1412
|
+
const current = await listLabelsForIssue(issue.id);
|
|
1413
|
+
return json({ current });
|
|
1414
|
+
} catch (e) {
|
|
1415
|
+
return json({ error: errMsg(e) }, e instanceof StoreError ? e.status : 500);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return json({ error: "method not allowed" }, 405);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1389
1421
|
if (req.method === "POST") {
|
|
1390
1422
|
if (!cfg.writesEnabled) return json({ error: "writes disabled" }, 403);
|
|
1391
1423
|
const up = url.pathname.match(UPLOAD_RE);
|
|
@@ -1765,38 +1797,6 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
1765
1797
|
}
|
|
1766
1798
|
}
|
|
1767
1799
|
|
|
1768
|
-
const issueLabelsApi = url.pathname.match(API_ISSUE_LABELS_RE);
|
|
1769
|
-
if (issueLabelsApi) {
|
|
1770
|
-
const [, owner, repo, numStr] = issueLabelsApi;
|
|
1771
|
-
if (!(owner && repo && numStr)) return html(errorPage("404", "bad path"), 404);
|
|
1772
|
-
const project = await getProject(owner, repo);
|
|
1773
|
-
if (!project) return json({ error: "project not found" }, 404);
|
|
1774
|
-
const issue = await getIssueWithMeta(project.id, Number(numStr));
|
|
1775
|
-
if (!issue) return json({ error: "issue not found" }, 404);
|
|
1776
|
-
if (req.method === "GET") {
|
|
1777
|
-
const [current, available] = await Promise.all([
|
|
1778
|
-
listLabelsForIssue(issue.id),
|
|
1779
|
-
listLabels(project.id),
|
|
1780
|
-
]);
|
|
1781
|
-
return json({ current, available });
|
|
1782
|
-
}
|
|
1783
|
-
if (req.method === "POST") {
|
|
1784
|
-
if (!ctx.user || !(await canWriteProject(project.id, ctx.user))) {
|
|
1785
|
-
return json({ error: "forbidden: needs writer role on project" }, 403);
|
|
1786
|
-
}
|
|
1787
|
-
const body = await req.json().catch(() => ({}));
|
|
1788
|
-
const labelIds = Array.isArray(body.labelIds) ? body.labelIds.map((n: unknown) => Number(n)).filter((n: number) => Number.isInteger(n) && n > 0) : [];
|
|
1789
|
-
try {
|
|
1790
|
-
await setIssueLabels(issue.id, labelIds);
|
|
1791
|
-
const current = await listLabelsForIssue(issue.id);
|
|
1792
|
-
return json({ current });
|
|
1793
|
-
} catch (e) {
|
|
1794
|
-
return json({ error: errMsg(e) }, e instanceof StoreError ? e.status : 500);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
return json({ error: "method not allowed" }, 405);
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
1800
|
const isNew = url.pathname.match(REPO_NEW_RE);
|
|
1801
1801
|
if (isNew) {
|
|
1802
1802
|
const [, owner, repo] = isNew;
|