summaryrefslogtreecommitdiff
path: root/src/connector.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/connector.js')
-rw-r--r--src/connector.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/connector.js b/src/connector.js
new file mode 100644
index 0000000..1fa513b
--- /dev/null
+++ b/src/connector.js
@@ -0,0 +1,39 @@
+class APIConnector {
+ constructor(url) {
+ this.url = url ?? ""
+ }
+
+ #fetch(endpoint) {
+ return fetch(this.url + "/api" + endpoint)
+ }
+
+ fetch(endpoint) {
+ return this.#fetch(endpoint)
+ .then(response => {
+ if (!response.ok)
+ throw new Error(`HTTP error! Status: ${response.status}`)
+ return response.json()
+ })
+ .then(data => {
+ return data
+ })
+ .catch(error => {
+ console.error("Fetch error:", error)
+ })
+ }
+
+ seek(increment) {
+ return this.fetch(`/seek?increment=${increment}`)
+ }
+
+ fetchAlbums() {
+ return this.fetch("/albums/get")
+ }
+
+ albumThumbSrc(key) {
+ return `${this.url}/api/albums/thumb/${key}`
+ }
+}
+
+const apiConnector = new APIConnector("http://localhost:5000")
+export default apiConnector