@hyperframes/share 0.9.32 → 0.9.33

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 (60) hide show
  1. package/README.md +61 -2
  2. package/dist/index.d.mts +2 -0
  3. package/dist/projectLock.d.mts +2 -2
  4. package/dist/projectSnapshot.d.mts +3 -1
  5. package/dist/reviewClient.d.mts +8 -0
  6. package/dist/reviewExport.d.mts +11 -1
  7. package/dist/reviewShare.d.mts +2 -1
  8. package/dist/reviewUpload.d.mts +2 -0
  9. package/dist/shareSources.d.mts +24 -0
  10. package/dist/sourceIgnore.d.mts +6 -0
  11. package/dist/sources/adapterTypes.d.ts +39 -0
  12. package/dist/sources/api.d.mts +29 -0
  13. package/dist/sources/capture.d.mts +24 -0
  14. package/dist/sources/contract.d.mts +2 -0
  15. package/dist/sources/errors.d.mts +24 -0
  16. package/dist/sources/limits.d.mts +12 -0
  17. package/dist/sources/manifest.d.mts +23 -0
  18. package/dist/sources/pathPolicy.d.mts +25 -0
  19. package/dist/sources/projectState.d.mts +9 -0
  20. package/dist/sources/store.d.mts +3 -0
  21. package/dist/sources/transfer.d.mts +45 -0
  22. package/dist/sources/types.d.ts +353 -0
  23. package/dist/sources/unicode.d.mts +15 -0
  24. package/dist/sources/upload.d.mts +9 -0
  25. package/dist/sources/uploadFiles.d.mts +31 -0
  26. package/dist/sources/wire.d.mts +21 -0
  27. package/dist/types/reviewWire.d.ts +2 -0
  28. package/package.json +1 -1
  29. package/scripts/copy-types.mjs +3 -0
  30. package/src/index.mjs +8 -0
  31. package/src/projectLock.mjs +11 -2
  32. package/src/projectSnapshot.mjs +22 -6
  33. package/src/reviewClient.mjs +8 -1
  34. package/src/reviewExport.mjs +155 -43
  35. package/src/reviewShare.mjs +11 -2
  36. package/src/reviewUpload.mjs +18 -16
  37. package/src/reviewVersionSentences.mjs +6 -4
  38. package/src/shareSources.mjs +236 -0
  39. package/src/sourceIgnore.mjs +92 -0
  40. package/src/sources/adapterTypes.d.ts +39 -0
  41. package/src/sources/api.mjs +114 -0
  42. package/src/sources/capture.mjs +264 -0
  43. package/src/sources/contract/LICENSE-Unicode.txt +39 -0
  44. package/src/sources/contract/path-policy.json +311 -0
  45. package/src/sources/contract/unicode-15.1.0.json +6179 -0
  46. package/src/sources/contract.mjs +13 -0
  47. package/src/sources/errors.mjs +77 -0
  48. package/src/sources/limits.mjs +48 -0
  49. package/src/sources/manifest.mjs +154 -0
  50. package/src/sources/pathPolicy.mjs +197 -0
  51. package/src/sources/projectState.mjs +59 -0
  52. package/src/sources/store.mjs +82 -0
  53. package/src/sources/transfer.mjs +196 -0
  54. package/src/sources/types.d.ts +353 -0
  55. package/src/sources/unicode.mjs +163 -0
  56. package/src/sources/upload.mjs +201 -0
  57. package/src/sources/uploadFiles.mjs +263 -0
  58. package/src/sources/wire.mjs +205 -0
  59. package/src/types/reviewWire.d.ts +2 -0
  60. package/LICENSE +0 -190
@@ -39,9 +39,10 @@ import { versionSentence } from "./reviewVersionSentences.mjs";
39
39
  * definitive result; `reviewSent`: cleanup cutoff, with attribution only when the accepted attempt is
40
40
  * known; `last`: the newest version.
