@snagset/server 0.1.66 → 0.1.68

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.
Files changed (89) hide show
  1. package/dist/db/migrations/0020_attachments_shared_key.sql +37 -0
  2. package/dist/jobs/reaper.js +71 -21
  3. package/dist/jobs/reaper.js.map +1 -1
  4. package/dist/plan.js +1 -1
  5. package/dist/plan.js.map +1 -1
  6. package/dist/routes/attachments.js +88 -32
  7. package/dist/routes/attachments.js.map +1 -1
  8. package/dist/routes/reviewLinks.js +4 -1
  9. package/dist/routes/reviewLinks.js.map +1 -1
  10. package/dist/storage/shared.js +96 -0
  11. package/dist/storage/shared.js.map +1 -0
  12. package/package.json +1 -1
  13. package/static/dashboard/assets/{CompositeItem-DUU2dBBI.js → CompositeItem-DBlbEmrq.js} +1 -1
  14. package/static/dashboard/assets/{CompositeList-nzDbuttJ.js → CompositeList-BzeA8yRv.js} +1 -1
  15. package/static/dashboard/assets/{ConfirmDialog-CHFBH7e-.js → ConfirmDialog-InDeLqVY.js} +1 -1
  16. package/static/dashboard/assets/{CopyButton-U3SFd-HD.js → CopyButton-CuM8jLD2.js} +1 -1
  17. package/static/dashboard/assets/{FieldItemContext-Ctu8Sx36.js → FieldItemContext-UklvviEG.js} +1 -1
  18. package/static/dashboard/assets/{InstallTag-Dv3gaL4O.js → InstallTag-SFIkAvLJ.js} +1 -1
  19. package/static/dashboard/assets/{InstanceRows-DPIpELtc.js → InstanceRows-CdfJ5245.js} +1 -1
  20. package/static/dashboard/assets/{McpTokens-yimU884S.js → McpTokens-DvasPFMw.js} +1 -1
  21. package/static/dashboard/assets/{Picker-CCAp0603.js → Picker-B42iZVoy.js} +1 -1
  22. package/static/dashboard/assets/{SaveState-zj94ZTUn.js → SaveState-BRkBmXqs.js} +1 -1
  23. package/static/dashboard/assets/_-Cqe1ACLG.js +1 -0
  24. package/static/dashboard/assets/_app-BYZ11Msi.js +1 -0
  25. package/static/dashboard/assets/{_app-Boi8G11t.js → _app-D16rNb9V.js} +1 -1
  26. package/static/dashboard/assets/{_app-CPD7sbIv.js → _app-gdWCSHu8.js} +1 -1
  27. package/static/dashboard/assets/{activity-BXgHGBG-.js → activity-DJN1xKxv.js} +1 -1
  28. package/static/dashboard/assets/address-C-21UTZG.js +1 -0
  29. package/static/dashboard/assets/{arrow-left-BWxLUUtR.js → arrow-left-COavGffT.js} +1 -1
  30. package/static/dashboard/assets/{avatar-C272UWe3.js → avatar-D-xvBFxx.js} +1 -1
  31. package/static/dashboard/assets/{badge-CYPTl0cy.js → badge-iEJVsBYn.js} +1 -1
  32. package/static/dashboard/assets/{check-2F6z9BBy.js → check-BoeukqKC.js} +1 -1
  33. package/static/dashboard/assets/{chevron-down-Co3oKci1.js → chevron-down-BI3rT8EZ.js} +1 -1
  34. package/static/dashboard/assets/{chevron-right-DMXTfy_h.js → chevron-right-BA1nBLwE.js} +1 -1
  35. package/static/dashboard/assets/{copy-B-mCACcx.js → copy-DvA576Ce.js} +1 -1
  36. package/static/dashboard/assets/{createBaseUIEventDetails-67bayC1B.js → createBaseUIEventDetails-DxVYwN0n.js} +1 -1
  37. package/static/dashboard/assets/{dialog-l22OkYXh.js → dialog-DMLR5Ann.js} +1 -1
  38. package/static/dashboard/assets/{dropdown-menu-CIJhCtDQ.js → dropdown-menu-DJu3c_AK.js} +1 -1
  39. package/static/dashboard/assets/{forgot-ykPZ1Kdg.js → forgot-C7sjq6sz.js} +1 -1
  40. package/static/dashboard/assets/{getPseudoElementBounds-D9YqITSR.js → getPseudoElementBounds-DzoINCkV.js} +1 -1
  41. package/static/dashboard/assets/{image-off-BkVnePLU.js → image-off-rYr6mHjc.js} +1 -1
  42. package/static/dashboard/assets/{index-BC1mWQy8.js → index-C7KR1inc.js} +3 -3
  43. package/static/dashboard/assets/{inertValue-Dy4HJtbg.js → inertValue-CI-rS9np.js} +1 -1
  44. package/static/dashboard/assets/{invite-DDvCZ3v_.js → invite-B42fXoS_.js} +1 -1
  45. package/static/dashboard/assets/{label-Des6lF0o.js → label-Blp9UOAu.js} +1 -1
  46. package/static/dashboard/assets/{layout-grid-ojTM11RH.js → layout-grid-Cnury9dY.js} +1 -1
  47. package/static/dashboard/assets/me-BK0rftp3.js +1 -0
  48. package/static/dashboard/assets/{plus-CqHIH0K8.js → plus-DZmzLC79.js} +1 -1
  49. package/static/dashboard/assets/{reset-GkTsanrN.js → reset-bLKOzgnn.js} +1 -1
  50. package/static/dashboard/assets/{s._site-DuFqROtI.js → s._site-Djh35HSb.js} +1 -1
  51. package/static/dashboard/assets/{s._site.comments-DwPDdi_u.js → s._site.comments-DJI0OPtT.js} +11 -11
  52. package/static/dashboard/assets/s._site.reviewers-BU7pBSo5.js +1 -0
  53. package/static/dashboard/assets/{s._site.settings-0uXBXAn-.js → s._site.settings-DWrNkl_z.js} +1 -1
  54. package/static/dashboard/assets/{setup-CGKTYRhS.js → setup-CmW1XX0v.js} +1 -1
  55. package/static/dashboard/assets/{sign-in-BFx4q3Vl.js → sign-in-XOa4u4NO.js} +1 -1
  56. package/static/dashboard/assets/{sign-up-BeS3OqBr.js → sign-up-BL6Twjt_.js} +1 -1
  57. package/static/dashboard/assets/{sites-DWQtdLHK.js → sites-DZSK9rHh.js} +1 -1
  58. package/static/dashboard/assets/studio-C6Nmlwud.js +1 -0
  59. package/static/dashboard/assets/{studio-DxClsYRz.js → studio-DyTgShdj.js} +1 -1
  60. package/static/dashboard/assets/{studio.index-BKeRxtvS.js → studio.index-4BPM7HJY.js} +1 -1
  61. package/static/dashboard/assets/{studio.integrations-BDKRHU8R.js → studio.integrations-iKQV-OdC.js} +1 -1
  62. package/static/dashboard/assets/{studio.members-Dnw8MvSM.js → studio.members-DFQ7Ifit.js} +1 -1
  63. package/static/dashboard/assets/{studio.plan-CV9lR0OF.js → studio.plan-BqilzE9p.js} +1 -1
  64. package/static/dashboard/assets/{sun-BDbnQON-.js → sun-BuEfrAI0.js} +1 -1
  65. package/static/dashboard/assets/{switch-BQZZEckg.js → switch-L54Y3-uU.js} +1 -1
  66. package/static/dashboard/assets/{table-B41i9RfM.js → table-CMT1vo3l.js} +1 -1
  67. package/static/dashboard/assets/{useAriaLabelledBy-hDZ_Qzgg.js → useAriaLabelledBy-B7r0Y4KR.js} +1 -1
  68. package/static/dashboard/assets/{useBaseQuery-Di_lHTAg.js → useBaseQuery-C-W7OQbv.js} +1 -1
  69. package/static/dashboard/assets/{useCompositeItem-R43gS2Zb.js → useCompositeItem-IXvKKl7V.js} +1 -1
  70. package/static/dashboard/assets/useQuery-Cgt__oKH.js +1 -0
  71. package/static/dashboard/assets/useRender-BH8zvQt8.js +1 -0
  72. package/static/dashboard/assets/{useScrollLock-DV1FkBvY.js → useScrollLock-BJQ8REVY.js} +1 -1
  73. package/static/dashboard/assets/{useValueChanged-CxAXjLUw.js → useValueChanged-Pz2Tfnzh.js} +1 -1
  74. package/static/dashboard/assets/{users-jxEArjZq.js → users-bHIFUIgt.js} +1 -1
  75. package/static/dashboard/assets/{welcome-D7cMtm0u.js → welcome-CdW8w4Iz.js} +1 -1
  76. package/static/dashboard/assets/{widget-signin-BtBII7zp.js → widget-signin-ne9Avuvc.js} +1 -1
  77. package/static/dashboard/assets/{you-DcgRgPxz.js → you-a05RPClq.js} +1 -1
  78. package/static/dashboard/assets/{zod-DxcG0x06.js → zod-BZsHesp0.js} +1 -1
  79. package/static/dashboard/index.html +1 -1
  80. package/static/widget/build.json +2 -2
  81. package/static/widget/snag.js +1 -1
  82. package/static/widget/snag.runtime.js +1 -1
  83. package/static/dashboard/assets/_-C2HgkYw_.js +0 -1
  84. package/static/dashboard/assets/_app-Cy8QntP-.js +0 -1
  85. package/static/dashboard/assets/me-DWKKjc2l.js +0 -1
  86. package/static/dashboard/assets/s._site.reviewers-BdujL59q.js +0 -1
  87. package/static/dashboard/assets/studio-gXJp7MI3.js +0 -1
  88. package/static/dashboard/assets/useQuery-B1QbR4lk.js +0 -1
  89. package/static/dashboard/assets/useRender-bF5mRtl9.js +0 -1
