From 084f8dba2075aec93d9d88fd7cdd7f67fc63a212 Mon Sep 17 00:00:00 2001 From: retoor Date: Mon, 3 Feb 2025 21:15:18 +0100 Subject: [PATCH] Heavy repair. --- Dockerfile | 1 - DockerfileDrive | 1 - pyproject.toml | 3 ++- setup.cfg | 29 ---------------------------- src/snek/static/app.js | 44 ++++++++++++++++++++++++------------------ 5 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 setup.cfg diff --git a/Dockerfile b/Dockerfile index 9af8e87..ffdc3d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,6 @@ RUN apk add --no-cache \ && apk del .build-deps COPY --from=wkhtmltopdf /bin/wkhtmltopdf /bin/wkhtmltopdf COPY --from=wkhtmltopdf /bin/wkhtmltoimage /bin/wkhtmltoimage -COPY setup.cfg setup.cfg COPY pyproject.toml pyproject.toml COPY src src RUN pip install --upgrade pip diff --git a/DockerfileDrive b/DockerfileDrive index 28f183a..0a03850 100644 --- a/DockerfileDrive +++ b/DockerfileDrive @@ -4,7 +4,6 @@ RUN apk add --no-cache gcc musl-dev linux-headers git openssh #WKHTMLTOPDFNEEDS -COPY setup.cfg setup.cfg COPY pyproject.toml pyproject.toml COPY src src COpy ssh_host_key ssh_host_key diff --git a/pyproject.toml b/pyproject.toml index ed36d70..5a147ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ dependencies = [ "requests", "asyncssh", "emoji", - "pywebpush" + "pywebpush", + "aiofiles" ] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 045fc92..0000000 --- a/setup.cfg +++ /dev/null @@ -1,29 +0,0 @@ -[metadata] -name = snek -version = 1.0.0 -description = Snek chat server -author = retoor -author_email = retoor@molodetz.nl -license = MIT -long_description = file: README.md -long_description_content_type = text/markdown - -[options] -packages = find: -package_dir = - = src -python_requires = >=3.7 -install_requires = - app @ git+https://retoor.molodetz.nl/retoor/app - beautifulsoup4 - gunicorn - imgkit - wkhtmltopdf - shed - -[options.packages.find] -where = src - -[options.entry_points] -console_scripts = - snek.serve = snek.server:cli diff --git a/src/snek/static/app.js b/src/snek/static/app.js index ada9654..06fef95 100644 --- a/src/snek/static/app.js +++ b/src/snek/static/app.js @@ -166,9 +166,10 @@ class Socket extends EventHandler { if (this.ensureTimer) { return this.connect(); } + const me = this; this.ensureTimer = setInterval(() => { - if (this.isConnecting) this.isConnecting = false; - this.connect(); + if (me.isConnecting) me.isConnecting = false; + me.connect(); }, 5000); return this.connect(); } @@ -178,32 +179,34 @@ class Socket extends EventHandler { } connect() { + + const me = this if (this.isConnected || this.isConnecting) { return new Promise((resolve) => { - this.connectPromises.push(resolve); - if (!this.isConnected) resolve(this); + me.connectPromises.push(resolve); + if (!me.isConnecting) resolve(me); }); } this.isConnecting = true; return new Promise((resolve) => { - this.connectPromises.push(resolve); + me.connectPromises.push(resolve); console.debug("Connecting.."); - const ws = new WebSocket(this.url); + const ws = new WebSocket(me.url); ws.onopen = () => { - this.ws = ws; - this.isConnected = true; - this.isConnecting = false; + me.ws = ws; + me.isConnected = true; + me.isConnecting = false; ws.onmessage = (event) => { - this.onData(JSON.parse(event.data)); + me.onData(JSON.parse(event.data)); }; ws.onclose = () => { - this.onClose(); + me.onClose(); }; ws.onerror = () => { - this.onClose(); + me.onClose(); }; - this.connectPromises.forEach(resolver => resolver(this)); + me.connectPromises.forEach(resolver => resolver(me)); }; }); } @@ -233,9 +236,10 @@ class Socket extends EventHandler { method, args, }; + const me = this return new Promise((resolve) => { - this.addEventListener(call.callId, data => resolve(data)); - this.sendJson(call); + me.addEventListener(call.callId, data => resolve(data)); + me.sendJson(call); }); } @@ -281,12 +285,13 @@ class App extends EventHandler { this.ws = new Socket(); this.rpc = this.ws.client; this.audio = new NotificationAudio(500); + const me = this this.ws.addEventListener("channel-message", (data) => { - this.emit(data.channel_uid, data); + me.emit(data.channel_uid, data); }); this.rpc.getUser(null).then(user => { - this.user = user; + me.user = user; }); } @@ -296,14 +301,15 @@ class App extends EventHandler { async benchMark(times = 100, message = "Benchmark Message") { const promises = []; + const me = this; for (let i = 0; i < times; i++) { promises.push(this.rpc.getChannels().then(channels => { channels.forEach(channel => { - this.rpc.sendMessage(channel.uid, `${message} ${i}`); + me.rpc.sendMessage(channel.uid, `${message} ${i}`); }); })); } } } -const app = new App(); \ No newline at end of file +const app = new App();