summaryrefslogtreecommitdiff
path: root/static/src/connector.js
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2025-12-09 22:16:48 -0600
committerTim Keller <tjk@tjkeller.xyz>2025-12-09 22:16:57 -0600
commit3e7fdfb6c8a50c59ac933f701526ad1815dded92 (patch)
treed2c699ff93e23d0fe45845a4c2dc05d820ec317b /static/src/connector.js
parent39738b84e9164b0f2d01f22440548c4393160013 (diff)
downloadimmich-frame-0.3.0.tar.xz
immich-frame-0.3.0.zip
refactor codebase. Reorganize file structure. Replace webpack for vite. Setup setuptools for application. Move closer to distributable appv0.3.0
Diffstat (limited to 'static/src/connector.js')
-rw-r--r--static/src/connector.js92
1 files changed, 0 insertions, 92 deletions
diff --git a/static/src/connector.js b/static/src/connector.js
deleted file mode 100644
index 9568dc8..0000000
--- a/static/src/connector.js
+++ /dev/null
@@ -1,92 +0,0 @@
-import io from "socket.io-client"
-
-class APIConnector {
- constructor(url) {
- this.url = url ?? ""
- this.socket = io(url)
-
- this.assetIndex = 0
- this.movement = 0
- this.assets = null
- this.currentAsset = null
- this.seekCallbacks = []
-
- this.socket.on("seek", e => {
- this.assetIndex = e.asset_index
- this.movement = e.movement
- this.assets = e.assets
- this.currentAsset = e.current_asset
- for (const cb of this.seekCallbacks)
- cb()
- })
-
- this.downloadAnchor = document.createElement("a")
- this.downloadAnchor.classList = "hidden"
- document.body.appendChild(this.downloadAnchor)
- }
-
- fetch(endpoint, c) {
- return fetch(this.url + "/api" + endpoint, c ?? {})
- .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)
- return null
- })
- }
-
- async assetDownload(key) {
- const filename = await this.assetFileName(key)
- fetch(this.assetFullsizeSrc(key))
- .then(response => {
- if (!response.ok)
- throw new Error(`HTTP error! Status: ${response.status}`)
- return response.blob()
- })
- .then(blob => {
- const blobUrl = URL.createObjectURL(blob)
- this.downloadAnchor.href = blobUrl
- this.downloadAnchor.download = filename
-
- this.downloadAnchor.click()
- URL.revokeObjectURL(blobUrl)
- })
- .catch(error => {
- console.error("Fetch error:", error)
- return null
- })
- }
-
- post(endpoint, body) {
- return this.fetch(endpoint, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(body),
- })
- }
-
- seek(increment) {
- this.socket.emit("seek", increment)
- }
-
- fetchAlbums() { return this.fetch("/albums") }
- fetchConfig() { return this.fetch("/config") }
- updateAlbums(albums) { return this.post("/albums/update", albums) }
- updateConfig(config) { return this.post("/config/update", config) }
-
- albumSrc(key) { return `${this.url}/api/redirect/albums/${key}` }
-
- assetPreviewSrc(key) { return `${this.url}/api/asset/${key}` }
- assetThumbnailSrc(key) { return `${this.url}/api/asset/${key}/thumbnail` }
- assetFullsizeSrc(key) { return `${this.url}/api/asset/${key}/fullsize` }
- assetFileName(key) { return this.fetch(`/asset/${key}/filename`).then(d => d.filename) }
-}
-
-const apiConnector = new APIConnector(window.location.origin)
-export default apiConnector