Add tryDeleteFile utility for safe file deletion in file-upload-tus.ts (#290)

This commit is contained in:
Hakan Shehu
2026-01-13 23:12:25 +01:00
committed by GitHub
parent d4c1af8ce1
commit 173c6358c5

View File

@@ -17,7 +17,13 @@ import { mapNode, updateNode } from '@colanode/server/lib/nodes';
import { storage } from '@colanode/server/lib/storage';
import { RedisLocker } from '@colanode/server/lib/storage/tus/redis-locker';
const tusStore = storage.tusStore;
const tryDeleteFile = async (path: string): Promise<void> => {
try {
await storage.delete(path);
} catch {
// Best effort cleanup - ignore errors if file doesn't exist or can't be deleted
}
};
export const fileUploadTusRoute: FastifyPluginCallbackZod = (
instance,
@@ -85,7 +91,7 @@ export const fileUploadTusRoute: FastifyPluginCallbackZod = (
const tusServer = new Server({
path: '/tus',
datastore: tusStore,
datastore: storage.tusStore,
locker:
config.storage.tus.locker.type === 'redis'
? new RedisLocker(redis, config.storage.tus.locker.prefix)
@@ -218,7 +224,7 @@ export const fileUploadTusRoute: FastifyPluginCallbackZod = (
}
const tusInfoPath = `${path}.info`;
await storage.delete(tusInfoPath);
await tryDeleteFile(tusInfoPath);
return {
status_code: 200,