mirror of
https://github.com/MrPatben8/konduktor.git
synced 2026-11-27 10:22:51 +01:00
Improved file browser
This commit is contained in:
1 parent
8d11acd783
commit
93ec2ef425
10 files changed
+540
-204
No files matched your search
@@ -17,7 +17,7 @@ from . import __version__, history, prefs
|
||||
from .app_state import STATE
|
||||
from .core import auto_hotcues as ah
|
||||
from . import importer
|
||||
from .core import registry
|
||||
from .core import places, registry
|
||||
from .core.adapter import (
|
||||
AdapterError,
|
||||
InvalidCommand,
|
||||
@@ -45,6 +45,7 @@ from .schemas import (
|
||||
FileTagOutcome,
|
||||
FsEntry,
|
||||
FsListing,
|
||||
FsPlace,
|
||||
AddGridMarker,
|
||||
GridMarkerEdit,
|
||||
ReplaceGrid,
|
||||
@@ -245,6 +246,46 @@ def patch_prefs(patch: dict) -> dict:
|
||||
return prefs.update_prefs(patch)
|
||||
|
||||
|
||||
@app.get("/api/fs/places", response_model=list[FsPlace])
|
||||
def fs_places(platform: str | None = None) -> list[FsPlace]:
|
||||
"""Sidebar shortcuts for the file browser: the user's folders, then drives.
|
||||
|
||||
Answered by the server because only it can stat a filesystem, and re-asked
|
||||
by the client rather than cached: drives come and go while a dialog is open,
|
||||
and a browser that exists to find a stick you just plugged in has to show it.
|
||||
|
||||
`platform` adds that platform's own default location, which is the likeliest
|
||||
destination when browsing for one of its libraries. Only for platforms whose
|
||||
library sits at a fixed path — a removable one's libraries ARE the drives,
|
||||
which are already listed.
|
||||
"""
|
||||
out = [FsPlace(**p) for p in places.user_places()]
|
||||
out += [FsPlace(**p) for p in places.volume_places()]
|
||||
if platform:
|
||||
try:
|
||||
driver = registry.driver_by_platform(platform)
|
||||
except LibraryNotSupported:
|
||||
driver = None
|
||||
if driver is not None and not getattr(driver, "removable", False):
|
||||
seen = {p.path for p in out}
|
||||
try:
|
||||
found = driver.detect()
|
||||
except OSError:
|
||||
found = []
|
||||
for candidate in found:
|
||||
# The place is the folder CONTAINING the library, because a
|
||||
# place is somewhere you navigate to, not something you pick.
|
||||
folder = Path(candidate["path"]).parent
|
||||
if str(folder) in seen or not folder.is_dir():
|
||||
continue
|
||||
seen.add(str(folder))
|
||||
out.append(
|
||||
FsPlace(kind="library", name=candidate.get("label") or folder.name,
|
||||
path=str(folder))
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
@app.get("/api/fs/list", response_model=FsListing)
|
||||
def fs_list(path: str | None = None, platform: str | None = None) -> FsListing:
|
||||
"""List directories and openable library files for the in-app file browser.
|
||||
|
||||
Reference in new issue
Block a user