From 63bb234f668eeab3d43ce57ce98842115b0fd8b0 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Mon, 5 Oct 2026 10:22:17 +0200 Subject: Skeleton implementation of song upload --- solo-tool-project/src/solo_tool/session_manager.py | 3 +++ solo-tool-project/src/solo_tool/storage.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'solo-tool-project') diff --git a/solo-tool-project/src/solo_tool/session_manager.py b/solo-tool-project/src/solo_tool/session_manager.py index 96b100a..5dcb91f 100644 --- a/solo-tool-project/src/solo_tool/session_manager.py +++ b/solo-tool-project/src/solo_tool/session_manager.py @@ -50,3 +50,6 @@ class SessionManager(): def saveRecording(self, recording: Path, destination: str) -> None: self._backend.writeRecording(recording, destination) + + def uploadSong(self, song: Path, destination: str) -> None: + self._backend.writeSong(song, destination) diff --git a/solo-tool-project/src/solo_tool/storage.py b/solo-tool-project/src/solo_tool/storage.py index d07ba25..4d82504 100644 --- a/solo-tool-project/src/solo_tool/storage.py +++ b/solo-tool-project/src/solo_tool/storage.py @@ -24,6 +24,10 @@ class StorageBackend(Protocol): def writeRecording(self, recording: Path, destination: str) -> None: raise NotImplementedError + @abstractmethod + def writeSong(self, song: Path, destination: str) -> None: + raise NotImplementedError + @abstractmethod def listSongs(self) -> list[str]: raise NotImplementedError @@ -47,6 +51,9 @@ class FileSystemStorageBackend(StorageBackend): def writeRecording(self, recording: Path, destination: str) -> None: pass + def writeSong(self, song: Path, destination: str) -> None: + pass + def listSongs(self) -> list[str]: return [str(Path(f).absolute()) for f in glob(str(self._storagePath / "songs" / "*"))] @@ -77,6 +84,11 @@ class FileBrowserStorageBackend(StorageBackend): with open(recording, "rb") as file: self._request("POST", url, {"Content-Type" : "audio/mpeg"}, data=file) + def writeSong(self, song: Path, destination: str) -> None: + url = f"{self._baseUrl}/api/resources/songs/{destination}" + with open(song, "rb") as file: + self._request("POST", url, {}, data=file) + def listSongs(self) -> list[str]: url = f"{self._baseUrl}/api/resources/songs" response = self._request("GET", url) -- cgit v1.2.3