aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-12-11 01:20:17 +0100
committermetamuffin <metamuffin@disroot.org>2025-12-11 01:20:17 +0100
commit6e5f6d9b9c6fedb4ab80190c156595d321d33bbf (patch)
treeb6c2140e744fc3018ad08975afefad40386ebbc6 /web
parente4f865e9da9d6660399e22a6fbeb5b84a749b07a (diff)
downloadjellything-6e5f6d9b9c6fedb4ab80190c156595d321d33bbf.tar
jellything-6e5f6d9b9c6fedb4ab80190c156595d321d33bbf.tar.bz2
jellything-6e5f6d9b9c6fedb4ab80190c156595d321d33bbf.tar.zst
refactor import plugins part 3
Diffstat (limited to 'web')
-rw-r--r--web/script/import_live.ts64
-rw-r--r--web/script/log_live.ts (renamed from web/script/log_stream.ts)0
-rw-r--r--web/script/main.ts3
3 files changed, 66 insertions, 1 deletions
diff --git a/web/script/import_live.ts b/web/script/import_live.ts
new file mode 100644
index 0000000..cc8c846
--- /dev/null
+++ b/web/script/import_live.ts
@@ -0,0 +1,64 @@
+/*
+ This file is part of jellything (https://codeberg.org/metamuffin/jellything)
+ which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
+ Copyright (C) 2025 metamuffin <metamuffin.org>
+*/
+/// <reference lib="dom" />
+
+import { OVar } from "./jshelper/mod.ts";
+import { e } from "./jshelper/src/element.ts";
+
+interface ImportProgress {
+ total_items: number
+ finished_items: number
+ tasks: string[]
+}
+
+function progress_bar(progress: OVar<number>, text: OVar<string>): HTMLElement {
+ const bar_inner = e("div")
+ bar_inner.style.height = "100%"
+ bar_inner.style.backgroundColor = "#444"
+ bar_inner.style.position = "absolute"
+ bar_inner.style.top = "0px"
+ bar_inner.style.left = "0px"
+ bar_inner.style.zIndex = "2"
+ const bar_text = e("div")
+ bar_text.style.position = "absolute"
+ bar_text.style.top = "0px"
+ bar_text.style.left = "0px"
+ bar_text.style.color = "white"
+ bar_text.style.zIndex = "3"
+ const bar_outer = e("div", bar_inner, bar_text)
+ bar_outer.style.position = "relative"
+ bar_outer.style.width = "100%"
+ bar_outer.style.height = "2em"
+ bar_outer.style.backgroundColor = "black"
+ bar_outer.style.borderRadius = "5px"
+ progress.onchangeinit(v => bar_inner.style.width = `${v * 100}%`)
+ text.onchangeinit(v => bar_text.textContent = v)
+ return bar_outer
+}
+
+globalThis.addEventListener("DOMContentLoaded", () => {
+ if (!document.getElementById("admin_import")) return
+ const el = document.getElementById("admin_import")!
+
+ const ws = new WebSocket(`/admin/import`)
+ ws.onopen = () => console.log("live log connected");
+ ws.onclose = () => console.log("live log disconnected");
+ ws.onerror = e => console.log("live log ws error", e);
+
+
+ const progress = new OVar(0)
+ const text = new OVar("")
+ const pre = e("pre")
+ el.append(progress_bar(progress, text), pre)
+
+ ws.onmessage = msg => {
+ if (msg.data == "done") return location.reload()
+ const p: ImportProgress = JSON.parse(msg.data)
+ text.value = `${p.finished_items} / ${p.total_items}`
+ progress.value = p.finished_items / p.total_items
+ pre.textContent = p.tasks.map((e, i) => `thread ${("#" + i).padStart(3)}: ${e}`).join("\n")
+ }
+})
diff --git a/web/script/log_stream.ts b/web/script/log_live.ts
index 053c110..053c110 100644
--- a/web/script/log_stream.ts
+++ b/web/script/log_live.ts
diff --git a/web/script/main.ts b/web/script/main.ts
index d7a36cb..d5905d3 100644
--- a/web/script/main.ts
+++ b/web/script/main.ts
@@ -8,4 +8,5 @@ import "./player/mod.ts"
import "./transition.ts"
import "./backbutton.ts"
import "./dangerbutton.ts"
-import "./log_stream.ts"
+import "./log_live.ts"
+import "./import_live.ts"