@lacrous/omnicloud 0.2.13 → 0.2.14

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.13",
3
+ "version": "0.2.14",
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.13",
52
- "@omnicloud/shared": "0.2.13",
53
- "@omnicloud/telegram": "0.2.13",
51
+ "@omnicloud/core": "0.2.14",
52
+ "@omnicloud/shared": "0.2.14",
53
+ "@omnicloud/telegram": "0.2.14",
54
54
  "@types/node": "^22.10.0",
55
55
  "esbuild": "0.25.12",
56
56
  "tsup": "^8.3.0",
package/server/index.js CHANGED
@@ -1137,6 +1137,7 @@ var FileService = class {
1137
1137
  const record = await this.performUpload(userId, input, {
1138
1138
  onStored: async (stored) => {
1139
1139
  await operations.update(op.id, { telegramMessageId: Number(stored.messageId) });
1140
+ await operations.claim(op.id, "UPLOADING", "COMMITTING");
1140
1141
  }
1141
1142
  });
1142
1143
  await operations.update(op.id, { status: "COMPLETED", fileId: record.id });
@@ -1177,13 +1178,27 @@ var FileService = class {
1177
1178
  const mimeType = mimeFromFilename(name);
1178
1179
  const size = op.size ?? input.spooled?.size ?? input.data?.byteLength ?? 0;
1179
1180
  const sha256 = op.sha256 ?? input.spooled?.sha256 ?? sha256Hex(input.data ?? Buffer.alloc(0));
1180
- const record = await this.commitRecord(userId, input, {
1181
- name,
1182
- mimeType,
1183
- size,
1184
- sha256,
1185
- telegramMessageId: op.telegramMessageId
1186
- });
1181
+ const claimed = await operations.claim(op.id, "UPLOADING", "COMMITTING");
1182
+ if (!claimed) {
1183
+ const current = await operations.findByOperationId(userId, op.operationId);
1184
+ if (current?.status === "COMPLETED" && current.fileId) {
1185
+ return this.get(userId, current.fileId);
1186
+ }
1187
+ throw new ConflictError("This upload is being committed by another request. Retry shortly.");
1188
+ }
1189
+ let record;
1190
+ try {
1191
+ record = await this.commitRecord(userId, input, {
1192
+ name,
1193
+ mimeType,
1194
+ size,
1195
+ sha256,
1196
+ telegramMessageId: op.telegramMessageId
1197
+ });
1198
+ } catch (error) {
1199
+ await operations.claim(op.id, "COMMITTING", "UPLOADING");
1200
+ throw error;
1201
+ }
1187
1202
  await operations.update(op.id, { status: "COMPLETED", fileId: record.id });
1188
1203
  return record;
1189
1204
  }
@@ -4983,7 +4998,7 @@ function encryptionCheck(configured) {
4983
4998
  }
4984
4999
 
4985
5000
  // ../../apps/api/src/routes/storage.ts
4986
- var VERSION = "0.2.13";
5001
+ var VERSION = "0.2.14";
4987
5002
  function registerStorageRoutes(app2, container2) {
4988
5003
  app2.get("/api/health", async () => {
4989
5004
  const database = await probeDatabase(container2);