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,
|
||||
|
||||
Reference in New Issue
Block a user