@lacrous/omnicloud 0.2.10 → 0.2.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lacrous/omnicloud",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "SDK and core building blocks for OmniCloud — self-hosted cloud storage powered by your Telegram account.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,9 +48,9 @@
48
48
  "prisma": "^6.2.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@omnicloud/core": "0.2.10",
52
- "@omnicloud/shared": "0.2.10",
53
- "@omnicloud/telegram": "0.2.10",
51
+ "@omnicloud/core": "0.2.12",
52
+ "@omnicloud/shared": "0.2.12",
53
+ "@omnicloud/telegram": "0.2.12",
54
54
  "@types/node": "^22.10.0",
55
55
  "esbuild": "0.25.12",
56
56
  "tsup": "^8.3.0",
package/server/index.js CHANGED
@@ -935,7 +935,9 @@ var ReconciliationApplier = class {
935
935
  const file = (await this.repos.files.listByUser(this.userId)).find(
936
936
  (candidate) => candidate.telegramMessageId === action.messageId
937
937
  );
938
- if (!file) return;
938
+ if (!file) {
939
+ throw new Error("No file of yours references this message, so there is nothing to detach");
940
+ }
939
941
  await this.repos.files.update(file.id, { deletedAt: /* @__PURE__ */ new Date(), trashBatchId: null });
940
942
  }
941
943
  async adopt(action) {
@@ -1591,6 +1593,23 @@ var FileService = class {
1591
1593
  }
1592
1594
  };
1593
1595
 
1596
+ // ../core/src/utils/folder-order.ts
1597
+ function deepestFirst(folderIds, folders) {
1598
+ const byId = new Map(folders.map((folder) => [folder.id, folder]));
1599
+ const depthOf = (id) => {
1600
+ let depth = 0;
1601
+ const seen = /* @__PURE__ */ new Set();
1602
+ let cursor = byId.get(id)?.parentId ?? null;
1603
+ while (cursor !== null && !seen.has(cursor)) {
1604
+ seen.add(cursor);
1605
+ depth += 1;
1606
+ cursor = byId.get(cursor)?.parentId ?? null;
1607
+ }
1608
+ return depth;
1609
+ };
1610
+ return [...folderIds].sort((a, b) => depthOf(b) - depthOf(a));
1611
+ }
1612
+
1594
1613
  // ../core/src/services/folder-service.ts
1595
1614
  var FolderService = class {
1596
1615
  constructor(folders, files, engineFor, activity = noopActivityRecorder) {
@@ -1793,7 +1812,10 @@ var FolderService = class {
1793
1812
  const remainingFolderIds = new Set(
1794
1813
  affected.filter((file) => !removedFileIds.includes(file.id)).map((file) => file.folderId)
1795
1814
  );
1796
- const deletable = folderIds.filter((folderId) => !remainingFolderIds.has(folderId));
1815
+ const deletable = deepestFirst(
1816
+ folderIds.filter((folderId) => !remainingFolderIds.has(folderId)),
1817
+ subtree
1818
+ );
1797
1819
  if (deletable.length > 0) {
1798
1820
  await this.folders.deleteMany(deletable);
1799
1821
  }
@@ -1967,22 +1989,13 @@ var TrashService = class {
1967
1989
  }
1968
1990
  const allFolders = await this.folders.listByUser(userId);
1969
1991
  const trashedFolders = allFolders.filter((folder) => folder.deletedAt !== null);
1970
- const depth = (folder) => {
1971
- let level = 0;
1972
- let cursor = folder.parentId;
1973
- const seen = /* @__PURE__ */ new Set();
1974
- while (cursor !== null && !seen.has(cursor)) {
1975
- seen.add(cursor);
1976
- const parent = allFolders.find((candidate) => candidate.id === cursor);
1977
- if (!parent) break;
1978
- level += 1;
1979
- cursor = parent.parentId;
1980
- }
1981
- return level;
1982
- };
1983
- trashedFolders.sort((a, b) => depth(a) - depth(b));
1992
+ const orderedIds = deepestFirst(
1993
+ trashedFolders.map((folder) => folder.id),
1994
+ allFolders
1995
+ );
1984
1996
  let deletedFolders = 0;
1985
- for (const folder of trashedFolders) {
1997
+ for (const folderId of orderedIds) {
1998
+ const folder = trashedFolders.find((candidate) => candidate.id === folderId);
1986
1999
  const stillHasFiles = await this.files.query(
1987
2000
  userId,
1988
2001
  { folderId: folder.id, trashed: true },
@@ -4970,7 +4983,7 @@ function encryptionCheck(configured) {
4970
4983
  }
4971
4984
 
4972
4985
  // ../../apps/api/src/routes/storage.ts
4973
- var VERSION = "0.2.10";
4986
+ var VERSION = "0.2.12";
4974
4987
  function registerStorageRoutes(app2, container2) {
4975
4988
  app2.get("/api/health", async () => {
4976
4989
  const database = await probeDatabase(container2);