@lacrous/omnicloud 0.2.21 → 0.2.23

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/dist/index.cjs CHANGED
@@ -2177,11 +2177,11 @@ var FolderService = class {
2177
2177
  const fileIds = await this.collectFileIds(userId, subtree);
2178
2178
  const batchId = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
2179
2179
  const stampedAt = /* @__PURE__ */ new Date();
2180
- await this.folders.updateMany(
2180
+ await this.folders.trashSubtree(
2181
2181
  subtree.map((folder) => folder.id),
2182
+ fileIds,
2182
2183
  { deletedAt: stampedAt, trashBatchId: batchId }
2183
2184
  );
2184
- await this.files.updateMany(fileIds, { deletedAt: stampedAt, trashBatchId: batchId });
2185
2185
  await this.activity.record({
2186
2186
  userId,
2187
2187
  action: "trash",
@@ -2250,9 +2250,16 @@ var FolderService = class {
2250
2250
  );
2251
2251
  const engine = await this.engineFor(userId);
2252
2252
  const removedFileIds = [];
2253
+ const versionsByFile = await this.files.listVersionsForFiles(affected.map((file) => file.id));
2253
2254
  for (const file of affected) {
2254
2255
  try {
2255
- await engine.remove({ messageId: String(file.telegramMessageId) });
2256
+ const messageIds = /* @__PURE__ */ new Set([String(file.telegramMessageId)]);
2257
+ for (const version of versionsByFile.get(file.id) ?? []) {
2258
+ messageIds.add(String(version.telegramMessageId));
2259
+ }
2260
+ for (const messageId of messageIds) {
2261
+ await engine.remove({ messageId });
2262
+ }
2256
2263
  removedFileIds.push(file.id);
2257
2264
  } catch {
2258
2265
  }
@@ -2689,11 +2696,15 @@ function mapTelegramError(error, fallbackMessage) {
2689
2696
  if (error instanceof DomainError) return error;
2690
2697
  if (isTelegramRpcError(error)) {
2691
2698
  const msg = error.errorMessage ?? "";
2692
- if (msg.startsWith("FLOOD_WAIT_")) {
2693
- const seconds = Number(msg.slice("FLOOD_WAIT_".length)) || 60;
2694
- return new RateLimitedError(`Telegram rate limit reached \u2014 retry in ${seconds} seconds`, {
2695
- retryAfterSeconds: seconds
2696
- });
2699
+ const seconds = error.seconds;
2700
+ const floodSeconds = typeof seconds === "number" ? seconds : msg.startsWith("FLOOD_WAIT_") ? Number(msg.slice("FLOOD_WAIT_".length)) : null;
2701
+ if (msg.startsWith("FLOOD") && floodSeconds !== null && floodSeconds > 0) {
2702
+ return new RateLimitedError(
2703
+ `Telegram rate limit reached \u2014 retry in ${floodSeconds} seconds`,
2704
+ {
2705
+ retryAfterSeconds: floodSeconds
2706
+ }
2707
+ );
2697
2708
  }
2698
2709
  switch (msg) {
2699
2710
  case "PHONE_NUMBER_INVALID":
@@ -2723,6 +2734,13 @@ function mapTelegramError(error, fallbackMessage) {
2723
2734
  case "CHANNEL_INVALID":
2724
2735
  case "CHAT_ID_INVALID":
2725
2736
  return new StorageNotInitializedError();
2737
+ // Permanent: the account cannot write to the channel. Retrying cannot help.
2738
+ case "CHAT_WRITE_FORBIDDEN":
2739
+ case "CHAT_ADMIN_REQUIRED":
2740
+ return new ForbiddenError("OmniCloud cannot write to the storage channel for this account");
2741
+ // Permanent: the stored channel reference is stale. Retrying with the same reference fails too.
2742
+ case "PEER_ID_INVALID":
2743
+ return new StorageNotInitializedError();
2726
2744
  case "MSG_ID_INVALID":
2727
2745
  case "MESSAGE_ID_INVALID":
2728
2746
  return new TelegramFileNotFoundError();
@@ -3127,7 +3145,9 @@ var TelegramStorageProvider = class {
3127
3145
  try {
3128
3146
  await this.client.deleteMessages(this.peer, [Number(ref.messageId)], { revoke: true });
3129
3147
  } catch (error) {
3130
- throw mapTelegramError(error, "Telegram delete failed");
3148
+ const mapped = mapTelegramError(error, "Telegram delete failed");
3149
+ if (mapped instanceof TelegramFileNotFoundError) return;
3150
+ throw mapped;
3131
3151
  }
3132
3152
  }
3133
3153
  async exists(ref) {