From 51be71d8943f6e5e0c4b28358f227860c73d53a7 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sun, 11 May 2025 13:35:06 -0500 Subject: work --- src/connector.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/connector.js (limited to 'src/connector.js') 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 -- cgit v1.2.3