feat: upload - deel 03
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -49,8 +50,6 @@ class FileDiscoveryService:
|
||||
iterator = target.iterdir()
|
||||
|
||||
for entry in iterator:
|
||||
if len(files) >= limit:
|
||||
break
|
||||
if not entry.is_file():
|
||||
continue
|
||||
ext = entry.suffix.lower()
|
||||
@@ -74,6 +73,10 @@ class FileDiscoveryService:
|
||||
}
|
||||
)
|
||||
|
||||
files.sort(key=lambda item: self._natural_sort_key(item.get("relative_path", "")))
|
||||
if len(files) > limit:
|
||||
files = files[:limit]
|
||||
|
||||
return {
|
||||
"root_id": root["id"],
|
||||
"root_path": str(root["path"]),
|
||||
@@ -83,6 +86,10 @@ class FileDiscoveryService:
|
||||
"items": files,
|
||||
}
|
||||
|
||||
def _natural_sort_key(self, value: str):
|
||||
text = str(value or "")
|
||||
return [int(part) if part.isdigit() else part.lower() for part in re.split(r"(\d+)", text)]
|
||||
|
||||
def list_folders(
|
||||
self,
|
||||
root_id: str,
|
||||
|
||||
@@ -736,6 +736,8 @@ class SessionService:
|
||||
proposed_filename=proposed_filename,
|
||||
allowed_roots=allowed_roots,
|
||||
)
|
||||
if source_path_str and source_path == destination_path:
|
||||
errors = [err for err in errors if err != "source and destination paths are equal"]
|
||||
|
||||
status = "ready"
|
||||
if errors:
|
||||
@@ -777,17 +779,25 @@ class SessionService:
|
||||
for item in preflight_items:
|
||||
source_path = Path(item["source_path"])
|
||||
destination_path = Path(item["destination_path"])
|
||||
os.replace(str(source_path), str(destination_path))
|
||||
rename_needed = source_path != destination_path
|
||||
|
||||
if rename_needed:
|
||||
os.replace(str(source_path), str(destination_path))
|
||||
target_path = destination_path
|
||||
item_status = "renamed"
|
||||
else:
|
||||
target_path = source_path
|
||||
item_status = "unchanged"
|
||||
|
||||
file_date_status, file_date_detail = self._apply_file_date_after_rename(
|
||||
enabled=set_file_date_to_first_aired,
|
||||
aired_value=aired_by_index.get(int(item["index"])),
|
||||
destination_path=destination_path,
|
||||
destination_path=target_path,
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
**item,
|
||||
"status": "renamed",
|
||||
"status": item_status,
|
||||
"errors": [],
|
||||
"file_date_status": file_date_status,
|
||||
"file_date_detail": file_date_detail,
|
||||
|
||||
Reference in New Issue
Block a user