@@ -0,0 +1,37 @@
1
+ -- ───────────────────────────────────────
2
+ -- attachments.storage_key stops being UNIQUE: two pictures may be the same
3
+ -- file.
4
+ --
5
+ -- The key is the content's hash (storage/bucket.ts), so the same bytes
6
+ -- uploaded twice to one site have the same key, and the bucket holds them
7
+ -- once. UNIQUE on the column turned that into "one ROW per file": the second
8
+ -- upload inserted nothing and was answered with the first upload's id. That
9
+ -- row was already bound to the first comment, the thread create binds only
10
+ -- pending rows, and so the second comment had no picture, although its
11
+ -- upload had answered 201. A reviewer leaving two comments on a page that
12
+ -- did not change between them is exactly this, every time. The same
13
+ -- happened for good once a row was deleted or reaped: its key stayed taken,
14
+ -- and no later comment could carry those bytes.
15
+ --
16
+ -- From here a row is one picture, on one comment, and several rows may name
17
+ -- one file. What the constraint used to guarantee by accident, that deleting
18
+ -- a row's file cannot take another row's picture with it, is now the
19
+ -- reaper's to check: it takes a file out of the bucket only when no other
20
+ -- row that is still pending or bound names it (jobs/reaper.ts). The index is
21
+ -- that question, and it replaces the one the constraint owned.
22
+ --
23
+ -- AN OLDER SERVER STILL RUNNING BESIDE THIS SCHEMA writes its upload with
24
+ -- ON CONFLICT (storage_key), which needs the constraint and fails without
25
+ -- it. For the length of a deploy's overlap an upload that reaches the old
26
+ -- process is a 500; the widget sends the comment without its picture, as it
27
+ -- does for any failed upload. Nothing is corrupted by it.
28
+ --
29
+ -- DDL only: no rows are read or written by this file, so no maintenance
30
+ -- claim. Dropping the constraint is a catalogue change. The plain CREATE
31
+ -- INDEX inside the runner's transaction blocks writes to attachments while
32
+ -- it builds, which on the tables this has met is well under a second.
33
+ --
34
+ -- Under D71, 05 §3 loses the UNIQUE and gains the index in the same commit.
35
+ ALTER TABLE attachments DROP CONSTRAINT attachments_storage_key_key;
36
+
37
+ CREATE INDEX attachments_storage_key_idx ON attachments (storage_key);
@@ -1,3 +1,4 @@
1
+ import { fileHolding } from "../storage/shared.js";
1
2
  /**
2
3
  * The reaper, cut to the three jobs L1 needs.
3
4
  *
@@ -127,6 +128,23 @@ export const expireRows = {
127
128
  * the row being marked orphaned while the bytes stay — so the delete is
128
129
  * attempted first and the row is updated after.
129
130
  *
131
+ * A ROW THE UPLOAD ROUTE GAVE UP is taken at once, whatever its age. When the
132
+ * bucket refuses an upload's write, the route marks the row deleted_at and
133
+ * released_at, takes its bytes off the count and leaves it pending
134
+ * (routes/attachments.ts): the row may be the last to name a file a deleted
135
+ * comment left behind, and whether it is can only be asked here, under the
136
+ * key's lock. For such a row a refused delete is NOT swallowed. It stays as
137
+ * it is for the next tick, because the row exists for this delete and
138
+ * nothing would come back for the object after it; a key that is not there
139
+ * is not a refusal, so a row cannot get stuck on a file that never arrived.
140
+ * Its bytes are not taken off a second time.
141
+ *
142
+ * THE FILE MAY NOT BE THIS ROW'S ALONE. Keys are content hashes, so the same
143
+ * bytes uploaded again are another row naming the same object, and that row
144
+ * may be on a comment that was sent. The delete is attempted only when no
145
+ * other pending or bound row names the key (storage/shared.ts); the row is
146
+ * written off and its bytes uncounted either way, since each row is counted.
147
+ *
130
148
  * With no bucket configured the job does nothing and says so. That is the
131
149
  * annotation-mode deployment, where no blob was ever written and
132
150
  * there is nothing to reap.
@@ -139,11 +157,12 @@ export function reapPendingAttachments(bucket) {
139
157
  const imageCutoff = new Date(now.getTime() - 2 * 60 * 60_000);
140
158
  const fileCutoff = new Date(now.getTime() - 15 * 60_000);
141
159
  const rows = await sql `
142
- SELECT id, project_id, storage_key, bytes, kind
160
+ SELECT id, project_id, storage_key, bytes, kind, (deleted_at IS NOT NULL) AS given_up, released_at
143
161
  FROM attachments
144
162
  WHERE state = 'pending'
145
163
  AND ((kind = 'file' AND created_at < ${fileCutoff})
146
- OR (kind <> 'file' AND created_at < ${imageCutoff}))
164
+ OR (kind <> 'file' AND created_at < ${imageCutoff})
165
+ OR deleted_at IS NOT NULL)
147
166
  ORDER BY created_at
148
167
  LIMIT ${BATCH}
149
168
  `;
@@ -154,23 +173,39 @@ export function reapPendingAttachments(bucket) {
154
173
  }
155
174
  let reaped = 0;
156
175
  for (const row of rows) {
157
- try {
158
- await bucket.del(row.storage_key);
159
- }
160
- catch (e) {
161
- // Named, not silent: a bucket that refuses every delete is a bill
162
- // that grows, and the only place it shows up is here.
163
- log(`jobs: reap-pending-attachments: delete ${row.storage_key} failed: ${String(e)}`);
176
+ // The file goes only with the last row that names it: the same bytes
177
+ // may be on a comment that WAS sent (storage/shared.ts). And a row
178
+ // whose bytes are being uploaded again this instant waits a tick.
179
+ const holding = await fileHolding(sql, row);
180
+ if (holding === "busy")
181
+ continue;
182
+ if (holding === "last") {
183
+ try {
184
+ await bucket.del(row.storage_key);
185
+ }
186
+ catch (e) {
187
+ // Named, not silent: a bucket that refuses every delete is a bill
188
+ // that grows, and the only place it shows up is here.
189
+ log(`jobs: reap-pending-attachments: delete ${row.storage_key} failed: ${String(e)}`);
190
+ // A given-up row is here FOR this delete, and may be the last to
191
+ // name a file that is known to be there. It waits for a bucket
192
+ // that answers, as a deleted picture does in the job below.
193
+ if (row.given_up)
194
+ continue;
195
+ }
164
196
  }
165
197
  await sql `UPDATE attachments SET state = 'orphaned' WHERE id = ${row.id}`;
166
198
  // The counter. Decremented per row rather than in one statement at
167
199
  // the end so a mid-batch failure cannot leave the counter describing
168
- // rows that were already reaped.
169
- await sql `
170
- UPDATE projects
171
- SET storage_bytes_used = GREATEST(0, storage_bytes_used - ${Number(row.bytes)})
172
- WHERE id = ${row.project_id}
173
- `;
200
+ // rows that were already reaped. Not for a row whose bytes the upload
201
+ // route already gave back when it gave the row up (released_at).
202
+ if (!row.released_at) {
203
+ await sql `
204
+ UPDATE projects
205
+ SET storage_bytes_used = GREATEST(0, storage_bytes_used - ${Number(row.bytes)})
206
+ WHERE id = ${row.project_id}
207
+ `;
208
+ }
174
209
  reaped++;
175
210
  }
176
211
  return {
@@ -228,6 +263,12 @@ export const DELETED_SITE_GRACE_MS = 30 * 24 * 60 * 60_000;
228
263
  * get stuck on a blob that is already gone. A refused row is not retried
229
264
  * inside the same run (`more` is false unless the whole batch went).
230
265
  *
266
+ * A FILE SHARED WITH A LIVE PICTURE STAYS. Two comments with the same
267
+ * screenshot are two rows naming one object (keys are content hashes). The
268
+ * deleted one's row is marked `orphaned` here like any other, and the object
269
+ * is deleted only when no other pending or bound row names it
270
+ * (storage/shared.ts), so it leaves with whichever row is collected last.
271
+ *
231
272
  * With no bucket the job does nothing and says how many are waiting: a studio
232
273
  * that disconnected its bucket still has the rows, and reconnecting it lets
233
274
  * the next tick finish.
@@ -263,12 +304,21 @@ export function collectDeletedAttachments(bucket) {
263
304
  }
264
305
  let collected = 0;
265
306
  for (const row of rows) {
266
- try {
267
- await bucket.del(row.storage_key);
268
- }
269
- catch (e) {
270
- log(`jobs: collect-deleted-attachments: delete ${row.storage_key} failed: ${String(e)}`);
307
+ // The file goes only with the last row that names it. A row that is
308
+ // not the last is marked all the same: it is done with, and the one
309
+ // that IS the last finds no other holder when its turn comes. A row
310
+ // whose bytes are being uploaded again this instant waits a tick.
311
+ const holding = await fileHolding(sql, row);
312
+ if (holding === "busy")
271
313
  continue;
314
+ if (holding === "last") {
315
+ try {
316
+ await bucket.del(row.storage_key);
317
+ }
318
+ catch (e) {
319
+ log(`jobs: collect-deleted-attachments: delete ${row.storage_key} failed: ${String(e)}`);
320
+ continue;
321
+ }
272
322
  }
273
323
  // What goes with the state, by the table's CHECKs: only a bound row
274
324
  // has `bound_at`, and only a bound row names a thread or a comment.
@@ -303,7 +353,7 @@ export function collectDeletedAttachments(bucket) {
303
353
  return {
304
354
  did: collected,
305
355
  more: rows.length === BATCH && collected === rows.length,
306
- ...(collected < rows.length ? { note: `${rows.length - collected} could not be deleted from the bucket and will be tried again` } : {}),
356
+ ...(collected < rows.length ? { note: `${rows.length - collected} could not be taken out of the bucket yet and will be tried again` } : {}),
307
357
  };
308
358
  },
309
359
  };
@@ -1 +1 @@
1
- {"version":3,"file":"reaper.js","sourceRoot":"","sources":["../../src/jobs/reaper.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;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MAAM,CAAC,MAAqB;IAC1C,OAAO,CAAC,kBAAkB,EAAE,UAAU,EAAE,sBAAsB,CAAC,MAAM,CAAC,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7G,CAAC"}
package/dist/plan.js CHANGED
@@ -47,7 +47,7 @@ export function limitsSource(sql, keys, resolver) {
47
47
  return value;
48
48
  };
49
49
  }
50
- /** The counts the numbers are measured against (an archived site, keeps its pictures but not its place under the site cap), under the org's claim. Storage is bucket bytes summed over the studio's sites (L4's per-project counters). */
50
+ /** The counts the numbers are measured against (an archived site, keeps its pictures but not its place under the site cap), under the org's claim. Storage is the bytes of the studio's pictures summed over its sites (L4's per-project counters); each picture is counted, and identical ones share a file in the bucket. */
51
51
  export async function usage(tx, orgId) {
52
52
  const [p] = await tx `SELECT (count(*) FILTER (WHERE archived_at IS NULL))::int AS n, COALESCE(sum(storage_bytes_used), 0)::float8 AS bytes FROM projects WHERE org_id = ${orgId}::uuid AND deleted_at IS NULL`;
53
53
  const [m] = await tx `SELECT count(*)::int AS n FROM memberships WHERE org_id = ${orgId}::uuid`;
package/dist/plan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plan.js","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAoCrD,MAAM,CAAC,MAAM,SAAS,GAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAYlI,MAAM,GAAG,GAAG,QAAQ,CAAC;AACrB,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAiD,CAAC;AAEvE,MAAM,UAAU,gBAAgB;IAC9B,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC;AAED,uGAAuG;AACvG,MAAM,U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ACF;AAED,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,iBAAiB,EAAW,CAAC;AAE1J;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,CAAU,EAAE,CAAe;IAC1D,MAAM,OAAO,GACX,CAAC,CAAC,QAAQ,KAAK,UAAU,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;QACnD,CAAC,CAAC,6BAA6B,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,IAAI,4CAA4C;QAC3H,CAAC,CAAC,uCAAuC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IAC3F,OAAO,CAAC,CAAC,IAAI,CACX,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,EAClJ,GAAG,CACJ,CAAC;AACJ,CAAC"}
@@ -4,6 +4,7 @@ import { HTTP_HEADER, ID_PREFIX } from "../vendor/types/names.js";
4
4
  import { getBucket, storageStatus } from "../storage/settings.js";
5
5
  import { storageKeyFor } from "../storage/bucket.js";
6
6
  import { inOrg, maintenance } from "../db/scope.js";
7
+ import { holdFileForUpload } from "../storage/shared.js";
7
8
  import { usage } from "../plan.js";
8
9
  function fail(c, status, code, message) {
9
10
  return c.json({ error: { code, message, requestId: c.get("requestId") } }, status);
@@ -70,55 +71,106 @@ export function attachmentRoutes(deps) {
70
71
  return fail(c, 413, "storage_quota_exceeded", "This studio has used the picture storage its plan includes. Existing comments are unaffected; a plan with more storage lifts it.");
71
72
  }
72
73
  }
73
- // The same digest the storage key is derived from — stored so integrity can
74
- // be checked without re-reading the object, and so a duplicate upload is
75
- // recognisable by content rather than by key alone.
74
+ // The same digest the storage key is derived from, stored so integrity can
75
+ // be checked without re-reading the object.
76
76
  const digest = createHash("sha256").update(body).digest();
77
77
  const key = storageKeyFor(project.id, body, ext);
78
78
  const width = Number(c.req.header(HTTP_HEADER.attachmentWidth)) || null;
79
79
  const height = Number(c.req.header(HTTP_HEADER.attachmentHeight)) || null;
80
- try {
81
- await bucket.put(key, body, contentType);
82
- }
83
- catch (e) {
84
- // The bucket is the operator's, so its failure is theirs to see —
85
- // and the reviewer's comment must survive it (the widget falls back
86
- // to sending the thread without a picture).
87
- console.error(`attachment upload failed [${c.get("requestId")}]`, e);
88
- return fail(c, 502, "storage_unavailable", "The picture could not be stored. Your comment can still be sent.");
89
- }
80
+ /*
81
+ * EVERY UPLOAD IS ITS OWN ROW, whatever its bytes.
82
+ *
83
+ * The key is the content's hash, so two reviewers screenshotting the
84
+ * identical viewport, or one reviewer leaving two comments on a page that
85
+ * did not change, send the same key, and the bucket holds one object.
86
+ * This used to hold one ROW as well: the column was UNIQUE, the insert
87
+ * was ON CONFLICT DO NOTHING, and the second upload was answered with the
88
+ * first one's id. That row was already bound to the first comment, the
89
+ * thread create binds only pending rows, and the second comment was left
90
+ * with no picture after a 201. Migration 0020 took the UNIQUE away. A row
91
+ * is one picture on one comment; the file is shared, and it is the
92
+ * reaper that asks whether anyone still holds it before it deletes one
93
+ * (storage/shared.ts).
94
+ *
95
+ * EACH ROW IS COUNTED. Two comments with the same screenshot take its
96
+ * bytes off the site's storage twice, although the bucket holds them
97
+ * once. The counter is then the plain sum of the pictures a site shows,
98
+ * and every path that gives bytes back (a deleted thread, a reaped
99
+ * upload) gives back its own row's and has no other row to ask about.
100
+ *
101
+ * THE ROW BEFORE THE OBJECT, and that order is the shared file's safety,
102
+ * not a preference: see the lock in storage/shared.ts. A row whose
103
+ * object never arrives is given up below and is the reaper's on its
104
+ * next tick, or, if this process dies in between, is a pending row like
105
+ * any other and the reaper's in two hours.
106
+ *
107
+ * 'pending', and the schema is what taught me that. 05 section 3.6's
108
+ * CHECKs say state='bound' requires bound_at AND exactly one of thread_id
109
+ * or comment_id, and at upload time the thread does not exist yet,
110
+ * because the widget uploads the picture and THEN creates the thread so
111
+ * the attachment ref can ride the same write. So a row is born pending
112
+ * and is bound by the thread create (05 section 6.6: v1's wire binds
113
+ * attachments relationally after the fact).
114
+ */
90
115
  const id = randomUUID();
91
- await sql.begin(async (tx) => {
92
- await tx `SELECT set_config('app.org_id', ${project.org_id}, true)`;
116
+ await inOrg(sql, project.org_id, async (tx) => {
117
+ await holdFileForUpload(tx, key);
93
118
  await tx `
94
119
  INSERT INTO attachments (id, org_id, project_id, kind, state, storage_key, storage_backend,
95
120
  content_type, bytes, width, height, sha256, uploaded_by)
96
- -- 'pending', and the schema is what taught me that. The CHECKs say
97
- -- state='bound' requires bound_at AND exactly one of thread_id or
98
- -- comment_id -- and at upload time the thread does not exist yet,
99
- -- because the widget uploads the picture and THEN creates the thread
100
- -- so the attachment ref can ride the same write. So a row is born
101
- -- pending and is bound by the thread create (v1's wire binds
102
- -- attachments relationally after the fact).
103
121
  VALUES (${id}, ${project.org_id}, ${project.id}, ${kind}::snag_attachment_kind, 'pending',
104
122
  ${key}, 's3', ${contentType}, ${body.length}, ${width}, ${height},
105
123
  ${digest}, ${session.sub})
106
- ON CONFLICT (storage_key) DO NOTHING
107
124
  `;
108
- // Two reviewers screenshotting the identical viewport produce the same
109
- // hash and therefore the same key — one object, and the byte count is
110
- // only charged once.
111
125
  await tx `
112
126
  UPDATE projects SET storage_bytes_used = storage_bytes_used + ${body.length}
113
127
  WHERE id = ${project.id}
114
- AND EXISTS (SELECT 1 FROM attachments WHERE id = ${id})
115
128
  `;
116
129
  });
117
- const [row] = await maintenance(sql, (tx) => tx `
118
- SELECT id FROM attachments WHERE storage_key = ${key}
119
- `);
130
+ try {
131
+ await bucket.put(key, body, contentType);
132
+ }
133
+ catch (e) {
134
+ // The bucket is the operator's, so its failure is theirs to see, and
135
+ // the reviewer's comment must survive it (the widget falls back to
136
+ // sending the thread without a picture).
137
+ console.error(`attachment upload failed [${c.get("requestId")}]`, e);
138
+ /*
139
+ * The row is given up, and its bytes come off the count now. It is
140
+ * NOT marked orphaned here, and that is the point. An orphaned row
141
+ * holds no file, and a row may stop holding one only when somebody has
142
+ * asked, under the key's lock, whether it was the last, and deleted the
143
+ * object if it was (storage/shared.ts). This row may be the last: the
144
+ * same bytes can be in the bucket from a comment since deleted, whose
145
+ * own row the reaper finished a moment ago BECAUSE this one named the
146
+ * file. Marking this one orphaned would leave that object with nobody
147
+ * to delete it, for good.
148
+ *
149
+ * So it is marked the way a deleted picture is, deleted_at and
150
+ * released_at, and left pending: it cannot be bound or served, it is
151
+ * not counted, it still holds, and reap-pending-attachments takes a
152
+ * given-up row on its next tick whatever its age, asks the question
153
+ * and deletes. No lock is taken here and nothing is asked of a bucket
154
+ * that has just said no.
155
+ *
156
+ * If this write fails too, the row is an ordinary pending one, counted
157
+ * until the same reaper reaches it in two hours.
158
+ */
159
+ await inOrg(sql, project.org_id, (tx) => tx `
160
+ WITH gone AS (
161
+ UPDATE attachments SET deleted_at = now(), released_at = now()
162
+ WHERE id = ${id} AND state = 'pending' AND deleted_at IS NULL
163
+ RETURNING project_id, bytes
164
+ )
165
+ UPDATE projects p
166
+ SET storage_bytes_used = GREATEST(0, p.storage_bytes_used - gone.bytes)
167
+ FROM gone
168
+ WHERE p.id = gone.project_id
169
+ `).catch((undo) => console.error(`attachment upload: could not give up ${id} [${c.get("requestId")}]`, undo));
170
+ return fail(c, 502, "storage_unavailable", "The picture could not be stored. Your comment can still be sent.");
171
+ }
120
172
  return c.json({
121
- id: ID_PREFIX.attachment + (row?.id ?? id),
173
+ id: ID_PREFIX.attachment + id,
122
174
  kind,
123
175
  contentType,
124
176
  byteSize: body.length,
@@ -139,8 +191,12 @@ export function attachmentRoutes(deps) {
139
191
  const id = wire.startsWith(ID_PREFIX.attachment) ? wire.slice(ID_PREFIX.attachment.length) : wire;
140
192
  const [row] = await maintenance(sql, (tx) => tx `
141
193
  SELECT storage_key, content_type, project_id FROM attachments
142
- WHERE id = ${id} AND deleted_at IS NULL
194
+ WHERE id = ${id} AND deleted_at IS NULL AND state <> 'orphaned'
143
195
  `);
196
+ // Not an orphaned row's either. That used to follow from the bucket: a
197
+ // reaped upload's object was gone, so the read below found nothing. Since
198
+ // a file can be shared (storage/shared.ts) the object may still be there
199
+ // for another comment, and a reaped row would go on serving it.
144
200
  if (!row)
145
201
  return fail(c, 404, "not_found", "No such attachment.");
146
202
  const bucket = await getBucket(sql, keys);
@@ -1 +1 @@
1
- {"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/routes/attachments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AAiCtD,SAAS,IAAI,CAAC,CAAM,EAAE,MAAc,EAAE,IAAY,EAAE,OAAe;IACjE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAa,CAAC,CAAC;AAC5F,CAAC;AAED,MAAM,GAAG,GAA2B;IAClC,Y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B,GAAiB,EACjB,IAAa,EACb,MAA0C,OAAO,CAAC,GAAG;IAErD,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC;AAC9D,CAAC"}
@@ -168,7 +168,10 @@ export function reviewLinkRoutes(deps) {
168
168
  // BOTH, in one transaction. `revoked_at` stops further exchanges; the epoch
169
169
  // bump kills the sessions already issued. Doing only the first leaves every
170
170
  // reviewer who already redeemed the link working for up to 12 hours.
171
- await sql.begin(async (tx) => {
171
+ // Under the studio's claim, like every other write: on a role that cannot
172
+ // bypass RLS (Cloud's), a bare transaction's UPDATEs matched no rows and
173
+ // the 204 below was a lie, with the link Active and its sessions alive.
174
+ await inOrg(sql, owner.orgId, async (tx) => {
172
175
  await tx `UPDATE review_links SET revoked_at = now() WHERE id = ${id} AND revoked_at IS NULL`;
173
176
  await tx `UPDATE projects SET session_epoch = session_epoch + 1 WHERE id = ${link.project_id}`;
174
177
  });
@@ -1 +1 @@
1
- {"version":3,"file":"reviewLinks.js","sourceRoot":"","sources":["../../src/routes/reviewLinks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAgB,MAAM,MAAM,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAmC3C,SAAS,IAAI,CAAC,CAAM,EAAE,MAAc,EAAE,IAAY,EAAE,OAAe;IACjE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EA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AAG,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;YACzC,MAAM,EAAE,CAAA,yDAAyD,EAAE,yBAAyB,CAAC;YAC7F,MAAM,EAAE,CAAA,oEAAoE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChG,CAAC,CAAC,CAAC;QACH,2EAA2E;QAC3E,yEAAyE;QACzE,qBAAqB;QACrB,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE9B,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Several pictures, one file.
3
+ *
4
+ * The storage key is the content's hash under the site's id
5
+ * (`storageKeyFor`), so the same bytes uploaded twice to one site are one
6
+ * object in the bucket. Each upload is still its own row: its own id, its
7
+ * own comment, its own delete. So a file can have several rows naming it,
8
+ * and the one thing that must never happen is the file leaving the bucket
9
+ * while a row that is still shown names it.
10
+ *
11
+ * Two rules keep that, and both live here so that the upload and the reaper
12
+ * cannot come to mean different things by them:
13
+ *
14
+ * · WHO HOLDS A FILE. A row that is `pending` or `bound`. An `orphaned`
15
+ * row is one the reaper has finished with; it names a key and holds
16
+ * nothing. A `bound` row with `deleted_at` set still holds, until the
17
+ * reaper reaches it: it is the reaper's own turn at that row that lets
18
+ * go, so of two deleted rows naming one file the second one collected
19
+ * is the one that deletes it. The same goes for a `pending` row the
20
+ * upload route gave up when the bucket refused its write. ONLY THE
21
+ * REAPER MAKES A ROW `orphaned`, and only after `fileHolding` below:
22
+ * a row marked orphaned anywhere else could be the last to name a file,
23
+ * and no job comes back for an orphaned row.
24
+ *
25
+ * · THE LOCK. "Nobody else holds it" and "delete it" are two steps with a
26
+ * network call between them, and an upload of the same bytes can land in
27
+ * the gap: the reaper finds no other holder, the upload writes the object
28
+ * and its row, the reaper deletes the object. The new comment then has a
29
+ * row and no picture, for good. An advisory lock on the key closes the
30
+ * gap. The reaper takes it exclusively before it looks and keeps it until
31
+ * its pass commits. The upload takes it shared, in the transaction that
32
+ * inserts its row, and writes the object only after that transaction has
33
+ * committed. So either the row is there when the reaper looks, and the
34
+ * file stays; or the reaper is done before the row exists, and the
35
+ * object is written after the delete, not before it.
36
+ *
37
+ * · WHO WAITS. The upload waits for the lock; the reaper only TRIES it,
38
+ * and leaves the row for its next tick when an upload has it. That is
39
+ * not politeness. The reaper's pass is one transaction that by then may
40
+ * hold the site's `projects` row (it takes bytes off the counter as it
41
+ * goes), and the upload, holding the key, is about to wait for that same
42
+ * row to add its own. A reaper that waited for the key there would be a
43
+ * deadlock, and Postgres would settle it by failing one of the two. A
44
+ * file whose bytes are being uploaded this instant is in no hurry to be
45
+ * deleted.
46
+ *
47
+ * Transaction-scoped, for the reason `migrate.ts` gives: a pooler in
48
+ * transaction mode hands out a backend per transaction, and a session lock
49
+ * taken on one and released on another is held by nobody. Shared between
50
+ * uploads, so two reviewers sending the same picture never wait on each
51
+ * other. An upload waits only on a reaper pass that is, at that moment,
52
+ * collecting a file with exactly its bytes, and for no longer than the rest
53
+ * of that pass.
54
+ *
55
+ * 0x6364424C is the ASCII for "cdBL", picked as `JOB_LOCK_NAMESPACE` picks
56
+ * "cdJB": the number means nothing, and every instance computes the same
57
+ * one. `hashtext` runs in Postgres on both sides, so the two agree by
58
+ * construction; a collision between two keys costs a wait and nothing else.
59
+ */
60
+ export const FILE_LOCK_NAMESPACE = 0x6364424c;
61
+ /** The upload's side: hold the key while this transaction inserts a row that names it. */
62
+ export async function holdFileForUpload(tx, storageKey) {
63
+ await tx `SELECT pg_advisory_xact_lock_shared(${FILE_LOCK_NAMESPACE}, hashtext(${storageKey}))`;
64
+ }
65
+ /**
66
+ * The reaper's side: may this row's file leave the bucket?
67
+ *
68
+ * "last" no other row that is pending or bound names the key: delete it.
69
+ * "shared" another row still holds it: leave the file, finish the row.
70
+ * "busy" an upload of these bytes is in flight: leave the row as it is
71
+ * and ask again on the next tick.
72
+ *
73
+ * Takes the key's lock first and keeps it to the end of the caller's
74
+ * transaction, which is what makes "last" still true when the delete that
75
+ * follows reaches the bucket. So it is for a caller already inside a
76
+ * transaction, as every job is (jobs/index.ts); on a bare connection the
77
+ * lock would be gone before the answer came back.
78
+ *
79
+ * Two statements on purpose. A statement's snapshot is taken when it starts,
80
+ * so one that locked and looked in the same breath could miss the row of an
81
+ * upload that committed in between.
82
+ */
83
+ export async function fileHolding(tx, row) {
84
+ const [lock] = await tx `
85
+ SELECT pg_try_advisory_xact_lock(${FILE_LOCK_NAMESPACE}, hashtext(${row.storage_key})) AS ok
86
+ `;
87
+ if (!lock?.ok)
88
+ return "busy";
89
+ const [other] = await tx `
90
+ SELECT id FROM attachments
91
+ WHERE storage_key = ${row.storage_key} AND id <> ${row.id} AND state <> 'orphaned'
92
+ LIMIT 1
93
+ `;
94
+ return other ? "shared" : "last";
95
+ }
96
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/storage/shared.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAE9C,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EAA2B,EAAE,UAAkB;IACrF,MAAM,EAAE,CAAA,uCAAuC,mBAAmB,cAAc,UAAU,IAAI,CAAC;AACjG,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,EAA0C,EAC1C,GAAwC;IAExC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,CAAmB;uCACL,mBAAmB,cAAc,GAAG,CAAC,WAAW;GACpF,CAAC;IACF,IAAI,CAAC,IAAI,EAAE,EAAE;QAAE,OAAO,MAAM,CAAC;IAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,EAAE,CAAkB;;2BAEjB,GAAG,CAAC,WAAW,cAAc,GAAG,CAAC,EAAE;;GAE3D,CAAC;IACF,OAAO,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snagset/server",
3
- "version": "0.1.66",
3
+ "version": "0.1.68",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "The Snagset server: API, dashboard and widget in one package. Node and Postgres, or Vercel.",
@@ -1 +1 @@
1
- import{E as u,aT as t,k as c}from"./index-BC1mWQy8.js";import{u as E}from"./useCompositeItem-R43gS2Zb.js";function A(e){const{render:d,className:l,style:C,state:s=u,props:o=t,refs:r=t,metadata:a,stateAttributesMapping:m,tag:p="div",...i}=e,{compositeProps:n,compositeRef:f}=E({metadata:a});return c(p,e,{state:s,ref:[f,...r],props:[n,...o,i],stateAttributesMapping:m})}export{A as C};
1
+ import{E as u,aT as t,k as c}from"./index-C7KR1inc.js";import{u as E}from"./useCompositeItem-IXvKKl7V.js";function A(e){const{render:d,className:l,style:C,state:s=u,props:o=t,refs:r=t,metadata:a,stateAttributesMapping:m,tag:p="div",...i}=e,{compositeProps:n,compositeRef:f}=E({metadata:a});return c(p,e,{state:s,ref:[f,...r],props:[n,...o,i],stateAttributesMapping:m})}export{A as C};