@valentinkolb/filegate 2.3.2 → 2.3.3

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": "@valentinkolb/filegate",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -86,7 +86,12 @@ const assembleFile = async (meta: UploadMeta): Promise<string | null> => {
86
86
  await semaphore.acquire();
87
87
 
88
88
  try {
89
+ // Check if assembly was already completed by another request while we waited
89
90
  const chunks = await getUploadedChunks(meta.uploadId);
91
+ if (chunks.length === 0) {
92
+ // Chunks were cleaned up - assembly was already completed
93
+ return null;
94
+ }
90
95
  if (chunks.length !== meta.totalChunks) return "missing chunks";
91
96
 
92
97
  // Verify all expected chunk indices are present (0 to totalChunks-1)
@@ -110,6 +115,14 @@ const assembleFile = async (meta: UploadMeta): Promise<string | null> => {
110
115
  for (let i = 0; i < meta.totalChunks; i++) {
111
116
  // Stream each chunk instead of loading entirely into memory
112
117
  const chunkFile = Bun.file(chunkPath(meta.uploadId, i));
118
+
119
+ // Verify chunk exists before streaming
120
+ if (!(await chunkFile.exists())) {
121
+ writer.end();
122
+ await rm(pathResult.realPath).catch(() => {});
123
+ return `chunk ${i} not found during assembly`;
124
+ }
125
+
113
126
  for await (const data of chunkFile.stream()) {
114
127
  hasher.update(data);
115
128
  writer.write(data);