@gryt/core 0.31.0 → 0.32.0

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.
@@ -41,6 +41,14 @@ export interface ImportDeps {
41
41
  /** The server's file size limit, so a file over it is never sealed and sent to be refused. */
42
42
  maxFileBytes?: number | null;
43
43
  }
44
+ /** A file that didn't come over, for the receipt. */
45
+ export interface ImportLeftOut {
46
+ url: string;
47
+ name: string;
48
+ /** Bytes, when it was downloaded. */
49
+ size: number | null;
50
+ reason: "too_large" | "not_downloaded";
51
+ }
44
52
  export interface ImportProgress {
45
53
  messages: {
46
54
  done: number;
@@ -58,6 +66,7 @@ export interface ImportProgress {
58
66
  /** Files this server won't take, each left out with a note on its message. */
59
67
  tooLarge: number;
60
68
  bytes: number;
69
+ leftOut: ImportLeftOut[];
61
70
  startedAt: number;
62
71
  }
63
72
  export interface ImportControl {
@@ -67,5 +76,10 @@ export interface ImportControl {
67
76
  /** For a 429's Retry-After header. Only the seconds form: anything else gets the default wait. */
68
77
  export declare function retryAfterMs(header: string | null): number;
69
78
  export declare const importId: (discordId: string) => string;
79
+ /**
80
+ * Another go at files left out: new entries beside the originals, holding only those files.
81
+ * A first run's message is already in history, and a repeat of its id is skipped there.
82
+ */
83
+ export declare function retryLeftOut(messages: DiscordPackageMessage[], urls: ReadonlySet<string>): DiscordPackageMessage[];
70
84
  /** Text first, then 20 messages at a time: their files go straight through, then those messages go. */
71
85
  export declare function runDiscordImport(messages: DiscordPackageMessage[], deps: ImportDeps, control: ImportControl, report: (p: ImportProgress) => void): Promise<ImportProgress>;
@@ -24,6 +24,16 @@ function nameOf(url) {
24
24
  return "file";
25
25
  }
26
26
  }
27
+ /**
28
+ * Another go at files left out: new entries beside the originals, holding only those files.
29
+ * A first run's message is already in history, and a repeat of its id is skipped there.
30
+ */
31
+ export function retryLeftOut(messages, urls) {
32
+ return messages.flatMap((m) => {
33
+ const attachments = m.attachments.filter((u) => urls.has(u));
34
+ return attachments.length ? [{ ...m, discordId: `${m.discordId}-files`, text: "", attachments }] : [];
35
+ });
36
+ }
27
37
  /** Text first, then 20 messages at a time: their files go straight through, then those messages go. */
28
38
  export async function runDiscordImport(messages, deps, control, report) {
29
39
  const fresh = [];
@@ -39,9 +49,10 @@ export async function runDiscordImport(messages, deps, control, report) {
39
49
  missing: 0,
40
50
  tooLarge: 0,
41
51
  bytes: 0,
52
+ leftOut: [],
42
53
  startedAt: Date.now(),
43
54
  };
44
- const tick = () => report({ ...p, messages: { ...p.messages }, downloaded: { ...p.downloaded }, sent: { ...p.sent } });
55
+ const tick = () => report({ ...p, leftOut: [...p.leftOut], messages: { ...p.messages }, downloaded: { ...p.downloaded }, sent: { ...p.sent } });
45
56
  tick();
46
57
  const hold = async () => {
47
58
  while (control.paused() && !control.stopped())
@@ -118,6 +129,7 @@ export async function runDiscordImport(messages, deps, control, report) {
118
129
  else if (!control.stopped()) {
119
130
  missing.add(url);
120
131
  p.missing = missing.size;
132
+ p.leftOut.push({ url, name: nameOf(url), size: null, reason: "not_downloaded" });
121
133
  }
122
134
  }
123
135
  if (control.stopped()) {
@@ -143,6 +155,7 @@ export async function runDiscordImport(messages, deps, control, report) {
143
155
  if ("tooLarge" in up) {
144
156
  tooLarge.add(url);
145
157
  p.tooLarge = tooLarge.size;
158
+ p.leftOut.push({ url, name: nameOf(url), size: file.bytes.length, reason: "too_large" });
146
159
  }
147
160
  else
148
161
  uploaded.set(url, up);
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { decodeMlsDmContent, encodeImportBundle, readImportBundle, encodeMlsDmCo
17
17
  export { applyMlsReaction, mlsReactionAction, type MlsReaction } from "./mls/reactions.js";
18
18
  export { type DiscordPackageDm, type DiscordPackageMessage, isDiscordPackage, linksExpireAt, listDiscordDms, type PackageFiles, readDiscordDm, } from "./import/discordPackage.js";
19
19
  export { inflateRaw, openZipBytes } from "./import/unzip.js";
20
- export { type ImportControl, type ImportDeps, type ImportFile, type ImportFileStore, importId, type ImportProgress, retryAfterMs, runDiscordImport, } from "./import/discordImportJob.js";
20
+ export { type ImportControl, type ImportDeps, type ImportFile, type ImportFileStore, importId, type ImportProgress, retryAfterMs, retryLeftOut, runDiscordImport, type ImportLeftOut, } from "./import/discordImportJob.js";
21
21
  export type { DmSealingMode, MlsAddOwnDeviceOptions, MlsClaimedKeyPackage, MlsDecryptedMessage, MlsDeviceRecord, MlsDeviceRef, MlsDmDriver, MlsDmDriverOptions, MlsDmEvents, MlsGroupPosition, MlsGroupRecord, MlsGroupView, MlsKeyPackageRecord, MlsListedDevice, MlsLogEntry, MlsDmDiagnostics, MlsOwnDevice, MlsOwnDeviceAdd, MlsPins, MlsRefusal, MlsReply, MlsServerCapability, MlsStateStore, MlsTransport, MlsWelcomeDelivery, } from "./mls/interfaces.js";
22
22
  export { createApproverPairing, type ApproverOptions, type ApproverPairing, type ApproverState, } from "./pairing/approver.js";
23
23
  export { createNewDevicePairing, PAIRING_APPROVAL_MS, type NewDeviceOptions, type NewDevicePairing, type NewDeviceState, } from "./pairing/newDevice.js";
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ export { decodeMlsDmContent, encodeImportBundle, readImportBundle, encodeMlsDmCo
19
19
  export { applyMlsReaction, mlsReactionAction } from "./mls/reactions.js";
20
20
  export { isDiscordPackage, linksExpireAt, listDiscordDms, readDiscordDm, } from "./import/discordPackage.js";
21
21
  export { inflateRaw, openZipBytes } from "./import/unzip.js";
22
- export { importId, retryAfterMs, runDiscordImport, } from "./import/discordImportJob.js";
22
+ export { importId, retryAfterMs, retryLeftOut, runDiscordImport, } from "./import/discordImportJob.js";
23
23
  export { createApproverPairing, } from "./pairing/approver.js";
24
24
  export { createNewDevicePairing, PAIRING_APPROVAL_MS, } from "./pairing/newDevice.js";
25
25
  export { createPairingRelay, PairingRelayError } from "./pairing/relayClient.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gryt/core",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "Gryt's shared application logic: one implementation of the things the desktop and mobile apps both do.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {