fix(file-manager): repair uploads and shared SFTP access
Build and publish Docker image / build-and-publish (push) Successful in 12s

This commit is contained in:
wfalkowski committed 2026-10-23 20:50:13 +00:00
1 parent 4c2f5f2c01
commit 2fcd0c3ef9
6 files changed
+275 -9

No files matched your search

+37 -5
View File
@@ -2060,7 +2060,13 @@ async def handle_upload_file(client_id, data):
return
# Use write_file_binary for all files to support binary files
success = k8s_manager.write_file_binary(namespace, pods[0], file_path, file_content)
success = k8s_manager.write_file_binary(
namespace,
pods[0],
file_path,
file_content,
container_name=server_id,
)
if success:
await send_message(client_id, {
@@ -2088,7 +2094,14 @@ async def handle_start_chunked_upload(client_id, data):
total_chunks = data.get('totalChunks')
total_size = data.get('totalSize')
if not server_id or not file_path or not total_chunks:
if (
not server_id
or not file_path
or not isinstance(total_chunks, int)
or total_chunks < 1
or not isinstance(total_size, int)
or total_size < 0
):
await send_message(client_id, {
'type': 'upload_error',
'error': 'Server ID, file path, and total chunks required',
@@ -2174,7 +2187,14 @@ async def handle_upload_file_chunk(client_id, data):
chunk_data = data.get('chunkData')
total_chunks = data.get('totalChunks')
if not server_id or not file_path or chunk_index is None or not chunk_data:
if (
not server_id
or not file_path
or not isinstance(chunk_index, int)
or chunk_index < 0
or chunk_data is None
or not isinstance(chunk_data, str)
):
await send_message(client_id, {
'type': 'upload_error',
'error': 'Missing required chunk data',
@@ -2205,6 +2225,8 @@ async def handle_upload_file_chunk(client_id, data):
return
upload_info = chunked_uploads[upload_id]
if chunk_index >= upload_info['total_chunks']:
raise ValueError('Chunk index is outside the upload session')
temp_file_path = upload_info['temp_file']
# Ensure CHUNK_UPLOAD_DIR and parent directory exist (in case they were cleaned up or don't exist)
@@ -2219,7 +2241,7 @@ async def handle_upload_file_chunk(client_id, data):
logger.warning(f"Chunk {chunk_index} already received for upload {upload_id}, skipping")
else:
# Decode base64 chunk and write directly to disk file
chunk_bytes = base64.b64decode(chunk_data)
chunk_bytes = base64.b64decode(chunk_data, validate=True)
# Write chunk to temporary file at correct position
# We need to write chunks in order, so we'll append and sort later, or use a different approach
@@ -2321,6 +2343,10 @@ async def handle_upload_file_chunk(client_id, data):
out_f.write(chunk_data)
bytes_written += read_size
expected_size = upload_info.get('total_size')
if expected_size is not None and os.path.getsize(reassembled_file_path) != expected_size:
raise ValueError('Uploaded file size does not match the declared size')
# Clear chunk positions to free memory
chunk_positions.clear()
@@ -2351,7 +2377,13 @@ async def handle_upload_file_chunk(client_id, data):
file_path = validate_path_for_server(server_id, file_path)
# Upload the file using streaming method (reads from disk, doesn't load into memory)
success = k8s_manager.write_file_binary_from_disk(namespace, pods[0], file_path, reassembled_file_path)
success = k8s_manager.write_file_binary_from_disk(
namespace,
pods[0],
file_path,
reassembled_file_path,
container_name=server_id,
)
if success:
await send_message(client_id, {