mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 04:51:13 +03:00
added session check + updates check fixed
This commit is contained in:
parent
63f0b0d732
commit
584983810b
4 changed files with 36 additions and 14 deletions
|
|
@ -48,11 +48,13 @@ motd = """
|
||||||
maxAvatarSize = 100000 # 100 KB
|
maxAvatarSize = 100000 # 100 KB
|
||||||
maxAvatars = 10
|
maxAvatars = 10
|
||||||
|
|
||||||
[advancedUsers.66004548-4de5-49de-bade-9c3933d8eb97]
|
[advancedUsers]
|
||||||
username = "Shiroyashik"
|
|
||||||
authSystem = "elyby"
|
# [advancedUsers.66004548-4de5-49de-bade-9c3933d8eb97]
|
||||||
special = [0,0,0,1,0,0] # 6
|
# username = "Shiroyashik"
|
||||||
pride = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # 25
|
# authSystem = "elyby"
|
||||||
|
# special = [0,0,0,1,0,0] # 6
|
||||||
|
# pride = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # 25
|
||||||
|
|
||||||
## With advancedUsers you can set additional parameters
|
## With advancedUsers you can set additional parameters
|
||||||
# [advancedUsers.your uuid here]
|
# [advancedUsers.your uuid here]
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,14 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use axum::{
|
use axum::{
|
||||||
async_trait, extract::FromRequestParts, http::{request::Parts, StatusCode}
|
async_trait, extract::{FromRequestParts, State}, http::{request::Parts, StatusCode}, response::{IntoResponse, Response}
|
||||||
};
|
};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::AppState;
|
||||||
|
|
||||||
use super::types::*;
|
use super::types::*;
|
||||||
|
|
||||||
// It's an extractor that pulls a token from the Header.
|
// It's an extractor that pulls a token from the Header.
|
||||||
|
|
@ -137,7 +139,7 @@ impl UManager {
|
||||||
) -> Option<dashmap::mapref::one::Ref<'_, Uuid, Userinfo>> {
|
) -> Option<dashmap::mapref::one::Ref<'_, Uuid, Userinfo>> {
|
||||||
self.registered.get(uuid)
|
self.registered.get(uuid)
|
||||||
}
|
}
|
||||||
pub fn _is_authenticated(&self, token: &String) -> bool {
|
pub fn is_authenticated(&self, token: &String) -> bool {
|
||||||
self.authenticated.contains_key(token)
|
self.authenticated.contains_key(token)
|
||||||
}
|
}
|
||||||
pub fn _is_registered(&self, uuid: &Uuid) -> bool {
|
pub fn _is_registered(&self, uuid: &Uuid) -> bool {
|
||||||
|
|
@ -148,4 +150,21 @@ impl UManager {
|
||||||
self.authenticated.remove(&token);
|
self.authenticated.remove(&token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of User manager
|
// End of User manager
|
||||||
|
|
||||||
|
pub async fn check_auth(
|
||||||
|
Token(token): Token,
|
||||||
|
State(state): State<AppState>,
|
||||||
|
) -> Response {
|
||||||
|
|
||||||
|
match token {
|
||||||
|
Some(token) => {
|
||||||
|
if state.user_manager.is_authenticated(&token) {
|
||||||
|
(StatusCode::OK, "ok".to_string()).into_response()
|
||||||
|
} else {
|
||||||
|
(StatusCode::UNAUTHORIZED, "unauthorized".to_string()).into_response()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => (StatusCode::BAD_REQUEST, "bad request".to_string()).into_response(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ use api::{
|
||||||
|
|
||||||
// Auth
|
// Auth
|
||||||
mod auth;
|
mod auth;
|
||||||
use auth::UManager;
|
use auth::{UManager, check_auth};
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
mod state;
|
mod state;
|
||||||
|
|
@ -112,6 +112,7 @@ async fn main() -> Result<()> {
|
||||||
let api = Router::new()
|
let api = Router::new()
|
||||||
.nest("//auth", api_auth::router())
|
.nest("//auth", api_auth::router())
|
||||||
.nest("/v1", api::v1::router())
|
.nest("/v1", api::v1::router())
|
||||||
|
.route("/", get(check_auth))
|
||||||
.route("/limits", get(api_info::limits))
|
.route("/limits", get(api_info::limits))
|
||||||
.route("/version", get(api_info::version))
|
.route("/version", get(api_info::version))
|
||||||
.route("/motd", get(api_info::motd))
|
.route("/motd", get(api_info::motd))
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ struct Tag {
|
||||||
async fn get_latest_version(repo: &str, current_version: Version) -> anyhow::Result<Option<String>> {
|
async fn get_latest_version(repo: &str, current_version: Version) -> anyhow::Result<Option<String>> {
|
||||||
let url = format!("https://api.github.com/repos/{repo}/tags");
|
let url = format!("https://api.github.com/repos/{repo}/tags");
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let response = client.get(&url).send().await?;
|
let response = client.get(&url).header("User-Agent", "reqwest").send().await?;
|
||||||
|
|
||||||
if response.status().is_success() {
|
if response.status().is_success() {
|
||||||
let tags: Vec<Tag> = response.json().await?;
|
let tags: Vec<Tag> = response.json().await?;
|
||||||
|
|
@ -27,9 +27,9 @@ async fn get_latest_version(repo: &str, current_version: Version) -> anyhow::Res
|
||||||
.max();
|
.max();
|
||||||
if let Some(latest_version) = latest_tag {
|
if let Some(latest_version) = latest_tag {
|
||||||
if latest_version > current_version {
|
if latest_version > current_version {
|
||||||
Ok(Some(latest_version.to_string()))
|
Ok(Some(format!("Available new v{latest_version}")))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(Some("Up to date".to_string()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(anyhow!("Can't find version tags!"))
|
Err(anyhow!("Can't find version tags!"))
|
||||||
|
|
@ -43,8 +43,8 @@ pub async fn check_updates(repo: &str, current_version: &str) -> anyhow::Result<
|
||||||
let current_version = semver::Version::parse(¤t_version)?;
|
let current_version = semver::Version::parse(¤t_version)?;
|
||||||
|
|
||||||
match get_latest_version(repo, current_version).await {
|
match get_latest_version(repo, current_version).await {
|
||||||
Ok(d) => if let Some(latest_version) = d {
|
Ok(d) => if let Some(text) = d {
|
||||||
Ok(format!(" - Available new v{latest_version}!"))
|
Ok(format!(" - {text}!"))
|
||||||
} else {
|
} else {
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue