diff options
| author | Morgana <Morgana@icolotl.com> | 2026-09-16 14:42:36 -0500 |
|---|---|---|
| committer | Morgana <Morgana@icolotl.com> | 2026-09-16 14:42:36 -0500 |
| commit | a7cbcf6efdc7c50814374b22d41a05f69eeb1ef4 (patch) | |
| tree | a289c89d6d1216edcd8ed78e0a4cdd6ff9205936 | |
| parent | 971a7225d784a624b4ceb56b9e367d6f33625482 (diff) | |
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | ivt.py | 19 | ||||
| -rw-r--r-- | static/script/main.js | 17 |
3 files changed, 17 insertions, 22 deletions
@@ -1,4 +1,5 @@ __pycache__/ .venv/ data/ -music/
\ No newline at end of file +music/ +static/dl/
\ No newline at end of file @@ -22,9 +22,12 @@ from argparse import ArgumentParser, ArgumentError, Namespace, _SubParsersAction from typing import Literal import sqlite3 from hashlib import scrypt -from os import urandom, listdir +from os import urandom, listdir, mkdir, link +from os.path import isdir +from uuid import uuid4, UUID from hmac import compare_digest from colorsys import rgb_to_hsv +from shutil import rmtree import requests from websockets.asyncio.server import serve, ServerConnection @@ -51,6 +54,9 @@ class IVTModel: cur.execute("SELECT value FROM config WHERE key = 'light_url'") self.light_url = cur.fetchone()[0] + if not isdir("static/dl"): + mkdir("static/dl") + async def newSession(self, websocket: ServerConnection) -> None: name = self.genNewAnonName() session = IVTSession(self, name, websocket) @@ -94,6 +100,7 @@ class IVTModel: await server.serve_forever() except (InterruptedError, asyncio.exceptions.CancelledError): print("Exiting.") + rmtree("static/dl") def makeParser(self) -> ArgumentParser: parser = ArgumentParser( @@ -391,9 +398,9 @@ class IVTSession: await self.send_error("song not found") return await self.send_text(f"Playing {album}/{song}...") - with open(f"music/{album}/{song}.mp3", "rb") as musicfile: - await self.send_prelude("music") - await self.socket.send(musicfile.read()) + songuuid = uuid4() + link(f"music/{album}/{song}.mp3", f"static/dl/{songuuid}.mp3") + await self.send_music(songuuid) async def send_password_request( self, pwdreturn: str, pwddata: Namespace, prompt: str, text: str @@ -413,8 +420,8 @@ class IVTSession: async def send_action(self, action: str) -> None: await self.socket.send(dumps({"act": "action", "action": action})) - async def send_prelude(self, action: str) -> None: - await self.socket.send(dumps({"act": "prelude", "action": action})) + async def send_music(self, uuid: UUID) -> None: + await self.socket.send(dumps({"act": "music", "uuid": str(uuid)})) async def send_display(self, msg) -> None: await self.socket.send(dumps({"act": "display", "msg": msg})) diff --git a/static/script/main.js b/static/script/main.js index c023851..f6534e3 100644 --- a/static/script/main.js +++ b/static/script/main.js @@ -72,7 +72,6 @@ class IVTClient { this.username = null; this.pwdreturn = false; this.oldprompt = null; - this.prelude = null; this.printTextCLS(BANNER, "term-bold term-centered"); this.stdinBox.addEventListener("submit", (event) => { event.preventDefault(); @@ -104,14 +103,6 @@ class IVTClient { this.stdinBtn.disabled = true; }) this.socket.addEventListener("message", (event) => { - if (this.prelude) { - var fxn = this["on_" + this.prelude + "_prelude"]; - if (fxn) { - fxn.call(this, event.data) - } - this.prelude = null; - return - } var data = JSON.parse(event.data); var fxn = this["on_" + data.act + "_msg"]; if (fxn) { @@ -157,13 +148,9 @@ class IVTClient { } } - on_prelude_msg(data) { - this.prelude = data.action; - } - - async on_music_prelude(data) { + async on_music_msg(data) { var elem = document.createElement("audio"); - elem.src = window.URL.createObjectURL(data); + elem.src = `dl/${data.uuid}.mp3`; elem.controls = true; elem.autoplay = true; this.stdout.append(elem); |
