This commit is contained in:
Vinci 2026-05-10 14:51:46 +08:00 committed by GitHub
commit f7038ba2b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,15 +59,22 @@ class InternalRoutes:
directory = get_directory_by_type(directory_type) directory = get_directory_by_type(directory_type)
def is_visible_file(entry: os.DirEntry) -> bool: def walk_visible_files(base: str):
"""Filter out hidden files (e.g., .DS_Store on macOS).""" """Recursively yield (rel_path, mtime) for all non-hidden files."""
return entry.is_file() and not entry.name.startswith('.') for dirpath, dirnames, filenames in os.walk(base):
dirnames[:] = [d for d in dirnames if not d.startswith('.')]
for f in filenames:
if f.startswith('.'):
continue
full = os.path.join(dirpath, f)
rel = os.path.relpath(full, base).replace('\\', '/')
try:
yield rel, os.stat(full).st_mtime
except OSError:
continue
sorted_files = sorted( sorted_files = sorted(walk_visible_files(directory), key=lambda x: -x[1])
(entry for entry in os.scandir(directory) if is_visible_file(entry)), return web.json_response([path for path, _ in sorted_files], status=200)
key=lambda entry: -entry.stat().st_mtime
)
return web.json_response([f"{entry.name} [{directory_type}]" for entry in sorted_files], status=200)
def get_app(self): def get_app(self):