From caed30716b2c8fd084ec66fc89fb46af7aa9beb9 Mon Sep 17 00:00:00 2001 From: lsy Date: Wed, 18 Dec 2024 21:51:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=EF=BC=9A=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5=E5=92=8C?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=89=80=E6=9C=89?= =?UTF-8?q?=E9=99=90=E5=88=B6=E7=A7=BB=E5=88=B0=E5=BA=94=E7=94=A8=E5=B1=82?= =?UTF-8?q?=E9=99=90=E5=88=B6=20=E5=90=8E=E7=AB=AF=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9E=84=E5=BB=BA=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=AD=89=E7=BA=A7=EF=BC=8Cjwt=E6=B7=BB=E5=8A=A0rote?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20=E5=89=8D=E7=AB=AF=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dpost=EF=BC=8C=E5=88=A0=E9=99=A4=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=EF=BC=8C=E4=BC=98=E5=8C=96http?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/api/settings.rs | 116 ------------------------------------ 1 file changed, 116 deletions(-) delete mode 100644 backend/src/api/settings.rs diff --git a/backend/src/api/settings.rs b/backend/src/api/settings.rs deleted file mode 100644 index 70e1354..0000000 --- a/backend/src/api/settings.rs +++ /dev/null @@ -1,116 +0,0 @@ -use super::SystemToken; -use crate::common::error::{AppResult, AppResultInto, CustomResult}; -use crate::storage::{sql, sql::builder}; -use crate::AppState; -use rocket::{ - get, - http::Status, - serde::json::{Json, Value}, - State, -}; -use serde::{Deserialize, Serialize}; -use serde_json::json; -use std::sync::Arc; - -#[derive(Deserialize, Serialize)] -pub struct SystemConfigure { - pub author_name: String, - pub current_theme: String, - pub site_keyword: String, - pub site_description: String, - pub admin_path: String, -} - -impl Default for SystemConfigure { - fn default() -> Self { - Self { - author_name: "lsy".to_string(), - current_theme: "echoes".to_string(), - site_keyword: "echoes".to_string(), - site_description: "echoes是一个高效、可扩展的博客平台".to_string(), - admin_path: "admin".to_string(), - } - } -} - -pub async fn get_setting( - sql: &sql::Database, - comfig_type: String, - name: String, -) -> CustomResult> { - let name_condition = builder::Condition::new( - "name".to_string(), - builder::Operator::Eq, - Some(builder::SafeValue::Text( - format!("{}_{}", comfig_type, name), - builder::ValidationLevel::Strict, - )), - )?; - - let where_clause = builder::WhereClause::Condition(name_condition); - - let mut sql_builder = builder::QueryBuilder::new( - builder::SqlOperation::Select, - sql.table_name("settings"), - sql.get_type(), - )?; - - sql_builder - .add_condition(where_clause) - .add_field("data".to_string())?; - println!("{:?}", sql_builder.build()); - - let result = sql.get_db().execute_query(&sql_builder).await?; - Ok(Json(json!(result))) -} - -pub async fn insert_setting( - sql: &sql::Database, - comfig_type: String, - name: String, - data: Json, -) -> CustomResult<()> { - let mut builder = builder::QueryBuilder::new( - builder::SqlOperation::Insert, - sql.table_name("settings"), - sql.get_type(), - )?; - builder.set_value( - "name".to_string(), - builder::SafeValue::Text( - format!("{}_{}", comfig_type, name).to_string(), - builder::ValidationLevel::Strict, - ), - )?; - builder.set_value( - "data".to_string(), - builder::SafeValue::Text(data.to_string(), builder::ValidationLevel::Relaxed), - )?; - sql.get_db().execute_query(&builder).await?; - Ok(()) -} - -#[get("/system")] -pub async fn system_config_get( - state: &State>, - _token: SystemToken, -) -> AppResult> { - let sql = state.sql_get().await.into_app_result()?; - let settings = get_setting(&sql, "system".to_string(), sql.table_name("settings")) - .await - .into_app_result()?; - Ok(settings) -} - -#[get("/theme/")] -pub async fn theme_config_get( - state: &State>, - _token: SystemToken, - name: String, -) -> AppResult> { - let sql = state.sql_get().await.into_app_result()?; - let settings = get_setting(&sql, "theme".to_string(), name) - .await - .into_app_result()?; - Ok(settings) -}