Release v0.2.1

This commit is contained in:
Shiroyasha 2024-06-12 14:03:16 +03:00
parent 5eedf26ca8
commit 27f06f5f2a
Signed by: shiroyashik
GPG key ID: E4953D3940D7860A
10 changed files with 586 additions and 115 deletions

View file

@ -34,7 +34,7 @@ async fn id(
State(state): State<AppState>,
) -> String {
let server_id =
bytes_into_string(&digest(&digest::SHA1_FOR_LEGACY_USE_ONLY, &rand()).as_ref()[0..20]);
hex::encode(&digest(&digest::SHA1_FOR_LEGACY_USE_ONLY, &rand()).as_ref()[0..20]);
let state = state.pending;
state.insert(server_id.clone(), query.username);
server_id

View file

@ -1,4 +1,4 @@
use anyhow::{anyhow, Result};
use anyhow::Result;
use axum::{
extract::DefaultBodyLimit, middleware::from_extractor, routing::{delete, get, post, put}, Router
};
@ -6,7 +6,7 @@ use dashmap::DashMap;
use std::sync::Arc;
use tokio::sync::{broadcast, Mutex};
use tower_http::trace::TraceLayer;
use tracing::{error, info};
use tracing::{info, trace};
use uuid::Uuid;
// WebSocket worker
@ -97,6 +97,7 @@ const SCULPTOR_VERSION: &'static str = env!("CARGO_PKG_VERSION");
#[tokio::main]
async fn main() -> Result<()> {
let _ = dotenvy::dotenv();
// "trace,axum=info,tower_http=info,tokio=info,tungstenite=info,tokio_tungstenite=info",
let logger_env = std::env::var(LOGGER_ENV).unwrap_or_else(|_| "info".into());
@ -138,14 +139,6 @@ async fn main() -> Result<()> {
}
});
let max_body_size = {
let mbs = state.config.clone().lock().await.limitations.max_avatar_size as usize;
if mbs >= 1024 {
mbs
} else {
return Err(anyhow!("maxAvatarSize {mbs} smaller than 1024!"));
}
};
let api = Router::new()
.nest("//auth", api_auth::router())
.route("/limits", get(api_info::limits))
@ -153,8 +146,8 @@ async fn main() -> Result<()> {
.route("/motd", get(api_info::motd))
.route("/equip", post(api_profile::equip_avatar))
.route("/:uuid", get(api_profile::user_info))
.route("/:uuid/avatar", get(api_profile::download_avatar).layer(DefaultBodyLimit::max(max_body_size)))
.route("/avatar", put(api_profile::upload_avatar).layer(DefaultBodyLimit::max(max_body_size)))
.route("/:uuid/avatar", get(api_profile::download_avatar).layer(DefaultBodyLimit::disable()))
.route("/avatar", put(api_profile::upload_avatar).layer(DefaultBodyLimit::disable()))
.route("/avatar", delete(api_profile::delete_avatar));
let app = Router::new()

View file

@ -1,7 +1,6 @@
use anyhow_http::{http_error_ret, response::Result};
use axum::{
body::Bytes,
debug_handler,
extract::{Path, State},
Json,
};
@ -20,7 +19,6 @@ use crate::{
AppState,
};
#[debug_handler]
pub async fn user_info(
Path(uuid): Path<Uuid>,
State(state): State<AppState>,
@ -85,7 +83,6 @@ pub async fn user_info(
Json(user_info_response)
}
#[debug_handler]
pub async fn download_avatar(Path(uuid): Path<Uuid>) -> Result<Vec<u8>> {
let uuid = format_uuid(&uuid);
tracing::info!("Requesting an avatar: {}", uuid);
@ -104,7 +101,6 @@ pub async fn download_avatar(Path(uuid): Path<Uuid>) -> Result<Vec<u8>> {
Ok(buffer)
}
#[debug_handler]
pub async fn upload_avatar(
Token(token): Token,
State(state): State<AppState>,

View file

@ -15,19 +15,6 @@ pub fn rand() -> [u8; 50] {
}
nums
}
//? What is this guy doing
#[tracing::instrument]
pub fn bytes_into_string(code: &[u8]) -> String {
// This *might* be the correct way to do it.
// code.iter().map(|byte| format!("{:02x}", byte)).collect::<String>() // ????? Why do you need this? Why not just hex::encode?
// So we need to turn each byte into a string with a 2-digit hexadecimal representation apparently...
hex::encode(code) // This is the correct way to do it.
// String::from_utf8_lossy(code).to_string() // Tried this, causes corrupted string
}
// End of Core functions
pub fn _generate_hex_string(length: usize) -> String {
@ -68,7 +55,7 @@ pub fn calculate_file_sha256(file_path: &str) -> Result<String, std::io::Error>
let hash = binding.as_ref();
// Convert the hash to a hexadecimal string
let hex_hash = bytes_into_string(hash);
let hex_hash = hex::encode(hash);
Ok(hex_hash)
}