Support for supabase api

This commit is contained in:
2025-10-12 13:00:35 +02:00
parent 80be4b703d
commit 2561f886c6
7 changed files with 135 additions and 22 deletions
+9 -6
View File
@@ -11,8 +11,8 @@ use serde::{Deserialize, Serialize};
use crate::types::{ClientMessage, WsMessage};
pub mod handshake {
use base64::engine::general_purpose::STANDARD as Base64;
use base64::Engine;
use base64::engine::general_purpose::STANDARD as Base64;
use sha1::{Digest, Sha1};
use std::collections::HashMap;
use std::io::{BufRead, BufReader, Write};
@@ -100,7 +100,7 @@ pub mod handshake {
}
}
pub struct Client(TcpStream, Option<u32>, u64);
pub struct Client(TcpStream, Option<String>, u64);
impl Client {
/// Create a client with no timeouts
@@ -324,12 +324,15 @@ impl Client {
self.read_t()
}
pub fn get_uuid(&self) -> crate::Result<u32> {
self.1.ok_or(anyhow!("Invalid UUID"))
pub fn get_uuid(&self) -> crate::Result<String> {
match &self.1 {
Some(v) => Ok(v.clone()),
None => Err(anyhow!("Client ({}) UUID not set", self.2).into()),
}
}
pub fn set_uuid(&mut self, uuid: u32) {
self.1 = Some(uuid)
pub fn set_uuid(&mut self, uuid: &str) {
self.1 = Some(uuid.to_string())
}
#[deprecated]
+6 -6
View File
@@ -12,7 +12,7 @@ impl Database {
"CREATE TABLE IF NOT EXISTS chat (
id INTEGER PRIMARY KEY AUTOINCREMENT,
channel_id TEXT NOT NULL,
user_id INTEGER NOT NULL,
user_id TEXT NOT NULL,
contents TEXT NOT NULL,
timestamp INTEGER NOT NULL
)",
@@ -30,7 +30,7 @@ impl Database {
pub fn insert_message(
&self,
channel_id: &str,
user_id: u32,
user_id: &str,
contents: &str,
timestamp: i64,
) -> Result<Message> {
@@ -45,7 +45,7 @@ impl Database {
Ok(Message {
id,
channel_id: channel_id.to_string(),
from: user_id,
from: user_id.to_string(),
contents: contents.to_string(),
timestamp,
})
@@ -73,7 +73,7 @@ impl Database {
}
/// Get a message by its ID
pub fn get_message_by_id(&self, message_id: usize) -> Result<Option<Message>> {
pub fn get_message_by_id(&self, message_id: &str) -> Result<Option<Message>> {
let mut stmt = self.0.prepare(
"SELECT id, channel_id, user_id, contents, timestamp
FROM chat
@@ -95,7 +95,7 @@ impl Database {
return Ok(Some(Message {
id,
channel_id,
from: user_id,
from: user_id.to_string(),
contents,
timestamp,
}));
@@ -116,7 +116,7 @@ impl Database {
Ok(Message {
id: row.get::<_, i64>(0)?,
channel_id: row.get::<_, String>(1)?,
from: row.get::<_, u32>(2)?,
from: row.get::<_, String>(2)?,
contents: row.get::<_, String>(3)?,
timestamp: row.get::<_, i64>(4)?,
})