41
41
  * @typedef {{ pending: { body: ExportRequest, videoId: string | null, projectId?: string | null,
42
- * checkingSince?: number, snapshotRefused?: boolean, unanswered?: boolean, reviewSent?: ReviewSent } | null,
43
- * last: { fingerprint: string, versionId: string, exportedAt: string, projectId: string, files?: boolean, checksum?: string }
44
- * | null }} VersionRecord */
42
+ * renderKey?: string, checkingSince?: number, snapshotRefused?: boolean, unanswered?: boolean, reviewSent?: ReviewSent } | null,
43
+ * last: { fingerprint: string, versionId: string, exportedAt: string, projectId: string, files?: boolean,
44
+ * snapshot?: ExportRequest["snapshot"], checksum?: string }
45
+ * | null, failure?: (Failure & { projectId: string }) | null }} VersionRecord */
45
46
 
46
47
  /** `onAdded`: a version went ready, with whether it carries files and whether it is the page's first from here.
47
48
  * @typedef {{ onProgress?: (progress: ReviewExportProgress | null) => void, onUploaded?: () => Promise<void>,
@@ -49,10 +50,11 @@ import { versionSentence } from "./reviewVersionSentences.mjs";
49
50
 
50
51
  /** `projectId` overrides the recorded review project; `open`: a held video is watched only while the project is open.
51
52
  * `filesForExport`: the synced snapshot a new version carries, null for
52
- * none.
53
+ * none. `allowPending` lets a host treat accepted processing or screening as a successful return.
53
54
  * @typedef {VersionHooks & { projectPath: string, title: string, client: ReviewClient, put?: typeof putFile,
54
55
  * sleep?: (ms: number) => Promise<void>, probe?: (file: string) => Promise<VideoFacts | null>, now?: () => number,
55
- * projectId?: string | null, filesForExport?: FilesForRender, fromReview?: FromReview | null }} VersionRequest */
56
+ * projectId?: string | null, filesForExport?: FilesForRender, fromReview?: FromReview | null,
57
+ * allowPending?: boolean, requireSource?: boolean, omitSource?: boolean }} VersionRequest */
56
58
 
57
59
  /** The snapshot of `rendered`, the project as the export was rendered; null when the folder is not that render.
58
60
  * @typedef {(projectPath: string, rendered: string | null) => Promise<import("./types/reviewWire.js").SnapshotRef | null>}
@@ -179,18 +181,36 @@ function isLast(value) {
179
181
  isSavedId(value.versionId) &&
180
182
  isSavedId(value.exportedAt) &&
181
183
  isSavedId(value.projectId) &&
184
+ isLastMetadata(value)
185
+ );
186
+ }
187
+
188
+ /** @param {Record<string, unknown>} value */
189
+ function isLastMetadata(value) {
190
+ return (
182
191
  isOptionalBoolean(value.files) &&
192
+ isOptionalSnapshot(value.snapshot) &&
183
193
  (value.checksum === undefined || isSavedId(value.checksum))
184
194
  );
185
195
  }
186
196
 
187
197
  /** @param {Record<string, unknown>} saved
188
- * @returns {saved is {pending?: VersionRecord["pending"], last?: SavedLast | null}} */
198
+ * @returns {saved is {pending?: VersionRecord["pending"], last?: SavedLast | null, failure?: unknown}} */
189
199
  const isExportState = (saved) =>
190
200
  ("pending" in saved || "last" in saved) &&
191
201
  (saved.pending == null || isPending(saved.pending)) &&
192
202
  (saved.last == null || isLast(saved.last));
193
203
 
204
+ /** @param {unknown} value @returns {value is Failure & { projectId: string }} */
205
+ const isSavedFailure = (value) =>
206
+ isJsonObject(value) &&
207
+ isSavedId(value.projectId) &&
208
+ typeof value.exportKey === "string" &&
209
+ typeof value.sentence === "string" &&
210
+ typeof value.final === "boolean" &&
211
+ typeof value.exportHelps === "boolean" &&
212
+ isOptionalBoolean(value.held);
213
+
194
214
  /** @param {string} dir @returns {Promise<VersionRecord>} */
