@hazem3500/palette 0.9.130 → 0.9.132
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/README.md +10 -6
- package/dist/adapters/css-variables.js +1 -1
- package/dist/adapters/tailwind.d.ts +1 -1
- package/dist/adapters/tailwind.js +1 -1
- package/dist/chunk-DQPAVGRB.js +1 -0
- package/dist/{chunk-UUV356RI.js → chunk-KMRWUNT7.js} +1 -1
- package/dist/{chunk-RAAJF54I.js → chunk-OAGWNW4W.js} +1 -1
- package/dist/chunk-UVWLXKWZ.js +1 -0
- package/dist/{color-editor-I5ELNYPO.js → color-editor-GCCLM3TV.js} +1 -1
- package/dist/design-comment-LHFSWNU7.js +1 -0
- package/dist/{design-export-55QSPEWM.js → design-export-I766FRDX.js} +1 -1
- package/dist/{design-geometry-OXGWR5J2.js → design-geometry-W7PSW5J2.js} +1 -1
- package/dist/design-mode.js +1 -1
- package/dist/design-system.d.ts +1 -1
- package/dist/frame-size-E6OGNHNX.js +1 -0
- package/dist/frame-size.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{inline-text-editor-S4LVCKZL.js → inline-text-editor-5JSAHEHE.js} +1 -1
- package/dist/message-links.d.ts +2 -0
- package/dist/node.mjs +175 -44
- package/dist/open-state.d.ts +7 -0
- package/dist/postgres/010_project_bot_tokens.sql +10 -0
- package/dist/postgres/011_comment_api_key_name.sql +1 -0
- package/dist/postgres/012_comment_images.sql +25 -0
- package/dist/react-props-panel-P47YFFSU.js +1 -0
- package/dist/react-props-panel.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/server.js +171 -43
- package/dist/setup.js +1 -1
- package/dist/snapshot-TUAELSKH.js +1 -0
- package/dist/snapshot-annotate-T3XC5ENZ.js +1 -0
- package/dist/snapshot-annotate.d.ts +16 -0
- package/dist/snapshot.d.ts +15 -4
- package/dist/thread-snapshot-2V4AV3UN.js +1 -0
- package/dist/thread-snapshot.d.ts +4 -6
- package/dist/token-adapter.d.ts +1 -0
- package/dist/{token-custom-7MJFPGVB.js → token-custom-CPPHGYMJ.js} +1 -1
- package/dist/{token-page-YQ52JS6G.js → token-page-63C3T4DY.js} +1 -1
- package/dist/{token-picker-HHT4OC3V.js → token-picker-ARVCFUCY.js} +1 -1
- package/dist/types.d.ts +4 -0
- package/package.json +2 -1
- package/server/bot-tokens.ts +42 -0
- package/server/index.ts +90 -22
- package/server/migrations/0024_project_bot_tokens.sql +10 -0
- package/server/migrations/0025_comment_api_key_name.sql +1 -0
- package/server/migrations/0026_comment_images.sql +22 -0
- package/server/project-management.ts +17 -0
- package/server/setup-client.txt +115 -79
- package/server/snapshots.ts +2 -1
- package/server/tokens.ts +2 -2
- package/server/webhooks.ts +5 -1
- package/src/types.ts +4 -0
- package/dist/chunk-EVRPBA4F.js +0 -1
- package/dist/design-comment-VXRH45UI.js +0 -1
- package/dist/frame-size-EAVSR4SA.js +0 -1
- package/dist/react-props-panel-VON2NO7N.js +0 -1
- package/dist/snapshot-BFHCCGOL.js +0 -1
- package/dist/thread-snapshot-TJHRZZOR.js +0 -1
- /package/dist/{design-panel-DBAUVCIJ.js → design-panel-GU2SWV33.js} +0 -0
package/server/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { authenticateBotToken, isBotToken } from "./bot-tokens";
|
|
1
2
|
import { projectSites, saveProjectSites } from "./project-sites";
|
|
2
3
|
import {
|
|
3
4
|
manageProject,
|
|
@@ -94,6 +95,7 @@ type CommentRow = {
|
|
|
94
95
|
verified: number;
|
|
95
96
|
created_at: number;
|
|
96
97
|
edited_at: number | null;
|
|
98
|
+
api_key_name?: string | null;
|
|
97
99
|
};
|
|
98
100
|
const identity = (row: UserRow): Identity => ({
|
|
99
101
|
id: row.id,
|
|
@@ -110,7 +112,7 @@ function webhookEvent(
|
|
|
110
112
|
threadId: string,
|
|
111
113
|
page: string,
|
|
112
114
|
anchor: string,
|
|
113
|
-
author:
|
|
115
|
+
author: Identity,
|
|
114
116
|
body: string | null,
|
|
115
117
|
origin: string
|
|
116
118
|
): WebhookEvent {
|
|
@@ -130,7 +132,8 @@ function webhookEvent(
|
|
|
130
132
|
threadId,
|
|
131
133
|
pageUrl: new URL(page, origin).toString(),
|
|
132
134
|
selector,
|
|
133
|
-
author,
|
|
135
|
+
author: author.name,
|
|
136
|
+
authorId: author.id,
|
|
134
137
|
body,
|
|
135
138
|
};
|
|
136
139
|
}
|
|
@@ -179,6 +182,8 @@ async function body(request: Request): Promise<Record<string, unknown>> {
|
|
|
179
182
|
? ["user"]
|
|
180
183
|
: path === "/project/sites"
|
|
181
184
|
? ["sites"]
|
|
185
|
+
: path === "/project/bots"
|
|
186
|
+
? ["name"]
|
|
182
187
|
: path === "/project/webhook"
|
|
183
188
|
? ["url", "secret", "events", "enabled"]
|
|
184
189
|
: ["access", "confirm", "threadIds"]
|
|
@@ -302,21 +307,21 @@ async function authenticate(
|
|
|
302
307
|
env: Env,
|
|
303
308
|
project: string,
|
|
304
309
|
access?: PatAccess
|
|
305
|
-
): Promise<Identity> {
|
|
310
|
+
): Promise<Identity & { apiKeyName?: string }> {
|
|
306
311
|
const bearer = request.headers
|
|
307
312
|
.get("Authorization")
|
|
308
313
|
?.match(/^Bearer (.{1,200})$/)?.[1];
|
|
309
314
|
check(bearer, 401, "Enter your name to comment.");
|
|
310
315
|
const { proxy, proxyAccessTokens, sessionMaxAge, allowGuests } = authOptions(env);
|
|
316
|
+
if (isBotToken(bearer)) return identity(await authenticateBotToken(env, bearer, project, access, request));
|
|
311
317
|
if (isPersonalToken(bearer)) {
|
|
312
318
|
check(
|
|
313
319
|
!proxy || proxyAccessTokens,
|
|
314
320
|
403,
|
|
315
321
|
"Access tokens are off behind the sign-in proxy. Use /auth/proxy/session."
|
|
316
322
|
);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
);
|
|
323
|
+
const actor = await authenticateToken(env, bearer, project, access, request);
|
|
324
|
+
return { ...identity(actor), apiKeyName: actor.tokenName };
|
|
320
325
|
}
|
|
321
326
|
const now = Date.now();
|
|
322
327
|
let row: UserRow | null;
|
|
@@ -1012,7 +1017,7 @@ async function route(
|
|
|
1012
1017
|
"Unknown management route."
|
|
1013
1018
|
);
|
|
1014
1019
|
check(
|
|
1015
|
-
["GET", "POST", "PATCH", "DELETE"].includes(request.method),
|
|
1020
|
+
["GET", "POST", "PUT", "PATCH", "DELETE"].includes(request.method),
|
|
1016
1021
|
405,
|
|
1017
1022
|
"Method not allowed."
|
|
1018
1023
|
);
|
|
@@ -1196,6 +1201,7 @@ async function route(
|
|
|
1196
1201
|
// Element snapshots are opt-in on the client; guests need project consent.
|
|
1197
1202
|
// Clients may send `share` on new threads and edit `/me/settings`.
|
|
1198
1203
|
share: true,
|
|
1204
|
+
commentImages: true,
|
|
1199
1205
|
snapshots: {
|
|
1200
1206
|
readiness: true,
|
|
1201
1207
|
guests: auth.allowGuests && config.allowGuestSnapshots === true,
|
|
@@ -1515,6 +1521,15 @@ async function route(
|
|
|
1515
1521
|
`${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/threads/${item.thread_id}/snapshot/${item.kind}?${scope}`;
|
|
1516
1522
|
snapshotsByThread.set(item.thread_id, group);
|
|
1517
1523
|
}
|
|
1524
|
+
const imagesByComment = new Map<string, number>();
|
|
1525
|
+
try {
|
|
1526
|
+
const images = await env.DB.prepare(
|
|
1527
|
+
`SELECT i.comment_id,i.created_at FROM comment_images i JOIN comments c ON c.id=i.comment_id WHERE c.thread_id IN (${placeholders})`
|
|
1528
|
+
).bind(...ids).all<{ comment_id: string; created_at: number }>();
|
|
1529
|
+
for (const image of images.results) imagesByComment.set(image.comment_id, image.created_at);
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
if (!(error instanceof Error) || !/no such table: comment_images|relation "comment_images" does not exist/.test(error.message)) throw error;
|
|
1532
|
+
}
|
|
1518
1533
|
const commentsByThread = new Map<string, CommentRow[]>();
|
|
1519
1534
|
for (const comment of comments.results) {
|
|
1520
1535
|
const group = commentsByThread.get(comment.thread_id) ?? [];
|
|
@@ -1557,6 +1572,10 @@ async function route(
|
|
|
1557
1572
|
avatarUrl: c.avatar_url || undefined,
|
|
1558
1573
|
accentColor: c.accent_color || undefined,
|
|
1559
1574
|
},
|
|
1575
|
+
...(c.api_key_name ? { apiKeyName: c.api_key_name } : {}),
|
|
1576
|
+
...(imagesByComment.has(c.id) ? {
|
|
1577
|
+
image: `${url.origin}${env.PALETTE_PUBLIC_PATH ?? ""}/threads/${c.thread_id}/comments/${c.id}/image?${new URLSearchParams({ project, repo, branch, v: String(imagesByComment.get(c.id)) })}`,
|
|
1578
|
+
} : {}),
|
|
1560
1579
|
createdAt: c.created_at,
|
|
1561
1580
|
editedAt: c.edited_at,
|
|
1562
1581
|
reactions: reactionsByComment.get(c.id) ?? {},
|
|
@@ -1587,7 +1606,7 @@ async function route(
|
|
|
1587
1606
|
revision,
|
|
1588
1607
|
});
|
|
1589
1608
|
}
|
|
1590
|
-
const user = await authenticate(request, env, project, access);
|
|
1609
|
+
const { apiKeyName, ...user } = await authenticate(request, env, project, access);
|
|
1591
1610
|
await limit(env, `${project}:session:${user.id}`, 60);
|
|
1592
1611
|
const now = Date.now();
|
|
1593
1612
|
if (url.pathname === "/threads" && request.method === "POST") {
|
|
@@ -1616,9 +1635,13 @@ async function route(
|
|
|
1616
1635
|
: env.DB.prepare(
|
|
1617
1636
|
"INSERT INTO threads(id,project,repo,branch,page,anchor,tags,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,?)"
|
|
1618
1637
|
).bind(id, project, repo, branch, page, JSON.stringify(anchor), JSON.stringify(tags), now, now),
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1638
|
+
apiKeyName
|
|
1639
|
+
? env.DB.prepare(
|
|
1640
|
+
"INSERT INTO comments(id,thread_id,user_id,body,created_at,api_key_name) VALUES(?,?,?,?,?,?)"
|
|
1641
|
+
).bind(firstCommentId, id, user.id, text, now, apiKeyName)
|
|
1642
|
+
: env.DB.prepare(
|
|
1643
|
+
"INSERT INTO comments(id,thread_id,user_id,body,created_at) VALUES(?,?,?,?,?)"
|
|
1644
|
+
).bind(firstCommentId, id, user.id, text, now),
|
|
1622
1645
|
env.DB.prepare("UPDATE threads SET snapshot_status=? WHERE id=?").bind(snapshotStatus, id),
|
|
1623
1646
|
enqueueWebhook(env.DB, project, { ...webhookEvent(
|
|
1624
1647
|
"comment.created",
|
|
@@ -1628,7 +1651,7 @@ async function route(
|
|
|
1628
1651
|
id,
|
|
1629
1652
|
page,
|
|
1630
1653
|
JSON.stringify(anchor),
|
|
1631
|
-
user
|
|
1654
|
+
user,
|
|
1632
1655
|
text,
|
|
1633
1656
|
origin || url.origin
|
|
1634
1657
|
), ...(snapshotStatus ? { snapshotStatus } : {}), ...(data.share === false ? { share: false } : {}) }, firstCommentId),
|
|
@@ -1759,10 +1782,10 @@ async function route(
|
|
|
1759
1782
|
);
|
|
1760
1783
|
}
|
|
1761
1784
|
const match = url.pathname.match(
|
|
1762
|
-
/^\/threads\/([\w:-]{1,100})(?:\/comments(?:\/([\w:-]{1,100})(?:\/(reactions))?)?)?$/
|
|
1785
|
+
/^\/threads\/([\w:-]{1,100})(?:\/comments(?:\/([\w:-]{1,100})(?:\/(reactions|image))?)?)?$/
|
|
1763
1786
|
);
|
|
1764
1787
|
check(match, 404, "Not found.");
|
|
1765
|
-
const [, threadId, commentId,
|
|
1788
|
+
const [, threadId, commentId, action] = match;
|
|
1766
1789
|
const thread = await env.DB.prepare(
|
|
1767
1790
|
"SELECT * FROM threads WHERE id=? AND project=? AND repo=? AND branch=?"
|
|
1768
1791
|
)
|
|
@@ -1864,7 +1887,7 @@ async function route(
|
|
|
1864
1887
|
).bind(Number(data.resolved), data.resolved ? user.id : null, now, threadId),
|
|
1865
1888
|
...(firstComment ? [enqueueWebhook(env.DB, project, webhookEvent(
|
|
1866
1889
|
"comment.resolved", project, repo, branch, threadId, thread.page,
|
|
1867
|
-
thread.anchor, user
|
|
1890
|
+
thread.anchor, user, null, origin || url.origin
|
|
1868
1891
|
), firstComment.id)] : []),
|
|
1869
1892
|
]);
|
|
1870
1893
|
ctx.waitUntil(drainWebhooks(env));
|
|
@@ -1878,9 +1901,13 @@ async function route(
|
|
|
1878
1901
|
const text = string(data.body, 4000, "reply");
|
|
1879
1902
|
const replyId = crypto.randomUUID();
|
|
1880
1903
|
const result = await env.DB.batch([
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1904
|
+
apiKeyName
|
|
1905
|
+
? env.DB.prepare(
|
|
1906
|
+
"INSERT INTO comments(id,thread_id,user_id,body,created_at,api_key_name) SELECT ?,?,?,?,?,? WHERE (SELECT COUNT(*) FROM comments WHERE thread_id=?)<200"
|
|
1907
|
+
).bind(replyId, threadId, user.id, text, now, apiKeyName, threadId)
|
|
1908
|
+
: env.DB.prepare(
|
|
1909
|
+
"INSERT INTO comments(id,thread_id,user_id,body,created_at) SELECT ?,?,?,?,? WHERE (SELECT COUNT(*) FROM comments WHERE thread_id=?)<200"
|
|
1910
|
+
).bind(replyId, threadId, user.id, text, now, threadId),
|
|
1884
1911
|
env.DB.prepare("UPDATE threads SET updated_at=? WHERE id=?").bind(
|
|
1885
1912
|
now,
|
|
1886
1913
|
threadId
|
|
@@ -1893,7 +1920,7 @@ async function route(
|
|
|
1893
1920
|
threadId,
|
|
1894
1921
|
thread.page,
|
|
1895
1922
|
thread.anchor,
|
|
1896
|
-
user
|
|
1923
|
+
user,
|
|
1897
1924
|
text,
|
|
1898
1925
|
origin || url.origin
|
|
1899
1926
|
), replyId),
|
|
@@ -1919,7 +1946,47 @@ async function route(
|
|
|
1919
1946
|
.bind(commentId, threadId)
|
|
1920
1947
|
.first<CommentRow>();
|
|
1921
1948
|
check(comment, 404, "Comment not found.");
|
|
1922
|
-
if (
|
|
1949
|
+
if (action === "image") {
|
|
1950
|
+
check(comment.body !== "[Comment deleted]", 404, "Comment not found.");
|
|
1951
|
+
if (request.method === "GET") {
|
|
1952
|
+
const image = await env.DB.prepare("SELECT mime,bytes FROM comment_images WHERE comment_id=?")
|
|
1953
|
+
.bind(commentId).first<{ mime: string; bytes: unknown }>();
|
|
1954
|
+
check(image, 404, "Image not found.");
|
|
1955
|
+
const bytes = blobBytes(image.bytes);
|
|
1956
|
+
return new Response(bytes as Uint8Array<ArrayBuffer>, {
|
|
1957
|
+
headers: {
|
|
1958
|
+
"Content-Type": image.mime,
|
|
1959
|
+
"X-Content-Type-Options": "nosniff",
|
|
1960
|
+
"Content-Security-Policy": "sandbox; default-src 'none'",
|
|
1961
|
+
"Cache-Control": "private, max-age=300",
|
|
1962
|
+
},
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
check(request.method === "PUT" || request.method === "DELETE", 405, "Method not allowed.");
|
|
1966
|
+
check(comment.user_id === user.id, 403, "Only the author can change this image.");
|
|
1967
|
+
if (request.method === "DELETE") {
|
|
1968
|
+
await env.DB.batch([
|
|
1969
|
+
env.DB.prepare("DELETE FROM comment_images WHERE comment_id=?").bind(commentId),
|
|
1970
|
+
env.DB.prepare("UPDATE threads SET updated_at=? WHERE id=?").bind(now, threadId),
|
|
1971
|
+
]);
|
|
1972
|
+
return json({ ok: true });
|
|
1973
|
+
}
|
|
1974
|
+
check(user.verified || (auth.allowGuests && config.allowGuestSnapshots === true),
|
|
1975
|
+
403, "Guests cannot attach images in this project.");
|
|
1976
|
+
await limit(env, `${project}:snapshot:${user.id}`, 60, 600);
|
|
1977
|
+
const image = await readSnapshot(request, "image");
|
|
1978
|
+
const stored = await env.DB.prepare(
|
|
1979
|
+
`INSERT INTO comment_images(comment_id,project,mime,bytes,size,created_at)
|
|
1980
|
+
SELECT ?,?,?,?,?,? WHERE EXISTS (SELECT 1 FROM comments WHERE id=? AND body<>'[Comment deleted]')
|
|
1981
|
+
AND (SELECT COALESCE(SUM(size),0) FROM comment_images WHERE project=? AND comment_id<>?)
|
|
1982
|
+
+ (SELECT COALESCE(SUM(s.size),0) FROM snapshots s JOIN threads t ON t.id=s.thread_id WHERE t.project=?)
|
|
1983
|
+
+ ? <= ? ON CONFLICT(comment_id) DO UPDATE SET mime=excluded.mime,bytes=excluded.bytes,size=excluded.size,created_at=excluded.created_at`
|
|
1984
|
+
).bind(commentId, project, image.mime, image.bytes, image.bytes.length, now, commentId,
|
|
1985
|
+
project, commentId, project, image.bytes.length, snapshotCap(config.maxSnapshotBytes)).run();
|
|
1986
|
+
check(stored.meta.changes, 409, "Could not attach the image. Check the comment and the project storage limit.");
|
|
1987
|
+
return json({ ok: true }, 201);
|
|
1988
|
+
}
|
|
1989
|
+
if (action === "reactions" && request.method === "POST") {
|
|
1923
1990
|
const data = await body(request);
|
|
1924
1991
|
check(
|
|
1925
1992
|
isEmoji(data.emoji) && typeof data.active === "boolean",
|
|
@@ -1949,7 +2016,7 @@ async function route(
|
|
|
1949
2016
|
return json({ ok: true });
|
|
1950
2017
|
}
|
|
1951
2018
|
check(
|
|
1952
|
-
!
|
|
2019
|
+
!action && comment.user_id === user.id,
|
|
1953
2020
|
403,
|
|
1954
2021
|
"Only the author can change this comment."
|
|
1955
2022
|
);
|
|
@@ -1976,6 +2043,7 @@ async function route(
|
|
|
1976
2043
|
now,
|
|
1977
2044
|
commentId
|
|
1978
2045
|
),
|
|
2046
|
+
env.DB.prepare("DELETE FROM comment_images WHERE comment_id=?").bind(commentId),
|
|
1979
2047
|
env.DB.prepare("DELETE FROM reactions WHERE comment_id=?").bind(
|
|
1980
2048
|
commentId
|
|
1981
2049
|
),
|
|
@@ -2089,7 +2157,7 @@ export default {
|
|
|
2089
2157
|
headers.set("Access-Control-Allow-Origin", origin);
|
|
2090
2158
|
headers.set(
|
|
2091
2159
|
"Access-Control-Allow-Methods",
|
|
2092
|
-
"GET, POST, PATCH, DELETE, OPTIONS"
|
|
2160
|
+
"GET, POST, PUT, PATCH, DELETE, OPTIONS"
|
|
2093
2161
|
);
|
|
2094
2162
|
headers.set(
|
|
2095
2163
|
"Access-Control-Allow-Headers",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
CREATE TABLE project_bot_tokens (
|
|
2
|
+
id text PRIMARY KEY,
|
|
3
|
+
project text NOT NULL,
|
|
4
|
+
user_id text NOT NULL REFERENCES users(id),
|
|
5
|
+
token_hash text NOT NULL,
|
|
6
|
+
created_by text NOT NULL REFERENCES users(id),
|
|
7
|
+
created_at bigint NOT NULL,
|
|
8
|
+
revoked_at bigint
|
|
9
|
+
);
|
|
10
|
+
CREATE INDEX project_bot_tokens_project ON project_bot_tokens(project);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE comments ADD COLUMN api_key_name TEXT;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
CREATE TABLE comment_images (
|
|
2
|
+
comment_id TEXT PRIMARY KEY REFERENCES comments(id) ON DELETE CASCADE,
|
|
3
|
+
project TEXT NOT NULL,
|
|
4
|
+
mime TEXT NOT NULL,
|
|
5
|
+
bytes BLOB NOT NULL,
|
|
6
|
+
size INTEGER NOT NULL,
|
|
7
|
+
created_at INTEGER NOT NULL
|
|
8
|
+
);
|
|
9
|
+
CREATE INDEX comment_images_by_project ON comment_images(project);
|
|
10
|
+
CREATE TRIGGER comment_image_quota_insert AFTER INSERT ON comment_images BEGIN
|
|
11
|
+
UPDATE project_quotas SET bytes=bytes+NEW.size+256 WHERE project=NEW.project;
|
|
12
|
+
SELECT RAISE(ABORT, 'komo_quota_exceeded') WHERE EXISTS(SELECT 1 FROM project_quotas WHERE project=NEW.project AND bytes>max_bytes);
|
|
13
|
+
UPDATE threads SET updated_at=MAX(updated_at,NEW.created_at) WHERE id=(SELECT thread_id FROM comments WHERE id=NEW.comment_id);
|
|
14
|
+
END;
|
|
15
|
+
CREATE TRIGGER comment_image_quota_update AFTER UPDATE OF size ON comment_images BEGIN
|
|
16
|
+
UPDATE project_quotas SET bytes=MAX(0,bytes+NEW.size-OLD.size) WHERE project=NEW.project;
|
|
17
|
+
SELECT RAISE(ABORT, 'komo_quota_exceeded') WHERE EXISTS(SELECT 1 FROM project_quotas WHERE project=NEW.project AND bytes>max_bytes);
|
|
18
|
+
UPDATE threads SET updated_at=MAX(updated_at,NEW.created_at) WHERE id=(SELECT thread_id FROM comments WHERE id=NEW.comment_id);
|
|
19
|
+
END;
|
|
20
|
+
CREATE TRIGGER comment_image_quota_delete AFTER DELETE ON comment_images BEGIN
|
|
21
|
+
UPDATE project_quotas SET bytes=MAX(0,bytes-OLD.size-256) WHERE project=OLD.project;
|
|
22
|
+
END;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createBotToken } from "./bot-tokens";
|
|
1
2
|
import { importProject } from "./import-project";
|
|
2
3
|
import { projectSites, saveProjectSites } from "./project-sites";
|
|
3
4
|
import { check, string } from "./validation";
|
|
@@ -23,6 +24,11 @@ export async function privateAccess(env: Env, project: string) {
|
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
26
|
export async function requireMember(env: Env, project: string, user: Identity) {
|
|
27
|
+
if (user.id.startsWith("bot:")) {
|
|
28
|
+
const grant = await env.DB.prepare("SELECT id FROM project_bot_tokens WHERE user_id=? AND project=? AND revoked_at IS NULL").bind(user.id, project).first();
|
|
29
|
+
check(grant, 403, "This bot is not allowed for this project.");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
26
32
|
check(
|
|
27
33
|
user.verified && user.id.startsWith("google:"),
|
|
28
34
|
403,
|
|
@@ -86,6 +92,17 @@ export async function manageProject(
|
|
|
86
92
|
return Response.json({ ok: true });
|
|
87
93
|
}
|
|
88
94
|
await googleOwner(env, project, user);
|
|
95
|
+
if (path === "/project/bots" && request.method === "POST")
|
|
96
|
+
return Response.json(await createBotToken(env, project, user.id, await readBody()), { status: 201 });
|
|
97
|
+
if (path === "/project/bots" && request.method === "GET") {
|
|
98
|
+
const rows = await env.DB.prepare("SELECT id,user_id,created_at,revoked_at FROM project_bot_tokens WHERE project=? ORDER BY created_at DESC").bind(project).all();
|
|
99
|
+
return Response.json({ bots: rows.results });
|
|
100
|
+
}
|
|
101
|
+
const botId = /^\/project\/bots\/([a-f0-9-]{36})$/.exec(path)?.[1];
|
|
102
|
+
if (botId && request.method === "DELETE") {
|
|
103
|
+
await env.DB.prepare("UPDATE project_bot_tokens SET revoked_at=? WHERE id=? AND project=? AND revoked_at IS NULL").bind(Date.now(), botId, project).run();
|
|
104
|
+
return Response.json({ ok: true });
|
|
105
|
+
}
|
|
89
106
|
if (path === "/project/webhook" && request.method === "GET") {
|
|
90
107
|
const row = await env.DB.prepare(
|
|
91
108
|
"SELECT webhook_url,webhook_secret,webhook_events,webhook_enabled FROM project_settings WHERE project=?"
|