code cleanup

This commit is contained in:
Thomas Weinhold 2026-01-11 13:16:25 +01:00
commit ccdc1cdfbc
50 changed files with 147 additions and 211 deletions

View file

@ -7,7 +7,7 @@ use sslo_lib::error::SsloError;
use sslo_lib::parameters::{DEFAULT_LOBBY_URL, LEAGUE_LOGO_MAX_DIMENSION};
use sslo_lib::pathbuf::PathBufSslo;
use crate::db2;
use crate::db2::{DatabaseManager, DatabaseManagerData};
use crate::db2::DatabaseManagerData;
use super::config::Config;
pub type AppState = SsloAppState<LeagueAppState>;

View file

@ -1,5 +1,5 @@
use std::path::Path;
use std::sync::{Arc, Weak};
use std::sync::Arc;
use tokio::sync::RwLock;
use sslo_lib::error::SsloError;
use crate::db2::configuration::{ConfigurationDbData, ConfigurationDbInterface};

View file

@ -4,12 +4,13 @@ use sqlx::SqlitePool;
use tokio::sync::RwLock;
use sslo_lib::error::SsloError;
use crate::db2::configuration::presets::{PresetTable, PresetTableData};
use crate::db2::{DatabaseManager, DatabaseManagerData};
use crate::db2::DatabaseManagerData;
pub mod presets;
pub struct ConfigurationDbData {
pool: SqlitePool,
_pool: SqlitePool,
tbl_presets: Arc<RwLock<PresetTableData>>,
db_mgr: Weak<RwLock<DatabaseManagerData>>,
}
@ -28,7 +29,7 @@ impl ConfigurationDbData {
// create data object
Ok(Arc::new_cyclic(|me| RwLock::new(Self {
pool: pool.clone(),
_pool: pool.clone(),
tbl_presets: PresetTableData::new(pool.clone(), me.clone()),
db_mgr: Weak::new(),
})))

View file

@ -2,16 +2,13 @@ use std::collections::HashMap;
use std::future::Future;
use std::pin::Pin;
use std::sync::{Arc, Weak};
use serde::de::IntoDeserializer;
use serde::Serialize;
use sqlx::{Row, SqlitePool};
use tokio::sync::{RwLock, RwLockReadGuard};
use utoipa::gen::serde_json;
use tokio::sync::RwLock;
use sslo_lib::error::SsloError;
use sslo_lib::db::{IndexedDataRow, OrderBy, WhereFieldsEqual};
use sslo_lib::ndpc2::collection::NdpcCollection;
use crate::db2::configuration::ConfigurationDbData;
use crate::db2::{DatabaseManager, DatabaseManagerData};
use crate::db2::DatabaseManager;
use crate::ndpc::coll_preset::CollPreset;
#[derive(sqlx::FromRow, Clone)]

View file

@ -18,7 +18,6 @@ pub mod brands;
pub mod cars;
pub mod liveries;
pub mod classes;
pub mod presets;
pub struct ContentDbData {
pool: SqlitePool,

View file

@ -42,7 +42,7 @@ impl BrandItem {
}
/// Returns true, when the item is not actively inuse (is obsolete)
pub async fn deprecated(&self) -> bool { self.0.read().await.row.deprecated }
pub async fn _deprecated(&self) -> bool { self.0.read().await.row.deprecated }
pub async fn cars(&self) -> Vec<CarItem> {
let db_content: ContentDbInterface;
@ -60,7 +60,7 @@ impl BrandItem {
}
/// Returns a string, that can be used in log messages
pub async fn display(&self) -> String {
pub async fn _display(&self) -> String {
self.0.read().await.row.display()
}
@ -108,7 +108,7 @@ impl BrandItem {
.await.inspect_err(|e| log::error!("Upserting {} failed: {}", item_data.row.display(), e))
}
pub async fn set_name(&self, name: &str) -> Result<(), SsloError> {
pub async fn _set_name(&self, name: &str) -> Result<(), SsloError> {
let mut item_data = self.0.write().await;
let pool = item_data.pool.clone();
item_data.row.name = name.trim().to_string();

View file

@ -66,7 +66,7 @@ impl CarItem {
}
/// Returns true, when the item is not actively inuse (is obsolete)
pub async fn deprecated(&self) -> bool { self.0.read().await.row.deprecated }
pub async fn _deprecated(&self) -> bool { self.0.read().await.row.deprecated }
/// Returns a string, that can be used in log messages
pub async fn display(&self) -> String {
@ -137,7 +137,7 @@ impl CarItem {
.inspect_err(|e| log::error!("Upserting {} failed: {}", item_data.row.display(), e))
}
pub async fn set_source(&self, source: Option<&str>) -> Result<(), SsloError> {
pub async fn _set_source(&self, source: Option<&str>) -> Result<(), SsloError> {
let mut item_data = self.0.write().await;
let pool = item_data.pool.clone();
item_data.row.source = match source {
@ -149,7 +149,7 @@ impl CarItem {
}
/// supported sim
pub async fn sim(&self) -> SupportedSim {
pub async fn _sim(&self) -> SupportedSim {
SupportedSim::from_sqlite(self.0.read().await.row.sim)
}
@ -157,7 +157,7 @@ impl CarItem {
pub async fn sim_data(&self) -> String { self.0.read().await.row.sim_data.clone() }
/// source (in case it is a mod)
pub async fn source(&self) -> Option<String> { self.0.read().await.row.source.clone() }
pub async fn _source(&self) -> Option<String> { self.0.read().await.row.source.clone() }
pub async fn url_html(&self) -> String {
let row = &self.0.read().await.row;

View file

@ -57,16 +57,16 @@ impl CountryItem {
}
/// the country code
pub async fn code(&self) -> String {
pub async fn _code(&self) -> String {
self.0.read().await.row.code.clone()
}
pub async fn deprecated(&self) -> bool {
pub async fn _deprecated(&self) -> bool {
self.0.read().await.row.deprecated
}
/// Returns a string, that can be used in log messages
pub async fn display(&self) -> String {
pub async fn _display(&self) -> String {
self.0.read().await.row.display()
}

View file

@ -64,7 +64,7 @@ impl LiveryItem {
}
/// Returns true, when the item is not actively inuse (is obsolete)
pub async fn deprecated(&self) -> bool { self.0.read().await.row.deprecated }
pub async fn _deprecated(&self) -> bool { self.0.read().await.row.deprecated }
/// Returns a string, that can be used in log messages
pub async fn display(&self) -> String {
@ -109,7 +109,7 @@ impl LiveryItem {
pub async fn id(&self) -> i64 { self.0.read().await.row.rowid }
/// name of the car
pub async fn number(&self) -> String { self.0.read().await.row.number.clone() }
pub async fn _number(&self) -> String { self.0.read().await.row.number.clone() }
/// description of the car
pub async fn name(&self) -> String { self.0.read().await.row.name.clone() }
@ -138,7 +138,7 @@ impl LiveryItem {
.inspect_err(|e| log::error!("Upserting {} failed: {}", item_data.row.display(), e))
}
pub async fn set_source(&self, source: Option<&str>) -> Result<(), SsloError> {
pub async fn _set_source(&self, source: Option<&str>) -> Result<(), SsloError> {
let mut item_data = self.0.write().await;
let pool = item_data.pool.clone();
item_data.row.source = match source {
@ -150,10 +150,10 @@ impl LiveryItem {
}
/// data for sim
pub async fn sim_data(&self) -> String { self.0.read().await.row.sim_data.clone() }
pub async fn _sim_data(&self) -> String { self.0.read().await.row.sim_data.clone() }
/// source (in case it is a mod)
pub async fn source(&self) -> Option<String> { self.0.read().await.row.source.clone() }
pub async fn _source(&self) -> Option<String> { self.0.read().await.row.source.clone() }
/// relative Url to html page
pub async fn url_html(&self) -> String {

View file

@ -10,6 +10,7 @@ use crate::db2::content::countries::CountryItem;
use crate::db2::content::tracks::TrackItem;
#[derive(PartialEq, Debug)]
#[allow(dead_code)]
pub struct GeoCoordinates {
pub latitude: f64,
pub longitude: f64,
@ -52,7 +53,7 @@ impl LocationItem {
Self(item_data)
}
pub async fn deprecated(&self) -> bool {
pub async fn _deprecated(&self) -> bool {
self.0.read().await.row.deprecated
}
@ -113,7 +114,7 @@ impl LocationItem {
pub async fn name(&self) -> String { self.0.read().await.row.name.clone() }
/// Geological coordinates
pub async fn coordinates(&self) -> GeoCoordinates {
pub async fn _coordinates(&self) -> GeoCoordinates {
let row = &self.0.read().await.row;
GeoCoordinates{
latitude: row.latitude,

View file

@ -1,16 +0,0 @@
use sslo_lib::db::OrderBy;
use sslo_lib::db::WhereFieldsEqual;
use sqlx::SqlitePool;
use sslo_lib::db::IndexedDataRow;
use sslo_lib::error::SsloError;
#[derive(sqlx::FromRow, Clone)]
#[derive(IndexedDataRow)]
#[tablename("brands")]
struct DbDataRow {
rowid: i64,
ancestor: Option<i64>,
deprecated: bool,
name: String,
json: Option<String>,
}

View file

@ -125,8 +125,8 @@ impl CookieLoginItem {
}
}
pub async fn last_useragent(&self) -> Option<String> { self.0.read().await.row.last_useragent.clone() }
pub async fn last_usage(&self) -> Option<DateTime<Utc>> { self.0.read().await.row.last_usage.clone() }
pub async fn _last_useragent(&self) -> Option<String> { self.0.read().await.row.last_useragent.clone() }
pub async fn _last_usage(&self) -> Option<DateTime<Utc>> { self.0.read().await.row.last_usage.clone() }
/// returns a http header to unset cookie
async fn delete(self) -> String {
@ -278,7 +278,7 @@ impl CookieLoginTable {
Some(CookieLoginItem::new(item_data))
}
pub async fn item_from_latest_usage(&self, user: &UserItem) -> Option<CookieLoginItem> {
pub async fn _item_from_latest_usage(&self, user: &UserItem) -> Option<CookieLoginItem> {
let pool: SqlitePool;
{

View file

@ -153,7 +153,7 @@ impl SteamAccountItem {
OptionalDateTime::new(data.row.last_login.clone())
}
pub async fn set_last_login(&self, last_login: DateTime<Utc>) -> Result<(), SsloError> {
pub async fn _set_last_login(&self, last_login: DateTime<Utc>) -> Result<(), SsloError> {
let mut data = self.0.write().await;
data.row.last_login = Some(last_login);
let pool = data.pool.clone();

View file

@ -175,7 +175,7 @@ impl UserItem {
}
pub async fn last_lap(&self) -> OptionalDateTime { OptionalDateTime::new(self.0.read().await.row.last_lap) }
pub async fn set_last_lap(self: &mut Self, last_lap: DateTime<Utc>) {
pub async fn _set_last_lap(self: &mut Self, last_lap: DateTime<Utc>) {
self.user_grade_reset().await;
let mut item_data = self.0.write().await;
item_data.row.last_lap = Some(last_lap);

View file

@ -131,7 +131,7 @@ impl HtmlTemplate {
&self.http_user
}
pub fn user(&self) -> UserItem {
pub fn _user(&self) -> UserItem {
self.http_user.user.clone()
}

View file

@ -1,4 +1,3 @@
use std::fs::Permissions;
use axum::extract::{FromRef, FromRequestParts};
use axum::http::header;
use axum::http::request::Parts;
@ -32,12 +31,6 @@ impl HttpUser {
}
}
pub fn permissions(&self) -> &PermissionContainer { &self.permissions }
pub fn user(&self) -> UserItem {
self.user.clone()
}
pub fn is_logged_in(&self) -> bool {
self.cookie_login.is_some()
}

View file

@ -15,8 +15,6 @@ pub async fn handler(State(app_state): State<AppState>,
html.include_js("/rsc/js/league/classes.js");
// check permissions
let user = html.user();
let user_grade = user.user_grade().await;
if !html.http_user_permissions.content.view().allowed() {
return Err(StatusCode::FORBIDDEN)
}
@ -59,8 +57,6 @@ pub async fn handler_class(State(app_state): State<AppState>,
html.include_js("/rsc/js/league/classes.js");
// check permissions
let user = html.user();
let user_grade = user.user_grade().await;
if !html.http_user_permissions.content.view().allowed() {
return Err(StatusCode::FORBIDDEN)
}

View file

@ -2,7 +2,7 @@ use std::future::Future;
use std::pin::Pin;
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::response::{Html, Response};
use axum::response::Response;
use sslo_lib::html_modal::{Dialog, DialogButtonStyle};
use sslo_lib::ndpc2::collection::NdpcCollection;
use crate::app_state::AppState;

View file

@ -6,7 +6,6 @@ use axum::response::{IntoResponse, Response};
use image::ImageFormat;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use sslo_lib::http::http2https_background_service;
use sslo_lib::pathbuf::PathBufSslo;
use sslo_lib::rest_api::{EmptyResponse, ErrorResponse};
use crate::app_state::AppState;

View file

@ -3,7 +3,6 @@ use axum::http::StatusCode;
use axum::Json;
use axum::response::{IntoResponse, Response};
use serde::{Deserialize, Serialize};
use tokio::task::id;
use utoipa::ToSchema;
use sslo_lib::ndpc2::collection::{NdpcCollection, NdpcCollectionIO};
use sslo_lib::rest_api::ErrorResponse;

Some files were not shown because too many files have changed in this diff Show more