feat: add boilerplate rust files
This commit is contained in:
parent
34b984a1b5
commit
8241196284
6 changed files with 52 additions and 0 deletions
|
@ -3,6 +3,7 @@ use actix_web::{Scope, web};
|
||||||
mod auth;
|
mod auth;
|
||||||
mod stats;
|
mod stats;
|
||||||
mod users;
|
mod users;
|
||||||
|
mod servers;
|
||||||
|
|
||||||
pub fn web() -> Scope {
|
pub fn web() -> Scope {
|
||||||
web::scope("/v1")
|
web::scope("/v1")
|
||||||
|
|
3
src/api/v1/servers/channels/mod.rs
Normal file
3
src/api/v1/servers/channels/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn web() -> Scope {
|
||||||
|
web::scope("/channels")
|
||||||
|
}
|
0
src/api/v1/servers/channels/uuid/messages.rs
Normal file
0
src/api/v1/servers/channels/uuid/messages.rs
Normal file
0
src/api/v1/servers/channels/uuid/mod.rs
Normal file
0
src/api/v1/servers/channels/uuid/mod.rs
Normal file
48
src/api/v1/servers/mod.rs
Normal file
48
src/api/v1/servers/mod.rs
Normal 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())
|
||||||
|
}
|
||||||
|
|
0
src/api/v1/servers/uuid.rs
Normal file
0
src/api/v1/servers/uuid.rs
Normal file
Loading…
Add table
Add a link
Reference in a new issue