Compare commits

...

3 commits

8 changed files with 89 additions and 0 deletions

View file

@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
simple_logger = "5.0.0"
sqlx = { version = "0.8", features = ["runtime-tokio", "tls-native-tls", "postgres"] }
tokio-tungstenite = { version = "0.26", features = ["native-tls", "url"] }
toml = "0.8"
url = { version = "2.5", features = ["serde"] }
uuid = { version = "1.16", features = ["serde", "v7"] }

View file

@ -3,6 +3,7 @@ use actix_web::{Scope, web};
mod auth;
mod stats;
mod users;
mod servers;
pub fn web() -> Scope {
web::scope("/v1")

View file

@ -0,0 +1,3 @@
pub fn web() -> Scope {
web::scope("/channels")
}

View file

48
src/api/v1/servers/mod.rs Normal file
View file

@ -0,0 +1,48 @@
use actix_web::{Error, HttpResponse, error, post, web};
use futures::StreamExt;
use log::error;
use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH};
mod uuid;
mod channels;
use crate::Data;
#[derive(Deserialize)]
struct Request {
access_token: String,
name: String
}
#[derive(Serialize)]
struct Response {
refresh_token: String,
access_token: String,
}
const MAX_SIZE: usize = 262_144;
pub fn web() -> Scope {
web::scope("/servers")
.service(channels::web())
.service(uuid::res)
}
#[post("")]
pub async fn res(mut payload: web::Payload, data: web::Data<Data>) -> Result<HttpResponse, Error> {
let mut body = web::BytesMut::new();
while let Some(chunk) = payload.next().await {
let chunk = chunk?;
// limit max size of in-memory payload
if (body.len() + chunk.len()) > MAX_SIZE {
return Err(error::ErrorBadRequest("overflow"));
}
body.extend_from_slice(&chunk);
}
let request = serde_json::from_slice::<Request>(&body)?;
Ok(HttpResponse::Unauthorized().finish())
}

View file

View file

@ -71,6 +71,42 @@ async fn main() -> Result<(), Error> {
refresh_token varchar(64) UNIQUE NOT NULL REFERENCES refresh_tokens(token),
uuid uuid NOT NULL REFERENCES users(uuid),
created int8 NOT NULL
);
CREATE TABLE IF NOT EXISTS guilds (
uuid uuid PRIMARY KEY NOT NULL,
name VARCHAR(100),
description VARCHAR(300),
created_at int8 NOT NULL
);
CREATE TABLE IF NOT EXISTS guild_members (
guild_uuid uuid NOT NULL REFERENCES guilds(uuid),
user_uuid uuid NOT NULL REFERENCES users(uuid),
permissions int8 NOT NULL DEFAULT 0,
PRIMARY KEY (guild_uuid, user_uuid)
);
CREATE TABLE IF NOT EXISTS channels (
uuid uuid PRIMARY KEY NOT NULL,
guild_uuid NOT NULL REFERENCES guilds(uuid),
name varchar(32) NOT NULL,
description varchar(500) NOT NULL
);
CREATE TABLE IF NOT EXISTS messages (
uuid uuid PRIMARY KEY NOT NULL,
channel_uuid uuid NOT NULL REFERENCES channels(uuid),
user_uuid uuid NOT NULL REFERENCES users(uuid),
message varchar(2000) NOT NULL,
created_at int8 NOT NULL
);
CREATE TABLE IF NOT EXISTS emojis (
uuid uuid PRIMARY KEY NOT NULL,
name varchar(32) NOT NULL,
guild_uuid uuid REFERENCES guilds(uuid)
);
CREATE TABLE IF NOT EXISTS message_reactions (
message_uuid uuid NOT NULL REFERENCES messages(uuid),
user_uuid uuid NOT NULL REFERENCES users(uuid),
emoji_uuid uuid NOT NULL REFERENCES emojis(uuid),
PRIMARY KEY (message_uuid, user_uuid, emoji_uuid)
)
"#,
)