fix: only on binary distribution, upload resume not working if attempted after a server restart, with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING in console
Massimo Melina committed
May 18, 2025 at 20:40 UTC
b161007b257c470ed22ee8c413fcf69e4c9fdb85
2 files changed
+3
-7
package.json
+1
-1
@@ -96,7 +96,7 @@
96
"tssrp6a": "^3.0.0",
97
"unzip-stream": "^0.3.4",
98
"valtio": "^1.10.3",
99
- "xxhash-wasm": "^1.1.0",
99
+ "xxhashjs": "^0.2.2",
100
"yaml": "^2.0.0-10"
101
},
102
"devDependencies": {
src/upload.ts
+2
-6
@@ -24,6 +24,7 @@ import { expiringCache } from './expiringCache'
24
import { onProcessExit } from './first'
25
import { once, Transform } from 'stream'
26
import { utimes } from 'node:fs/promises'
27
+import XXH from 'xxhashjs'
28
29
export const deleteUnfinishedUploadsAfter = defineConfig<undefined|number>('delete_unfinished_uploads_after', 86_400)
30
export const minAvailableMb = defineConfig('min_available_mb', 100)
@@ -52,7 +53,7 @@ function setUploadMeta(path: string, ctx: Koa.Context) {
53
}
54
55
async function calcHash(fn: string, limit=Infinity) {
55
- const hash = await makeXXHash()
56
+ const hash = XXH.h32()
57
const stream = new Transform({
58
transform(chunk, enc, done) {
59
hash.update(chunk)
@@ -66,11 +67,6 @@ async function calcHash(fn: string, limit=Infinity) {
67
return hash.digest().toString(16)
68
}
69
69
-async function makeXXHash(seed?: string) {
70
- const lib = await import('xxhash-wasm')
71
- return (await lib.default()).create32(seed ? parseInt(seed, 16) : undefined)
72
-}
73
-
70
const diskSpaceCache = expiringCache<ReturnType<typeof getDiskSpaceSync>>(3_000) // invalidate shortly
71
const uploadingFiles = new Set()
72
// stay sync because we use this function with formidable()