195
215
  async function readState(dir) {
196
216
  const file = statePath(dir);
@@ -200,6 +220,7 @@ async function readState(dir) {
200
220
  const { last, pending } = saved;
201
221
  return {
202
222
  pending: pending ?? null,
223
+ failure: isSavedFailure(saved.failure) ? saved.failure : null,
203
224
  last: typeof last?.fingerprint === "string" ? { ...last, fingerprint: last.fingerprint } : null,
204
225
  };
205
226
  }
@@ -267,7 +288,8 @@ export async function reviewVersion(projectPath, server = {}) {
267
288
  const last = state.last?.projectId === projectId ? state.last : null;
268
289
  const onServer =
269
290
  server.latestReadyVersionId === undefined || server.latestReadyVersionId === last?.versionId;
270
- const failed = failures.get(key);
291
+ const savedFailure = state.failure?.projectId === projectId ? state.failure : null;
292
+ const failed = savedFailure ?? failures.get(key);
271
293
  return {
272
294
  last: last
273
295
  ? { exportedAt: last.exportedAt, current: last.fingerprint === now && onServer }
@@ -287,8 +309,8 @@ export async function reviewVersion(projectPath, server = {}) {
287
309
 
288
310
  /** The newest MP4 and the body that adds it; a stale, non-MP4, too big or too long export never sends anything.
289
311
  * @param {string} dir @param {string} title @param {(file: string) => Promise<VideoFacts | null>} probe
290
- * @param {FilesForRender} filesForExport */
291
- async function exportSource(dir, title, probe, filesForExport) {
312
+ * @param {FilesForRender} filesForExport @param {boolean} requireSource */
313
+ async function exportSource(dir, title, probe, filesForExport, requireSource) {
292
314
  const latest = latestExportFile(dir);
293
315
  if (!latest || sourceOf(dir, await projectFingerprint(dir)) !== "ready")
294
316
  return { failure: local("Export an MP4 of the project as it is now first.") };
@@ -315,18 +337,34 @@ async function exportSource(dir, title, probe, filesForExport) {
315
337
  content_type: "video/mp4",
316
338
  },
317
339
  };
318
- const snapshot = await filesForExport(dir, body.source_fingerprint).catch((error) => {
319
- // expected: the version still goes up, and Share's files line says it has no files and offers Sync now.
320
- console.error(
321
- "[review files] couldn't read the synced snapshot; the version goes up without files:",
322
- error,
323
- );
324
- return null;
325
- });
340
+ const snapshot = await sourceSnapshot(
341
+ dir,
342
+ body.source_fingerprint,
343
+ filesForExport,
344
+ requireSource,
345
+ );
346
+ if (missingRequiredSource(requireSource, snapshot))
347
+ return {
348
+ failure: local(
349
+ "Source changed after preparation. Retry sharing, or choose video-only explicitly.",
350
+ ),
351
+ };
326
352
  if (snapshot) body.snapshot = snapshot;
327
353
  return { file: latest.path, body };
328
354
  }
329
355
 
356
+ /** @param {boolean} required @param {import("./types/reviewWire.js").SnapshotRef | null} snapshot */
357
+ const missingRequiredSource = (required, snapshot) => required && !snapshot;
358
+
359
+ /** @param {string} dir @param {string | null} rendered @param {FilesForRender} filesForExport @param {boolean} requireSource */
360
+ async function sourceSnapshot(dir, rendered, filesForExport, requireSource) {
361
+ return filesForExport(dir, rendered).catch((error) => {
362
+ if (requireSource) throw error;
363
+ console.error("[review files] could not read source; adding video only:", error);
364
+ return null;
365
+ });
366
+ }
367
+
330
368
  /** @param {ExportRequest["snapshot"]} a @param {ExportRequest["snapshot"]} b */
331
369
  const sameSnapshot = (a, b) =>
332
370
  a?.space_id === b?.space_id &&
@@ -376,7 +414,7 @@ async function createdExport(r, id, pending, kept) {
376
414
  return await sendCreate(r, id, pending, kept);
377
415
  } catch (error) {
378
416
  const refused = error instanceof ReviewFailed && error.reason === "snapshot_mismatch";
379
- if (!refused || !pending.body.snapshot || pending.unanswered) throw error;
417
+ if (!refused || !pending.body.snapshot || pending.unanswered || r.requireSource) throw error;
380
418
  console.error("[review] snapshot refused; the version goes up without files:", error);
381
419
  const body = { ...pending.body, client_operation_id: `export-${randomUUID()}` };
382
420
  delete body.snapshot;
@@ -569,17 +607,31 @@ const permanentRefusal = (error) =>
569
607
  * @param {string} id @param {ExportDTO} done @param {FromReview | null} fromReview @returns {Promise<Said | null>} */
570
608
  async function finish(dir, state, pending, id, done, fromReview) {
571
609
  const ready = done.status === "ready";
572
- const last = {
573
- fingerprint: pending.body.source_fingerprint ?? "",
574
- versionId: done.version_id,
575
- exportedAt: done.exported_at,
576
- projectId: id,
577
- files: Boolean(pending.body.snapshot),
578
- checksum: pending.body.local_upload.checksum_sha256,
579
- };
580
- await writeState(dir, { pending: null, last: ready ? last : state.last });
610
+ const last = readyRecord(pending, id, done);
611
+ const failure = ready ? null : said(new ReviewFailed(200, done.error?.reason ?? ""));
612
+ await writeState(dir, {
613
+ pending: null,
614
+ last: ready ? last : state.last,
615
+ ...(failure && {
616
+ failure: { ...failure, projectId: id, exportKey: await failedExportKey(dir, pending) },
617
+ }),
618
+ });
581
619
  if (ready) await sharedFromReview(fromReview, dir, pending.reviewSent?.since);
582
- return ready ? null : said(new ReviewFailed(200, done.error?.reason ?? ""));
620
+ return failure;
621
+ }
622
+
623
+ /** @param {string} dir @param {NonNullable<VersionRecord["pending"]>} pending */
624
+ async function failedExportKey(dir, pending) {
625
+ if (typeof pending.renderKey === "string") return pending.renderKey;
626
+ const latest = latestExportFile(dir);
627
+ if (!latest) return "";
628
+ const checksum =
629
+ latest.fingerprint === pending.body.source_fingerprint
630
+ ? await fileSha256Base64(latest.path).catch(() => null)
631
+ : null;
632
+ return checksum === pending.body.local_upload.checksum_sha256
633
+ ? exportKeyOf(dir)
634
+ : `pending:${pending.body.client_operation_id}`;
583
635
  }
584
636
 
585
637
  /** @param {Required<VersionRequest>} r @param {(progress: ReviewExportProgress) => void} report
@@ -587,17 +639,37 @@ async function finish(dir, state, pending, id, done, fromReview) {
587
639
  async function run(r, report) {
588
640
  report({ step: "preparing", sent: 0, total: 0 });
589
641
  const state = await readState(r.projectPath);
590
- const source = await exportSource(r.projectPath, r.title, r.probe, r.filesForExport);
642
+ const source = await exportSource(
643
+ r.projectPath,
644
+ r.title,
645
+ r.probe,
646
+ r.omitSource ? noSource : r.filesForExport,
647
+ r.requireSource,
648
+ );
591
649
  if ("failure" in source) return source.failure ?? null;
592
650
  const id = r.projectId ?? (await reviewProjectId(r.projectPath));
593
651
  if (!id) return local("Share the project first, then add a version.");
594
- if (await alreadyUploaded(r.client, id, state, source.body)) return null;
652
+ if (
653
+ sameSourceMode(r, state.last, source.body.snapshot) &&
654
+ (await alreadyUploaded(r.client, id, state, source.body))
655
+ )
656
+ return null;
595
657
  return sendVersion(r, report, source, id, state);
596
658
  }
659
+ const noSource = async () => null;
660
+
661
+ /** @param {Required<VersionRequest>} r @param {VersionRecord["last"]} last @param {ExportRequest["snapshot"]} snapshot */
662
+ function sameSourceMode(r, last, snapshot) {
663
+ if (r.requireSource) return sameSnapshot(last?.snapshot, snapshot);
664
+ if (r.omitSource) return last?.files !== true;
665
+ return true;
666
+ }
667
+
597
668
  /** @param {ReviewClient} client @param {string} id @param {VersionRecord} state @param {ExportRequest} body */
598
669
  async function alreadyUploaded(client, id, state, body) {
599
670
  const last = state.last;
600
- if (state.pending || !last || last.projectId !== id) return false;
671
+ if (state.pending || state.failure?.projectId === id || !last || last.projectId !== id)
672
+ return false;
601
673
  if (
602
674
  last.fingerprint !== body.source_fingerprint ||
603
675
  last.checksum !== body.local_upload.checksum_sha256
@@ -609,8 +681,10 @@ async function alreadyUploaded(client, id, state, body) {
609
681
  * @param {{file: string, body: ExportRequest}} source @param {string} id @param {VersionRecord} state */
610
682
  async function sendVersion(r, report, source, id, state) {
611
683
  const first = state.last?.projectId !== id;
612
- let pending = bodyToSend(state, source.body, id);
613
- await writeState(r.projectPath, (state = { ...state, pending }));
684
+ let pending = bindRenderKey(bodyToSend(state, source.body, id), r.projectPath);
685
+ const sourceConflict = pendingSourceConflict(r, pending, source.body);
686
+ if (sourceConflict) return local(sourceConflict);
687
+ await writeState(r.projectPath, (state = { ...state, pending, failure: null }));
614
688
  try {
615
689
  const answer = await createdExport(r, id, pending, (next) =>
616
690
  writeState(r.projectPath, (state = { ...state, pending: next })),
@@ -636,24 +710,40 @@ async function sendVersion(r, report, source, id, state) {
636
710
  const done = await watch(r, id, uploaded, size, report, clock);
637
711
  return finishRun(r, state, pending, id, done, first);
638
712
  } catch (error) {
639
- return failedSend(r.projectPath, state, error);
713
+ return failedSend(r.projectPath, state, pending, id, error);
640
714
  }
641
715
  }
642
716
 
643
- /** @param {string} dir @param {VersionRecord} state @param {unknown} error */
644
- async function failedSend(dir, state, error) {
717
+ /** @param {string} dir @param {VersionRecord} state
718
+ * @param {NonNullable<VersionRecord["pending"]>} pending @param {string} id @param {unknown} error */
719
+ async function failedSend(dir, state, pending, id, error) {
645
720
  const refused = permanentRefusal(error);
646
721
  // An earlier create can still be in flight when the replay is refused.
647
722
  const unansweredCreate = state.pending?.unanswered === true && state.pending.videoId === null;
648
- if (refused && !unansweredCreate) await writeState(dir, { ...state, pending: null });
649
- console.error("[review] version failed:", error);
650
- return said(error, refused && unansweredCreate);
723
+ const failure = said(error, refused && unansweredCreate);
724
+ await writeState(dir, {
725
+ ...state,
726
+ pending: refused && !unansweredCreate ? null : state.pending,
727
+ failure: { ...failure, projectId: id, exportKey: await failedExportKey(dir, pending) },
728
+ });
729
+ return failure;
730
+ }
731
+
732
+ /** @param {Required<VersionRequest>} r @param {NonNullable<VersionRecord["pending"]>} pending @param {ExportRequest} fresh */
733
+ function pendingSourceConflict(r, pending, fresh) {
734
+ if (r.requireSource && !pending.body.snapshot)
735
+ return "A pending video-only upload must finish before attaching source. Retry with --video-only, then share source again.";
736
+ if (r.omitSource && pending.body.snapshot)
737
+ return "A pending upload includes source. Check its status or retry with source before creating a video-only version.";
738
+ if (r.requireSource && !sameSnapshot(pending.body.snapshot, fresh.snapshot))
739
+ return "A pending upload includes a different source snapshot. Check its status before sharing again.";
740
+ return null;
651
741
  }
652
742
 
653
743
  /** @param {Required<VersionRequest>} r @param {VersionRecord} state
654
744
  * @param {NonNullable<VersionRecord["pending"]>} pending @param {string} id @param {ExportDTO} done @param {boolean} first */
655
745
  async function finishRun(r, state, pending, id, done, first) {
656
- if (going(done)) return stillGoing(done);
746
+ if (going(done)) return r.allowPending ? null : stillGoing(done);
657
747
  const failed = await finish(r.projectPath, state, pending, id, done, r.fromReview);
658
748
  if (!failed) {
659
749
  const fromReview = pending.reviewSent?.value;
@@ -676,8 +766,11 @@ export async function addVersion(request) {
676
766
  now: () => Date.now(),
677
767
  onProgress: () => {},
678
768
  open: () => true,
679
- filesForExport: async () => null,
769
+ allowPending: false,
770
+ filesForExport: noSource,
680
771
  fromReview: null,
772
+ requireSource: false,
773
+ omitSource: false,
681
774
  onAdded: () => {},
682
775
  ...request,
683
776
  projectId: request.projectId ?? null,
@@ -698,7 +791,6 @@ export async function addVersion(request) {
698
791
  if (kept) failures.set(key, { ...failure, exportKey: exportKeyOf(r.projectPath) });
699
792
  return failure?.sentence ?? null;
700
793
  } catch (error) {
701
- console.error("[review] version failed:", error);
702
794
  const sentence =
703
795
  error instanceof SharingStateError ? error.message : "Couldn't add this version. Try again.";
704
796
  failures.set(key, {
@@ -768,7 +860,7 @@ async function settleSavedExport(dir, client, fromReview) {
768
860
  const id = await reviewProjectId(dir);
769
861
  if (!pending?.videoId || !id || pending.projectId !== id) return;
770
862
  const done = await client.readExport(id, pending.videoId);
771
- if (going(done)) return;
863
+ if (done.status === "upload_pending" || going(done)) return;
772
864
  const failure = await finish(dir, state, pending, id, done, fromReview);
773
865
  const key = normalize(dir);
774
866
  if (failure) failures.set(key, { ...failure, exportKey: exportKeyOf(dir) });
@@ -838,3 +930,23 @@ export async function pendingReviewExport(projectPath) {
838
930
  checksum: pending.body.local_upload.checksum_sha256,
839
931
  };
840
932
  }
933
+
934
+ /** @param {NonNullable<VersionRecord["pending"]>} pending @param {string} id @param {ExportDTO} done */
935
+ function readyRecord(pending, id, done) {
936
+ return {
937
+ fingerprint: pending.body.source_fingerprint ?? "",
938
+ versionId: done.version_id,
939
+ exportedAt: done.exported_at,
940
+ projectId: id,
941
+ files: Boolean(pending.body.snapshot),
942
+ ...(pending.body.snapshot && { snapshot: pending.body.snapshot }),
943
+ checksum: pending.body.local_upload.checksum_sha256,
944
+ };
945
+ }
946
+
947
+ /** @param {NonNullable<VersionRecord["pending"]>} pending @param {string} dir */
948
+ function bindRenderKey(pending, dir) {
949
+ return typeof pending.renderKey === "string"
950
+ ? pending
951
+ : { ...pending, renderKey: exportKeyOf(dir) };
952
+ }
@@ -446,9 +446,17 @@ async function spaceRefusal(client, refused, error) {
446
446
 
447
447
  /** Share's press: the first registers the project into the space given (none: the signed-in one) and opens its link
448
448
  * to that space; a later one reads the link, turning it back on when it was off. A registered project keeps its space.
449
+ * A host can prepare review content after registration is saved and before the link or its audience changes.
449
450
  * @param {{ projectPath: string, title: string, client: ReviewClient, spaceId?: string | null, audience?:
450
- * import("./types/share.js").AccessMode | undefined }} request */
451
- export const shareForReview = ({ projectPath, title, client, spaceId = null, audience }) =>
451
+ * import("./types/share.js").AccessMode | undefined, beforeOpen?: (projectId: string) => Promise<void> }} request */
452
+ export const shareForReview = ({
453
+ projectPath,
454
+ title,
455
+ client,
456
+ spaceId = null,
457
+ audience,
458
+ beforeOpen,
459
+ }) =>
452
460
  oneAtATime(projectPath, async () => {
453
461
  const read = await recordToShare(client, projectPath, spaceId);
454
462
  const id = read.projectId ?? (await registerOnce(client, projectPath, read, title));
@@ -458,6 +466,7 @@ export const shareForReview = ({ projectPath, title, client, spaceId = null, aud
458
466
  if (!read.projectId) await writeJsonAtomic(recordPath(projectPath), record);
459
467
  const share = await readShare(client, id, projectPath);
460
468
  if (takenDown(share)) return shown(client, share);
469
+ if (!record.opened || share.revoked) await beforeOpen?.(id);
461
470
  return openLink(client, projectPath, record, id, share, audience).then(
462
471
  (opened) => shown(client, opened),
463
472
  heldInstead(client, id),
@@ -18,6 +18,22 @@ export function fileSha256Base64(file) {
18
18
 
19
19
  /** @typedef {"sent" | "expired" | "refused" | "offline"} PutOutcome */
20
20
 
21
+ /** @param {string} url */
22
+ export function trustedUploadUrl(url) {
23
+ if (!URL.canParse(url)) return null;
24
+ const target = new URL(url);
25
+ const loopback = target.protocol === "http:" && target.hostname === "127.0.0.1";
26
+ if (
27
+ (target.protocol !== "https:" && !loopback) ||
28
+ target.username ||
29
+ target.password ||
30
+ target.hash ||
31
+ !reviewUploadOrigins().includes(target.origin)
32
+ )
33
+ return null;
34
+ return target;
35
+ }
36
+
21
37
  /** Streams the file to the signed URL through main's fetch (the app's proxy), the server's headers as given plus
22
38
  * the length, and no bearer. Nothing sent or answered for `stallMs` ends it as offline, never "Uploading" forever.
23
39
  * @param {{ put_url: string, headers: Record<string, string> }} upload @param {string} file @param {number} size
@@ -29,22 +45,8 @@ export async function putFile(
29
45
  onSent,
30
46
  { stallMs = 60_000, fetchImpl = fetch } = {},
31
47
  ) {
32
- let target;
33
- try {
34
- target = new URL(upload.put_url);
35
- } catch {
36
- return "refused";
37
- }
38
- const loopback = target.protocol === "http:" && target.hostname === "127.0.0.1";
39
- if (
40
- (target.protocol !== "https:" && !loopback) ||
41
- target.username ||
42
- target.password ||
43
- target.hash ||
44
- !reviewUploadOrigins().includes(target.origin)
45
- ) {
46
- return "refused";
47
- }
48
+ const target = trustedUploadUrl(upload.put_url);
49
+ if (!target) return "refused";
48
50
  const stall = new AbortController();
49
51
  /** @type {ReturnType<typeof setTimeout> | undefined} */
50
52
  let timer;
@@ -11,8 +11,10 @@ const SAID = {
11
11
  export_too_large: "This video is over 2 GB, the most a review page takes. Export a smaller one.",
12
12
  export_too_long:
13
13
  "This video is over 30 minutes, the most a review page takes. Export a shorter one.",
14
+ export_hourly_limit: (error) =>
15
+ `You've added the most versions for this hour. Try again ${laterIn(error.retryAfterMs, "in an hour")}.`,
14
16
  export_daily_limit: (error) =>
15
- `You've added the most versions for today. Try again ${laterIn(error.retryAfterMs)}.`,
17
+ `You've added the most versions for today. Try again ${laterIn(error.retryAfterMs, "tomorrow")}.`,
16
18
  content_rejected: "This video can't be shared.",
17
19
  export_blocked: "Adding videos to review pages isn't available for this account.",
18
20
  feature_unavailable: "Review pages aren't available for your account yet.",
@@ -38,9 +40,9 @@ export function versionSentence(error, fallback = "Couldn't add this version. Tr
38
40
  return fallback;
39
41
  }
40
42
 
41
- /** "in about 3 hours", from the server's Retry-After. @param {number | undefined} ms */
42
- function laterIn(ms) {
43
- if (!ms) return "tomorrow";
43
+ /** "in about 3 hours", from the server's Retry-After; `unknown` when it sent none. @param {number | undefined} ms @param {string} unknown */
44
+ function laterIn(ms, unknown) {
45
+ if (!ms) return unknown;
44
46
  const minutes = Math.ceil(ms / 60_000);
45
47
  if (minutes < 60) return `in ${minutes} minute${minutes === 1 ? "" : "s"}`;
46
48
  const hours = Math.round(minutes / 60);