KajetanNiewczas commited on
Commit ·
0f30dc5
1
Parent(s): cceba7f
Upload safe file names
Browse files
src/interface/upload_files.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
"""Module to handle file uploads via UI."""
|
| 2 |
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
import shutil
|
| 5 |
from ..telemetry.logging_utils import Logger
|
|
@@ -30,7 +31,10 @@ def upload_files(files: list) -> tuple[str, list[str]]:
|
|
| 30 |
for file in files:
|
| 31 |
try:
|
| 32 |
temp_path = Path(file.name)
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
target_path = upload_dir / file_name
|
| 35 |
|
| 36 |
if target_path.exists():
|
|
|
|
| 1 |
"""Module to handle file uploads via UI."""
|
| 2 |
|
| 3 |
+
import re
|
| 4 |
from pathlib import Path
|
| 5 |
import shutil
|
| 6 |
from ..telemetry.logging_utils import Logger
|
|
|
|
| 31 |
for file in files:
|
| 32 |
try:
|
| 33 |
temp_path = Path(file.name)
|
| 34 |
+
# Prepare the safe file name
|
| 35 |
+
safe_name = re.sub(r'[^a-zA-Z0-9_]', '_', temp_path.stem)
|
| 36 |
+
safe_name = re.sub(r'_+', '_', safe_name)
|
| 37 |
+
file_name = f"{safe_name}{temp_path.suffix}"
|
| 38 |
target_path = upload_dir / file_name
|
| 39 |
|
| 40 |
if target_path.exists():
|