summary refs log tree commit diff
path: root/v2/client.ts
diff options
context:
space:
mode:
authorwlodekm <[email protected]>2024-11-15 09:46:47 +0200
committerwlodekm <[email protected]>2024-11-15 09:46:47 +0200
commitd28d8333ebe71e2937660b13d9afb1d516cf14f0 (patch)
tree6c941712ec80b785a940b37aec52b2cea7861835 /v2/client.ts
parentd51dbb974d83125f4bfb017188de6a013b7f746c (diff)
v1.0.2
Diffstat (limited to 'v2/client.ts')
-rw-r--r--v2/client.ts67
1 files changed, 0 insertions, 67 deletions
diff --git a/v2/client.ts b/v2/client.ts
deleted file mode 100644
index 3e09f7e..0000000
--- a/v2/client.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-
-import { Screen } from "./screen.ts";
-import type { Text } from "./elements.ts";
-import strftime from "./strftime.js";
-
-export let token: string;
-export let account;
-export const connection = new WebSocket("wss://api.meower.org/v0/cloudlink?v=1")
-
-export let home: any[] = [];
-
-let screen: Screen;
-
-export function setScreen(screenN: Screen) {
-    screen = screenN
-}
-
-export async function login(username: string, password: string) {
-    screen.logs.push(`logging in as ${username}`)
-    const authr = await (await fetch("https://api.meower.org/auth/login", {
-        method: "post",
-        headers: {
-            "content-type": "application/json"
-        },
-        body: JSON.stringify({
-            username,
-            password
-        })
-    })).json();
-    screen.logs.push(`got auth response (${authr.error ? "error" : "not error"})`)
-    token = authr.token;
-    account = authr.account;
-    screen.logs.push(`Got token ${token}`);
-    connection.addEventListener("message", (ev) => {
-        const data = JSON.parse(ev.data.toString());
-        screen.logs.push("INC: " + JSON.stringify(data))
-        if(data.cmd != "post") return;
-        home.push(data.val);
-        const textHome: string[] = home.map(p => `[${strftime("%H:%M:%S", new Date(p.t.e * 1000))}] ${p.u}: ${p.p}`);
-        const homeElem: Text = screen.elements.get("home") as Text;
-        homeElem.text = textHome.join("\n")+"\n";
-        screen.render()        
-    })
-}
-
-export async function loadHome(screen: Screen) {
-    home = (await (await fetch("https://api.meower.org/home")).json()).autoget.reverse();
-    const textHome: string[] = home.map(p => `[${strftime("%H:%M:%S")}] ${p.u}: ${p.p}`);
-    const homeElem: Text = screen.elements.get("home") as Text;
-    homeElem.text = textHome.join("\n")+"\n";
-    screen.logs.push("loadHome ran", home.length.toString())
-    screen.render()
-}
-
-export async function sendHome(post:string) {
-    screen.logs.push("sendHome ran", home.length.toString())
-    fetch("https://api.meower.org/home", {
-        method: "POST",
-        headers: {
-            token,
-            "content-type": "application/json"
-        },
-        body: JSON.stringify({
-            content: post
-        })
-    }).then(async r=>screen.logs.push(`Got send response (${r.status} ${r.statusText}) ${await r.text()}`))
-}