@gryt/core 0.30.0 → 0.31.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.
@@ -152,9 +152,30 @@ export function historyBatches(entries, newId) {
152
152
  return sizedBatches(entries, historyBody, (raw) => readHistoryEntry(raw) !== null, { type: "history" })
153
153
  .map((batch) => ({ type: "history", id: newId(), entries: batch }));
154
154
  }
155
+ /* The server takes this many upload ids with one send, and a batch has to name all of its files. */
156
+ const MAX_FILES_PER_SEND = 10;
157
+ function withinFileLimit(batch) {
158
+ const out = [];
159
+ let current = [];
160
+ let files = 0;
161
+ for (const e of batch) {
162
+ const count = Object.keys(e.attachments ?? {}).length;
163
+ if (current.length && files + count > MAX_FILES_PER_SEND) {
164
+ out.push(current);
165
+ current = [];
166
+ files = 0;
167
+ }
168
+ current.push(e);
169
+ files += count;
170
+ }
171
+ if (current.length)
172
+ out.push(current);
173
+ return out;
174
+ }
155
175
  /** An import as batches small enough to send, oldest first, the same way `historyBatches` splits. */
156
176
  export function importBatches(entries, newId) {
157
177
  return sizedBatches(entries, importBody, (raw) => readImportEntry(raw) !== null, { type: "import", source: "discord" })
178
+ .flatMap(withinFileLimit)
158
179
  .map((batch) => ({ type: "import", id: newId(), source: "discord", entries: batch }));
159
180
  }
160
181
  /** Discord's own epoch, 2015-01-01. Nothing from Discord is older. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gryt/core",
3
- "version": "0.30.0",
3
+ "version": "0.31.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": {