@lacrous/omnicloud 0.2.12 → 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/dist/index.cjs +23 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +23 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/server/index.js +24 -9
package/dist/index.d.cts
CHANGED
|
@@ -809,11 +809,13 @@ interface StorageStats {
|
|
|
809
809
|
*
|
|
810
810
|
* PENDING accepted, Telegram write not started
|
|
811
811
|
* UPLOADING Telegram write in progress or its outcome unknown
|
|
812
|
+
* COMMITTING the stored object is being turned into a file record by exactly one
|
|
813
|
+
* request, which holds this state as an exclusive claim
|
|
812
814
|
* COMPLETED Telegram object stored and file record committed; result is final
|
|
813
815
|
* FAILED Telegram write definitively failed; the operation may be retried
|
|
814
816
|
* under a new id
|
|
815
817
|
*/
|
|
816
|
-
type UploadOperationStatus = "PENDING" | "UPLOADING" | "COMPLETED" | "FAILED";
|
|
818
|
+
type UploadOperationStatus = "PENDING" | "UPLOADING" | "COMMITTING" | "COMPLETED" | "FAILED";
|
|
817
819
|
|
|
818
820
|
/**
|
|
819
821
|
* Repository interfaces. The application depends on these, not on a specific
|
package/dist/index.d.ts
CHANGED
|
@@ -809,11 +809,13 @@ interface StorageStats {
|
|
|
809
809
|
*
|
|
810
810
|
* PENDING accepted, Telegram write not started
|
|
811
811
|
* UPLOADING Telegram write in progress or its outcome unknown
|
|
812
|
+
* COMMITTING the stored object is being turned into a file record by exactly one
|
|
813
|
+
* request, which holds this state as an exclusive claim
|
|
812
814
|
* COMPLETED Telegram object stored and file record committed; result is final
|
|
813
815
|
* FAILED Telegram write definitively failed; the operation may be retried
|
|
814
816
|
* under a new id
|
|
815
817
|
*/
|
|
816
|
-
type UploadOperationStatus = "PENDING" | "UPLOADING" | "COMPLETED" | "FAILED";
|
|
818
|
+
type UploadOperationStatus = "PENDING" | "UPLOADING" | "COMMITTING" | "COMPLETED" | "FAILED";
|
|
817
819
|
|
|
818
820
|
/**
|
|
819
821
|
* Repository interfaces. The application depends on these, not on a specific
|
package/dist/index.js
CHANGED
|
@@ -1409,7 +1409,7 @@ var noopActivityRecorder = {
|
|
|
1409
1409
|
// ../core/src/utils/filename.ts
|
|
1410
1410
|
function sanitizeFileName(name) {
|
|
1411
1411
|
const base = name.split(/[/\\]/).pop() ?? name;
|
|
1412
|
-
const cleaned = base.replace(/[\u0000-\u001f\u007f]/g, "").replace(/[<>:"|?*]/g, "_").trim();
|
|
1412
|
+
const cleaned = base.replace(/[\u0000-\u001f\u007f-\u009f]/g, "").replace(/[\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "").replace(/[<>:"|?*]/g, "_").trim();
|
|
1413
1413
|
if (!cleaned || cleaned === "." || cleaned === "..") return "";
|
|
1414
1414
|
return cleaned.slice(0, 255);
|
|
1415
1415
|
}
|
|
@@ -1479,6 +1479,7 @@ var FileService = class {
|
|
|
1479
1479
|
const record = await this.performUpload(userId, input, {
|
|
1480
1480
|
onStored: async (stored) => {
|
|
1481
1481
|
await operations.update(op.id, { telegramMessageId: Number(stored.messageId) });
|
|
1482
|
+
await operations.claim(op.id, "UPLOADING", "COMMITTING");
|
|
1482
1483
|
}
|
|
1483
1484
|
});
|
|
1484
1485
|
await operations.update(op.id, { status: "COMPLETED", fileId: record.id });
|
|
@@ -1519,13 +1520,27 @@ var FileService = class {
|
|
|
1519
1520
|
const mimeType = mimeFromFilename(name);
|
|
1520
1521
|
const size = op.size ?? input.spooled?.size ?? input.data?.byteLength ?? 0;
|
|
1521
1522
|
const sha256 = op.sha256 ?? input.spooled?.sha256 ?? sha256Hex(input.data ?? Buffer.alloc(0));
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1523
|
+
const claimed = await operations.claim(op.id, "UPLOADING", "COMMITTING");
|
|
1524
|
+
if (!claimed) {
|
|
1525
|
+
const current = await operations.findByOperationId(userId, op.operationId);
|
|
1526
|
+
if (current?.status === "COMPLETED" && current.fileId) {
|
|
1527
|
+
return this.get(userId, current.fileId);
|
|
1528
|
+
}
|
|
1529
|
+
throw new ConflictError("This upload is being committed by another request. Retry shortly.");
|
|
1530
|
+
}
|
|
1531
|
+
let record;
|
|
1532
|
+
try {
|
|
1533
|
+
record = await this.commitRecord(userId, input, {
|
|
1534
|
+
name,
|
|
1535
|
+
mimeType,
|
|
1536
|
+
size,
|
|
1537
|
+
sha256,
|
|
1538
|
+
telegramMessageId: op.telegramMessageId
|
|
1539
|
+
});
|
|
1540
|
+
} catch (error) {
|
|
1541
|
+
await operations.claim(op.id, "COMMITTING", "UPLOADING");
|
|
1542
|
+
throw error;
|
|
1543
|
+
}
|
|
1529
1544
|
await operations.update(op.id, { status: "COMPLETED", fileId: record.id });
|
|
1530
1545
|
return record;
|
|
1531
1546
|
}
|