From ba3af8dc24aa57109a015720284e7631bb2bb40c Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 4 Jul 2024 18:10:35 +0800 Subject: [PATCH 01/68] =?UTF-8?q?:wrench:=20=E5=B0=86=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=8C=96=E6=A8=A1=E5=9D=97=E6=B7=BB=E5=8A=A0=E5=88=B0workspace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 91f9304d..1d00aea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,10 @@ debug = 1 members = [ "libs/*", "persistence/persistence", + "persistence/dao/*", + "persistence/database/*", + "persistence/migrate/*", + "persistence/models/*", "./macros/*", "./middle-server/*", "./logic/*", From 95c252a0a4494f55bd9f01aa66ed37638e1d8893 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 4 Jul 2024 18:12:29 +0800 Subject: [PATCH 02/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=89=88=E6=9C=AC=E6=8E=A5=E5=8F=A3=E7=9A=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=BB=93=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- persistence/models/mongo-models/Cargo.toml | 1 + .../mongo-models/src/ceobe/operation/mod.rs | 1 + .../src/ceobe/operation/version/mod.rs | 1 + .../version/models/download_source.rs | 68 +++++++++++++++++++ .../ceobe/operation/version/models/force.rs | 20 ++++++ .../src/ceobe/operation/version/models/mod.rs | 9 +++ .../operation/version/models/platform.rs | 12 ++++ .../ceobe/operation/version/models/version.rs | 33 +++++++++ 8 files changed, 145 insertions(+) create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/mod.rs create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs diff --git a/persistence/models/mongo-models/Cargo.toml b/persistence/models/mongo-models/Cargo.toml index e9bb843b..e1b96b53 100644 --- a/persistence/models/mongo-models/Cargo.toml +++ b/persistence/models/mongo-models/Cargo.toml @@ -16,6 +16,7 @@ tracing = { workspace = true } modify-cache = { path = "../../../libs/modify-cache" } bool_or.workspace = true serde_json.workspace = true +semver = { version = "1.0.23", features = ["serde"] } [dependencies.sub-model] workspace = true diff --git a/persistence/models/mongo-models/src/ceobe/operation/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/mod.rs index 577fffc5..3f800a43 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/mod.rs @@ -1 +1,2 @@ pub mod plugin_version; +mod version; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs new file mode 100644 index 00000000..255e2521 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs @@ -0,0 +1 @@ +mod models; \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs new file mode 100644 index 00000000..01955495 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -0,0 +1,68 @@ +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; +use url::Url; + +/// 可供使用的下载源 +#[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder)] +#[builder(mutators( + /// 一次添加一个备用下载源 + fn add_spare_url(&mut self, spare: SpareUrl){ + self.spare_urls.push(spare) + } + /// 一次添加多个备用下载源 + fn extend_spare_url(&mut self, spares: impl IntoIterator){ + self.spare_urls.extend(spares) + } +),doc)] +pub struct DownloadSourceItem { + /// 下载源的名称,例如 “百度云盘”、“Github”等 + #[builder(setter(doc="下载源的名称,例如 “百度云盘”、“Github”等"))] + name: String, + /// 下载源的描述,可选内容 + #[builder(default)] + #[builder(setter(doc="下载源的描述,可选内容"))] + description: Option, + /// 下载源的主要URL + #[builder(setter(doc="下载源的主要URL"))] + primary_url: Url, + /// 下载源的备用URL,可空 + #[builder(via_mutators)] + spare_urls: Vec, +} + + +/// 下载源的备用URL +#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder)] +#[builder(doc)] +pub struct SpareUrl { + /// 下载源备用URL的名称 + #[builder(setter(doc="下载源备用URL的名称"))] + name: String, + /// 下载源备用URL的描述,可选 + #[builder(default)] + #[builder(setter(doc="下载源备用URL的描述,可选"))] + description: Option, + /// 下载源备用URL的URL + /// + #[builder(setter(doc="下载源备用URL的URL"))] + url: Url, +} + +mod test { + use crate::ceobe::operation::version::models::download_source::{ + DownloadSourceItem, SpareUrl, + }; + #[test] + fn test_construct_spare() { + let item = DownloadSourceItem::builder() + .extend_spare_url([SpareUrl::builder() + .url("http://example.com".parse().unwrap()) + .name("example backup".to_string()) + .build()]) + .name("ABC".to_string()) + .primary_url("http://primary.com".parse().unwrap()) + .build(); + + println!("{item:?}") + } +} diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs new file mode 100644 index 00000000..66a894d8 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs @@ -0,0 +1,20 @@ +use semver::Version; +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; + +#[derive(Debug,Serialize,Deserialize,Clone,TypedBuilder)] +pub struct ForceCtrl { + #[builder(setter(strip_bool))] + force:bool, + previous_force_version:Version +} + +mod test{ + use semver::Version; + #[test] + fn test_version_serde(){ + let ver = Version::new(1,1,1); + let s = serde_json::to_string(&ver).unwrap(); + assert_eq!(s,"1.1.1") + } +} \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs new file mode 100644 index 00000000..504a12ca --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -0,0 +1,9 @@ +mod download_source; +mod force; +mod platform; +mod version; + +pub use download_source::{DownloadSourceItem, SpareUrl}; +pub use force::ForceCtrl; +pub use platform::Platform; +pub use version::ReleaseVersion; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs new file mode 100644 index 00000000..beb67b3c --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + +/// 下载源对应的平台 +#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] +pub enum Platform { + /// 插件端 + Plugin, + /// 桌面端 + Desktop, + /// 口袋端(Android,IOS,WP等) + Pocket, +} \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs new file mode 100644 index 00000000..b0f9aea5 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -0,0 +1,33 @@ +use semver::{Op, Version}; +use serde::{Deserialize, Serialize}; +use typed_builder::TypedBuilder; +use crate::ceobe::operation::version::models::download_sourece::DownloadSourceItem; +use crate::ceobe::operation::version::models::force::ForceCtrl; +use crate::ceobe::operation::version::models::platform::Platform; + +#[derive(Debug,Serialize,Deserialize,Clone,TypedBuilder)] +#[builder(mutators( + /// 一次添加一个下载源 + fn add_spare_url(&mut self, source: DownloadSourceItem){ + self.download_source.push(source) + } + /// 一次添加多个下载源 + fn extend_spare_url(&mut self, sources: impl IntoIterator){ + self.download_source.extend(sources) + } + ) +)] +pub struct ReleaseVersion{ + /// 当前要发布的版本号 + version:Version, + /// 发布的版本更新控制 + force:ForceCtrl, + ///发布的版本的说明 + #[builder(default)] + description:Option, + ///该版本发布的平台 + platform: Platform, + /// 该版本的可用下载源 + #[builder(via_mutators)] + download_source:Vec +} \ No newline at end of file From e4524df691f469b424559668423f3137905d247e Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 4 Jul 2024 18:49:57 +0800 Subject: [PATCH 03/68] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=BA=8F=E5=88=97=E5=8C=96=E9=AA=8C=E8=AF=81=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/models/download_source.rs | 29 +++-- .../ceobe/operation/version/models/force.rs | 16 +-- .../operation/version/models/platform.rs | 3 +- .../ceobe/operation/version/models/version.rs | 103 +++++++++++++++--- 4 files changed, 116 insertions(+), 35 deletions(-) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs index 01955495..cb363e1c 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -6,45 +6,53 @@ use url::Url; #[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder)] #[builder(mutators( /// 一次添加一个备用下载源 - fn add_spare_url(&mut self, spare: SpareUrl){ + pub fn add_spare_url(&mut self, spare: SpareUrl){ self.spare_urls.push(spare) } /// 一次添加多个备用下载源 - fn extend_spare_url(&mut self, spares: impl IntoIterator){ + pub fn extend_spare_url(&mut self, spares: impl IntoIterator){ self.spare_urls.extend(spares) } ),doc)] pub struct DownloadSourceItem { /// 下载源的名称,例如 “百度云盘”、“Github”等 - #[builder(setter(doc="下载源的名称,例如 “百度云盘”、“Github”等"))] + #[builder(setter( + doc = "下载源的名称,例如 “百度云盘”、“Github”等", + into + ))] name: String, /// 下载源的描述,可选内容 #[builder(default)] - #[builder(setter(doc="下载源的描述,可选内容"))] + #[builder(setter(doc = "下载源的描述,可选内容", into, strip_option))] + #[serde(skip_serializing_if = "Option::is_none")] description: Option, /// 下载源的主要URL - #[builder(setter(doc="下载源的主要URL"))] + #[builder(setter(doc = "下载源的主要URL"))] primary_url: Url, /// 下载源的备用URL,可空 #[builder(via_mutators)] + #[serde(skip_serializing_if = "Vec::is_empty")] spare_urls: Vec, } - /// 下载源的备用URL #[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder)] #[builder(doc)] pub struct SpareUrl { /// 下载源备用URL的名称 - #[builder(setter(doc="下载源备用URL的名称"))] + #[builder(setter(doc = "下载源备用URL的名称", into))] name: String, /// 下载源备用URL的描述,可选 #[builder(default)] - #[builder(setter(doc="下载源备用URL的描述,可选"))] + #[builder(setter( + doc = "下载源备用URL的描述,可选", + into, + strip_option + ))] + #[serde(skip_serializing_if = "Option::is_none")] description: Option, /// 下载源备用URL的URL - /// - #[builder(setter(doc="下载源备用URL的URL"))] + #[builder(setter(doc = "下载源备用URL的URL"))] url: Url, } @@ -62,7 +70,6 @@ mod test { .name("ABC".to_string()) .primary_url("http://primary.com".parse().unwrap()) .build(); - println!("{item:?}") } } diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs index 66a894d8..d0275375 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs @@ -2,19 +2,19 @@ use semver::Version; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; -#[derive(Debug,Serialize,Deserialize,Clone,TypedBuilder)] +#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder)] pub struct ForceCtrl { #[builder(setter(strip_bool))] - force:bool, - previous_force_version:Version + force_update: bool, + previous_force_version: Version, } -mod test{ +mod test { use semver::Version; #[test] - fn test_version_serde(){ - let ver = Version::new(1,1,1); + fn test_version_serde() { + let ver = Version::new(1, 1, 1); let s = serde_json::to_string(&ver).unwrap(); - assert_eq!(s,"1.1.1") + assert_eq!(s, "\"1.1.1\"") } -} \ No newline at end of file +} diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index beb67b3c..60e6d3ab 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; /// 下载源对应的平台 #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] +#[serde(rename_all = "lowercase")] pub enum Platform { /// 插件端 Plugin, @@ -9,4 +10,4 @@ pub enum Platform { Desktop, /// 口袋端(Android,IOS,WP等) Pocket, -} \ No newline at end of file +} diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index b0f9aea5..3a065176 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -1,33 +1,106 @@ use semver::{Op, Version}; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; -use crate::ceobe::operation::version::models::download_sourece::DownloadSourceItem; -use crate::ceobe::operation::version::models::force::ForceCtrl; -use crate::ceobe::operation::version::models::platform::Platform; -#[derive(Debug,Serialize,Deserialize,Clone,TypedBuilder)] +use crate::ceobe::operation::version::models::{ + download_source::DownloadSourceItem, force::ForceCtrl, platform::Platform, +}; + +#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder)] #[builder(mutators( /// 一次添加一个下载源 - fn add_spare_url(&mut self, source: DownloadSourceItem){ + pub fn add_download_source(&mut self, source: DownloadSourceItem){ self.download_source.push(source) } /// 一次添加多个下载源 - fn extend_spare_url(&mut self, sources: impl IntoIterator){ + pub fn extend_download_source(&mut self, sources: impl IntoIterator){ self.download_source.extend(sources) } ) )] -pub struct ReleaseVersion{ +pub struct ReleaseVersion { /// 当前要发布的版本号 - version:Version, + version: Version, /// 发布的版本更新控制 - force:ForceCtrl, - ///发布的版本的说明 - #[builder(default)] - description:Option, - ///该版本发布的平台 + force: ForceCtrl, + /// 发布的版本的说明 + #[builder(default, setter(into, strip_option))] + #[serde(skip_serializing_if = "Option::is_none")] + description: Option, + /// 该版本发布的平台 platform: Platform, /// 该版本的可用下载源 #[builder(via_mutators)] - download_source:Vec -} \ No newline at end of file + download_source: Vec, +} + +mod test { + use semver::Version; + use serde_json::json; + + use crate::ceobe::operation::version::models::{ + DownloadSourceItem, ForceCtrl, Platform, ReleaseVersion, SpareUrl, + }; + #[test] + fn test_version_serde() { + let ver = ReleaseVersion::builder() + .version(Version::new(1, 13, 2)) + .force( + ForceCtrl::builder() + .previous_force_version(Version::new(1, 0, 0)) + .build(), + ) + .description("Abc") + .platform(Platform::Desktop) + .add_download_source( + DownloadSourceItem::builder() + .name("百度云盘") + .description("PanBaidu") + .primary_url( + "https://pan.baidu.com/s/114514".parse().unwrap(), + ) + .add_spare_url( + SpareUrl::builder() + .url( + "https://pan.baidu.com/s/1919810" + .parse() + .unwrap(), + ) + .description("百度英语语言") + .name("百度云备用") + .build(), + ) + .build(), + ) + .build(); + + let serde = serde_json::to_value(ver).expect("serde json error"); + assert_eq!( + serde, + json!({ + "version": "1.13.2", + "force": { + "force_update": false, + "previous_force_version": "1.0.0" + }, + "description": "Abc", + "platform": "desktop", + "download_source": [ + { + "name": "百度云盘", + "description": "PanBaidu", + "primary_url": "https://pan.baidu.com/s/114514", + "spare_urls": [ + { + "name": "百度云备用", + "description": "百度英语语言", + "url": "https://pan.baidu.com/s/1919810" + } + ] + } + ] + + }) + ) + } +} From d82d0119d6db114875f203f7a6b52e1499cbe0f2 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 4 Jul 2024 18:53:22 +0800 Subject: [PATCH 04/68] :art: cargo clippy & fmt --- .../tencent-cloud-server/src/task_trait/header_fetch.rs | 2 +- persistence/models/mongo-models/src/ceobe/operation/mod.rs | 2 +- .../models/mongo-models/src/ceobe/operation/version/mod.rs | 2 +- .../src/ceobe/operation/version/models/download_source.rs | 1 + .../mongo-models/src/ceobe/operation/version/models/force.rs | 1 + .../src/ceobe/operation/version/models/version.rs | 4 +++- 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/middle-server/tencent-cloud-server/src/task_trait/header_fetch.rs b/middle-server/tencent-cloud-server/src/task_trait/header_fetch.rs index 69d41574..12dca2c2 100644 --- a/middle-server/tencent-cloud-server/src/task_trait/header_fetch.rs +++ b/middle-server/tencent-cloud-server/src/task_trait/header_fetch.rs @@ -67,7 +67,7 @@ impl HeaderFetch for TcAction { fn fetch_header( &self, _: &T, _: &Url, ) -> Result { - HeaderValue::from_str(&T::ACTION) + HeaderValue::from_str(T::ACTION) } } diff --git a/persistence/models/mongo-models/src/ceobe/operation/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/mod.rs index 3f800a43..65ad7f7b 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/mod.rs @@ -1,2 +1,2 @@ pub mod plugin_version; -mod version; +pub mod version; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs index 255e2521..c446ac88 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs @@ -1 +1 @@ -mod models; \ No newline at end of file +pub mod models; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs index cb363e1c..1eb8b83a 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -56,6 +56,7 @@ pub struct SpareUrl { url: Url, } +#[cfg(test)] mod test { use crate::ceobe::operation::version::models::download_source::{ DownloadSourceItem, SpareUrl, diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs index d0275375..b83c7253 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs @@ -9,6 +9,7 @@ pub struct ForceCtrl { previous_force_version: Version, } +#[cfg(test)] mod test { use semver::Version; #[test] diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index 3a065176..dba7d3ce 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -1,4 +1,4 @@ -use semver::{Op, Version}; +use semver::Version; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; @@ -34,6 +34,7 @@ pub struct ReleaseVersion { download_source: Vec, } +#[cfg(test)] mod test { use semver::Version; use serde_json::json; @@ -41,6 +42,7 @@ mod test { use crate::ceobe::operation::version::models::{ DownloadSourceItem, ForceCtrl, Platform, ReleaseVersion, SpareUrl, }; + #[test] fn test_version_serde() { let ver = ReleaseVersion::builder() From c8f19612468413544b74e68bdff46c31a5bca7de Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 4 Jul 2024 23:33:01 +0800 Subject: [PATCH 05/68] =?UTF-8?q?:recycle:=20=E8=B0=83=E6=95=B4=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=89=88=E6=9C=AC=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/models/download_source.rs | 56 ++++++++++--------- .../ceobe/operation/version/models/force.rs | 2 +- .../src/ceobe/operation/version/models/mod.rs | 4 +- .../ceobe/operation/version/models/primary.rs | 46 +++++++++++++++ .../ceobe/operation/version/models/version.rs | 36 ++++++++---- 5 files changed, 107 insertions(+), 37 deletions(-) create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs index 1eb8b83a..a1cdc128 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -1,18 +1,20 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use url::Url; - +use crate::ceobe::operation::version::models::primary::Primary; +use super::primary::SkipPrimarySerialize; /// 可供使用的下载源 -#[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder)] +#[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder,PartialEq)] #[builder(mutators( /// 一次添加一个备用下载源 - pub fn add_spare_url(&mut self, spare: SpareUrl){ + pub fn add_spare_url(&mut self, spare: ResourceUrl){ self.spare_urls.push(spare) } /// 一次添加多个备用下载源 - pub fn extend_spare_url(&mut self, spares: impl IntoIterator){ + pub fn extend_spare_url(&mut self, spares: impl IntoIterator){ self.spare_urls.extend(spares) } + ),doc)] pub struct DownloadSourceItem { /// 下载源的名称,例如 “百度云盘”、“Github”等 @@ -28,49 +30,53 @@ pub struct DownloadSourceItem { description: Option, /// 下载源的主要URL #[builder(setter(doc = "下载源的主要URL"))] - primary_url: Url, + primary_url: ResourceUrl, /// 下载源的备用URL,可空 #[builder(via_mutators)] #[serde(skip_serializing_if = "Vec::is_empty")] - spare_urls: Vec, + spare_urls: Vec, } + + /// 下载源的备用URL -#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder)] +#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder,PartialEq)] #[builder(doc)] -pub struct SpareUrl { +pub struct ResourceUrl { /// 下载源备用URL的名称 - #[builder(setter(doc = "下载源备用URL的名称", into))] - name: String, - /// 下载源备用URL的描述,可选 - #[builder(default)] - #[builder(setter( - doc = "下载源备用URL的描述,可选", - into, - strip_option - ))] - #[serde(skip_serializing_if = "Option::is_none")] - description: Option, + #[builder(setter(doc = "下载源URL的名称", into))] + #[serde(skip_serializing_if="SkipPrimarySerialize::should_skip",bound = "for<'d>Name: SkipPrimarySerialize + Serialize+Deserialize<'d>")] + name: Name, /// 下载源备用URL的URL - #[builder(setter(doc = "下载源备用URL的URL"))] + #[builder(setter(doc = "下载源URL的URL"))] url: Url, + #[builder(setter(strip_bool))] + manual: bool, } + + #[cfg(test)] mod test { - use crate::ceobe::operation::version::models::download_source::{ - DownloadSourceItem, SpareUrl, - }; + use crate::ceobe::operation::version::models::download_source::{DownloadSourceItem, Primary, ResourceUrl}; #[test] fn test_construct_spare() { let item = DownloadSourceItem::builder() - .extend_spare_url([SpareUrl::builder() + .extend_spare_url([ResourceUrl::builder() .url("http://example.com".parse().unwrap()) .name("example backup".to_string()) .build()]) .name("ABC".to_string()) - .primary_url("http://primary.com".parse().unwrap()) + .primary_url( + ResourceUrl::builder() + .url("http://primary.com".parse().unwrap()).name(Primary).build(), + ) .build(); println!("{item:?}") } + #[test] + fn test_primary_serde(){ + let a= serde_json::to_string(&Primary).unwrap(); + assert_eq!(a,"\"primary\"") + } } diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs index b83c7253..943eea85 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs @@ -2,7 +2,7 @@ use semver::Version; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; -#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder)] +#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder,PartialEq)] pub struct ForceCtrl { #[builder(setter(strip_bool))] force_update: bool, diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 504a12ca..48e84093 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -2,8 +2,10 @@ mod download_source; mod force; mod platform; mod version; +mod primary; -pub use download_source::{DownloadSourceItem, SpareUrl}; +pub use download_source::{DownloadSourceItem, ResourceUrl,}; pub use force::ForceCtrl; pub use platform::Platform; pub use version::ReleaseVersion; +pub use primary::Primary; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs new file mode 100644 index 00000000..5f87d276 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs @@ -0,0 +1,46 @@ +use serde::{ + de::Unexpected, Deserialize, Deserializer, Serialize, Serializer, +}; + +#[derive(Debug, Copy, Clone, Default,PartialEq)] +pub struct Primary; + +impl<'de> Deserialize<'de> for Primary { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s = + as Deserialize<'de>>::deserialize(deserializer)?; + match s { + Some("primary") | None => Ok(Primary), + Some(s) => { + Err(serde::de::Error::invalid_value( + Unexpected::Str(s), + &"primary", + )) + } + } + } +} + +impl Serialize for Primary { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str("primary") + } +} + +pub trait SkipPrimarySerialize { + fn should_skip(&self) -> bool; +} + +impl SkipPrimarySerialize for Primary { + fn should_skip(&self) -> bool { true } +} + +impl SkipPrimarySerialize for String { + fn should_skip(&self) -> bool { false } +} diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index dba7d3ce..70e62cd6 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -6,7 +6,7 @@ use crate::ceobe::operation::version::models::{ download_source::DownloadSourceItem, force::ForceCtrl, platform::Platform, }; -#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder)] +#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder,PartialEq)] #[builder(mutators( /// 一次添加一个下载源 pub fn add_download_source(&mut self, source: DownloadSourceItem){ @@ -40,8 +40,10 @@ mod test { use serde_json::json; use crate::ceobe::operation::version::models::{ - DownloadSourceItem, ForceCtrl, Platform, ReleaseVersion, SpareUrl, + DownloadSourceItem, ForceCtrl, Platform, + ReleaseVersion, ResourceUrl, }; + use crate::ceobe::operation::version::models::primary::Primary; #[test] fn test_version_serde() { @@ -59,24 +61,32 @@ mod test { .name("百度云盘") .description("PanBaidu") .primary_url( - "https://pan.baidu.com/s/114514".parse().unwrap(), + ResourceUrl::builder() + .url( + "https://pan.baidu.com/s/114514" + .parse() + .unwrap(), + ) + .name(Primary) + .manual() + .build(), ) .add_spare_url( - SpareUrl::builder() + ResourceUrl::builder() .url( "https://pan.baidu.com/s/1919810" .parse() .unwrap(), ) - .description("百度英语语言") .name("百度云备用") + .build(), ) .build(), ) .build(); - let serde = serde_json::to_value(ver).expect("serde json error"); + let serde = serde_json::to_value(ver.clone()).expect("serde json error"); assert_eq!( serde, json!({ @@ -91,18 +101,24 @@ mod test { { "name": "百度云盘", "description": "PanBaidu", - "primary_url": "https://pan.baidu.com/s/114514", + "primary_url": { + "url":"https://pan.baidu.com/s/114514", + "manual":true + }, "spare_urls": [ { "name": "百度云备用", - "description": "百度英语语言", - "url": "https://pan.baidu.com/s/1919810" + "url": "https://pan.baidu.com/s/1919810", + "manual":false } ] } ] }) - ) + ); + + let ver_de = serde_json::from_value(serde).expect("Deserailze_err"); + assert_eq!(ver,ver_de) } } From 9aeecfb81f26c55150d356d653434a13000bf1de Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 4 Jul 2024 23:34:26 +0800 Subject: [PATCH 06/68] :art: cargo fmt --- .../version/models/download_source.rs | 39 +++++++++++-------- .../ceobe/operation/version/models/force.rs | 2 +- .../src/ceobe/operation/version/models/mod.rs | 6 +-- .../ceobe/operation/version/models/primary.rs | 2 +- .../ceobe/operation/version/models/version.rs | 13 +++---- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs index a1cdc128..3762fad0 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -1,20 +1,23 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use url::Url; -use crate::ceobe::operation::version::models::primary::Primary; + use super::primary::SkipPrimarySerialize; +use crate::ceobe::operation::version::models::primary::Primary; /// 可供使用的下载源 -#[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder,PartialEq)] +#[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder, PartialEq)] #[builder(mutators( /// 一次添加一个备用下载源 pub fn add_spare_url(&mut self, spare: ResourceUrl){ self.spare_urls.push(spare) } /// 一次添加多个备用下载源 - pub fn extend_spare_url(&mut self, spares: impl IntoIterator){ + pub fn extend_spare_url( + &mut self, + spares: impl IntoIterator + ){ self.spare_urls.extend(spares) } - ),doc)] pub struct DownloadSourceItem { /// 下载源的名称,例如 “百度云盘”、“Github”等 @@ -37,15 +40,17 @@ pub struct DownloadSourceItem { spare_urls: Vec, } - - /// 下载源的备用URL -#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder,PartialEq)] +#[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder, PartialEq)] #[builder(doc)] -pub struct ResourceUrl { +pub struct ResourceUrl { /// 下载源备用URL的名称 #[builder(setter(doc = "下载源URL的名称", into))] - #[serde(skip_serializing_if="SkipPrimarySerialize::should_skip",bound = "for<'d>Name: SkipPrimarySerialize + Serialize+Deserialize<'d>")] + #[serde( + skip_serializing_if = "SkipPrimarySerialize::should_skip", + bound = "for<'d>Name: SkipPrimarySerialize + \ + Serialize+Deserialize<'d>" + )] name: Name, /// 下载源备用URL的URL #[builder(setter(doc = "下载源URL的URL"))] @@ -54,11 +59,11 @@ pub struct ResourceUrl { manual: bool, } - - #[cfg(test)] mod test { - use crate::ceobe::operation::version::models::download_source::{DownloadSourceItem, Primary, ResourceUrl}; + use crate::ceobe::operation::version::models::download_source::{ + DownloadSourceItem, Primary, ResourceUrl, + }; #[test] fn test_construct_spare() { let item = DownloadSourceItem::builder() @@ -69,14 +74,16 @@ mod test { .name("ABC".to_string()) .primary_url( ResourceUrl::builder() - .url("http://primary.com".parse().unwrap()).name(Primary).build(), + .url("http://primary.com".parse().unwrap()) + .name(Primary) + .build(), ) .build(); println!("{item:?}") } #[test] - fn test_primary_serde(){ - let a= serde_json::to_string(&Primary).unwrap(); - assert_eq!(a,"\"primary\"") + fn test_primary_serde() { + let a = serde_json::to_string(&Primary).unwrap(); + assert_eq!(a, "\"primary\"") } } diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs index 943eea85..c5da8301 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs @@ -2,7 +2,7 @@ use semver::Version; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; -#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder,PartialEq)] +#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder, PartialEq)] pub struct ForceCtrl { #[builder(setter(strip_bool))] force_update: bool, diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 48e84093..1b131e95 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -1,11 +1,11 @@ mod download_source; mod force; mod platform; -mod version; mod primary; +mod version; -pub use download_source::{DownloadSourceItem, ResourceUrl,}; +pub use download_source::{DownloadSourceItem, ResourceUrl}; pub use force::ForceCtrl; pub use platform::Platform; -pub use version::ReleaseVersion; pub use primary::Primary; +pub use version::ReleaseVersion; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs index 5f87d276..7ba709d4 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/primary.rs @@ -2,7 +2,7 @@ use serde::{ de::Unexpected, Deserialize, Deserializer, Serialize, Serializer, }; -#[derive(Debug, Copy, Clone, Default,PartialEq)] +#[derive(Debug, Copy, Clone, Default, PartialEq)] pub struct Primary; impl<'de> Deserialize<'de> for Primary { diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index 70e62cd6..70d893e5 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -6,7 +6,7 @@ use crate::ceobe::operation::version::models::{ download_source::DownloadSourceItem, force::ForceCtrl, platform::Platform, }; -#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder,PartialEq)] +#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder, PartialEq)] #[builder(mutators( /// 一次添加一个下载源 pub fn add_download_source(&mut self, source: DownloadSourceItem){ @@ -40,10 +40,9 @@ mod test { use serde_json::json; use crate::ceobe::operation::version::models::{ - DownloadSourceItem, ForceCtrl, Platform, + primary::Primary, DownloadSourceItem, ForceCtrl, Platform, ReleaseVersion, ResourceUrl, }; - use crate::ceobe::operation::version::models::primary::Primary; #[test] fn test_version_serde() { @@ -79,14 +78,14 @@ mod test { .unwrap(), ) .name("百度云备用") - .build(), ) .build(), ) .build(); - let serde = serde_json::to_value(ver.clone()).expect("serde json error"); + let serde = + serde_json::to_value(ver.clone()).expect("serde json error"); assert_eq!( serde, json!({ @@ -117,8 +116,8 @@ mod test { }) ); - + let ver_de = serde_json::from_value(serde).expect("Deserailze_err"); - assert_eq!(ver,ver_de) + assert_eq!(ver, ver_de) } } From 5cfc6fd1763505b61bd2df0824293f5873efc0b3 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 5 Jul 2024 10:15:11 +0800 Subject: [PATCH 07/68] =?UTF-8?q?:recycle:=20=E8=B0=83=E6=95=B4=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../version/models/download_source.rs | 16 ++++++++--- .../src/ceobe/operation/version/models/mod.rs | 2 +- .../operation/version/models/platform.rs | 28 ++++++++++++++++++- .../ceobe/operation/version/models/version.rs | 14 ++++++---- 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs index 3762fad0..67fb88e6 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use url::Url; +use crate::ceobe::operation::version::models::platform::SupportPlatform; use super::primary::SkipPrimarySerialize; use crate::ceobe::operation::version::models::primary::Primary; @@ -29,27 +30,31 @@ pub struct DownloadSourceItem { /// 下载源的描述,可选内容 #[builder(default)] #[builder(setter(doc = "下载源的描述,可选内容", into, strip_option))] - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none",default)] description: Option, /// 下载源的主要URL #[builder(setter(doc = "下载源的主要URL"))] primary_url: ResourceUrl, /// 下载源的备用URL,可空 #[builder(via_mutators)] - #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(skip_serializing_if = "Vec::is_empty",default)] spare_urls: Vec, } /// 下载源的备用URL #[derive(Debug, Clone, Deserialize, Serialize, TypedBuilder, PartialEq)] -#[builder(doc)] +#[builder(doc, mutators( + pub fn add_support_platform(&mut self, platform: SupportPlatform){ + self.support_platforms.push(platform) + } +))] pub struct ResourceUrl { /// 下载源备用URL的名称 #[builder(setter(doc = "下载源URL的名称", into))] #[serde( skip_serializing_if = "SkipPrimarySerialize::should_skip", bound = "for<'d>Name: SkipPrimarySerialize + \ - Serialize+Deserialize<'d>" + Serialize+Deserialize<'d>",default )] name: Name, /// 下载源备用URL的URL @@ -57,6 +62,9 @@ pub struct ResourceUrl { url: Url, #[builder(setter(strip_bool))] manual: bool, + #[builder(via_mutators)] + #[serde(skip_serializing_if = "Vec::is_empty",default)] + support_platforms:Vec } #[cfg(test)] diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 1b131e95..ae00f5f8 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -6,6 +6,6 @@ mod version; pub use download_source::{DownloadSourceItem, ResourceUrl}; pub use force::ForceCtrl; -pub use platform::Platform; +pub use platform::{ReleasePlatform, SupportPlatform}; pub use primary::Primary; pub use version::ReleaseVersion; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index 60e6d3ab..945a495d 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; /// 下载源对应的平台 #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] #[serde(rename_all = "lowercase")] -pub enum Platform { +pub enum ReleasePlatform { /// 插件端 Plugin, /// 桌面端 @@ -11,3 +11,29 @@ pub enum Platform { /// 口袋端(Android,IOS,WP等) Pocket, } + +/// 当前下载源支持的平台 +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] +#[non_exhaustive] +pub enum SupportPlatform { + // desktop + /// linux发行版桌面端,能兼容X11和Wayland + Linux, + MacOS, + Windows, + // plugin + Chrome, + Firefox, + /// Webkit, Linux平台上基于webkit4gtk-dev等开发的轻量化浏览器 + Webkit, + /// MacOS\IPadOS\IOS的内置浏览器 + Safari, + /// 微软的Internet Explorer 浏览器 + IE, + // pocket + Android, + Ios, + WindowsPhone, + /// 鸿蒙系统 + Harmony, +} diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index 70d893e5..ca84a84e 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use crate::ceobe::operation::version::models::{ - download_source::DownloadSourceItem, force::ForceCtrl, platform::Platform, + download_source::DownloadSourceItem, force::ForceCtrl, platform::ReleasePlatform, }; #[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder, PartialEq)] @@ -28,7 +28,7 @@ pub struct ReleaseVersion { #[serde(skip_serializing_if = "Option::is_none")] description: Option, /// 该版本发布的平台 - platform: Platform, + platform: ReleasePlatform, /// 该版本的可用下载源 #[builder(via_mutators)] download_source: Vec, @@ -40,9 +40,10 @@ mod test { use serde_json::json; use crate::ceobe::operation::version::models::{ - primary::Primary, DownloadSourceItem, ForceCtrl, Platform, + primary::Primary, DownloadSourceItem, ForceCtrl, ReleasePlatform, ReleaseVersion, ResourceUrl, }; + use crate::ceobe::operation::version::models::platform::SupportPlatform; #[test] fn test_version_serde() { @@ -54,7 +55,7 @@ mod test { .build(), ) .description("Abc") - .platform(Platform::Desktop) + .platform(ReleasePlatform::Desktop) .add_download_source( DownloadSourceItem::builder() .name("百度云盘") @@ -68,6 +69,8 @@ mod test { ) .name(Primary) .manual() + .add_support_platform(SupportPlatform::Firefox) + .add_support_platform(SupportPlatform::Safari) .build(), ) .add_spare_url( @@ -102,7 +105,8 @@ mod test { "description": "PanBaidu", "primary_url": { "url":"https://pan.baidu.com/s/114514", - "manual":true + "manual":true, + "support_platforms":["Firefox","Safari"] }, "spare_urls": [ { From 91add47a7991808f119d2d06142cc291f13e1eeb Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 5 Jul 2024 10:20:40 +0800 Subject: [PATCH 08/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=BA=94Checker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mongo-models/src/ceobe/operation/version/checker.rs | 4 ++++ .../models/mongo-models/src/ceobe/operation/version/mod.rs | 1 + .../src/ceobe/operation/version/models/platform.rs | 1 + 3 files changed, 6 insertions(+) create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/checker.rs diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs b/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs new file mode 100644 index 00000000..d99eb444 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs @@ -0,0 +1,4 @@ +use checker::prefabs::no_check::NoCheck; +use crate::ceobe::operation::version::models::ReleaseVersion; + +pub type ReleaseVersionChecker = NoCheck; \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs index c446ac88..f1e56ec4 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs @@ -1 +1,2 @@ pub mod models; +pub mod checker; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index 945a495d..59616867 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -24,6 +24,7 @@ pub enum SupportPlatform { // plugin Chrome, Firefox, + Edge, /// Webkit, Linux平台上基于webkit4gtk-dev等开发的轻量化浏览器 Webkit, /// MacOS\IPadOS\IOS的内置浏览器 From 2859d25a75583d14f5282c975bf173e9aa1a6eac Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 5 Jul 2024 10:52:29 +0800 Subject: [PATCH 09/68] =?UTF-8?q?:card=5Ffile=5Fbox:=20=E6=B7=BB=E5=8A=A0r?= =?UTF-8?q?elease-version=E7=9A=84=E6=95=B0=E6=8D=AEmigration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrate/mongo-migration/Cargo.toml | 6 +++ .../migrate/mongo-migration/src/lib.rs | 46 +++++++++++++++++++ .../src/migrations/ceobe/operation/mod.rs | 1 + .../ceobe/operation/release_version.rs | 37 +++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs diff --git a/persistence/migrate/mongo-migration/Cargo.toml b/persistence/migrate/mongo-migration/Cargo.toml index 40e9b3e1..0ce71557 100644 --- a/persistence/migrate/mongo-migration/Cargo.toml +++ b/persistence/migrate/mongo-migration/Cargo.toml @@ -17,3 +17,9 @@ path = "../../models/mongo-models" [dependencies.mongo-migrate-util] path = "../../../libs/mongo-migrate-util" + +[dev-dependencies] +database_traits = { path = "../../database/database_traits", features = ["all", "get-connect", "initial"] } +mongo_connection = { path = "../../database/mongo_connection" } + +tokio = { workspace = true, features = ["test-util"] } diff --git a/persistence/migrate/mongo-migration/src/lib.rs b/persistence/migrate/mongo-migration/src/lib.rs index 87217ce8..f5044160 100644 --- a/persistence/migrate/mongo-migration/src/lib.rs +++ b/persistence/migrate/mongo-migration/src/lib.rs @@ -23,8 +23,54 @@ impl MigratorTrait for Migrator { .append(migrations::ceobe::cookie::raw::Migration) .await? .append(migrations::ceobe::cookie::terra_comic::Migration) + .await? + .append(migrations::ceobe::operation::release_version::Migration) .await?; Ok(()) } } + +#[cfg(test)] +mod test{ + use serde::Deserialize; + use database_traits::initial::connect_db_with_migrate; + use mongo_connection::{DatabaseManage, DbConnectConfig}; + use crate::Migrator; + + #[tokio::test] + async fn test_migrate(){ + #[derive(Deserialize)] + pub struct MongoDbConfig; + impl DbConnectConfig for MongoDbConfig{ + fn scheme(&self) -> &str { + "mongodb" + } + + fn username(&self) -> &str { + "ceobe" + } + + fn password(&self) -> &str { + "114514" + } + + fn host(&self) -> &str { + "localhost" + } + + fn port(&self) -> u16 { + 27017 + } + + fn name(&self) -> &str { + "ceobe_canteen" + } + } + + let ret = connect_db_with_migrate::( + &MongoDbConfig, + Migrator + ).await.expect("Migrate error"); + } +} \ No newline at end of file diff --git a/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/mod.rs b/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/mod.rs index 577fffc5..75c4dc29 100644 --- a/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/mod.rs +++ b/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/mod.rs @@ -1 +1,2 @@ pub mod plugin_version; +pub mod release_version; diff --git a/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs b/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs new file mode 100644 index 00000000..57836fe6 --- /dev/null +++ b/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs @@ -0,0 +1,37 @@ +use async_trait::async_trait; +use mongo_migrate_util::{CollectManage, MigrationTrait}; +use mongo_models::ceobe::operation::version::models::ReleaseVersion; +use mongodb::{bson::doc, error::Error, options::IndexOptions, IndexModel}; + +const UNIQUE_KEY: &str = "unique_version_platform"; + +pub struct Migration; +#[async_trait] +impl MigrationTrait for Migration { + type Model = ReleaseVersion; + + fn name(&self) -> &'static str { "ceobe_operation_release_version" } + + async fn migrate( + &self, mut collection: CollectManage, + ) -> Result<(), Error> { + collection + .create_idx_if_not_exist( + IndexModel::builder() + .keys(doc! { + "version": 1i32, + "platform": 1i32 + }) + .options( + IndexOptions::builder() + .unique(true) + .name(UNIQUE_KEY.to_owned()) + .build(), + ) + .build(), + None + ) + .await?; + Ok(()) + } +} From 42e076da283ec9f2f8fc4901cca3d5350b089773 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sat, 6 Jul 2024 02:50:39 +0800 Subject: [PATCH 10/68] =?UTF-8?q?:sparkles:=20database-operate=20=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=B7=BB=E5=8A=A0=E8=BE=85=E5=8A=A9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/mongo/plugin_version/mod.rs | 8 +- .../database/database_traits/Cargo.toml | 1 + .../src/database_operates/dao_macros.rs | 92 +++++++++++++++++++ .../src/database_operates/mod.rs | 7 +- .../database/database_traits/src/lib.rs | 4 + .../database/mongo_connection/src/config.rs | 12 +++ .../database/mongo_connection/src/lib.rs | 2 + .../migrate/mongo-migration/src/lib.rs | 2 +- .../src/ceobe/operation/version/models/mod.rs | 1 + .../ceobe/operation/version/models/version.rs | 4 +- 10 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 persistence/database/database_traits/src/database_operates/dao_macros.rs diff --git a/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs index ed33e833..d580472b 100644 --- a/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs @@ -1,11 +1,11 @@ use std::ops::Deref; -pub use db_ops_prelude::mongo_models::ceobe::operation::plugin_version::*; use db_ops_prelude::{ database_operates::sub_operate::{SubOperate, SuperOperate}, - mongo_connection::MongoDbError, - ErrPrefix, HttpCode, StatusErr, ThisError, + ErrPrefix, + HttpCode, mongo_connection::MongoDbError, StatusErr, ThisError, }; +pub use db_ops_prelude::mongo_models::ceobe::operation::plugin_version::*; use crate::OperationDatabaseOperate; @@ -51,6 +51,6 @@ type OperateResult = Result; impl<'db, Conn> OperationDatabaseOperate<'db, Conn> { pub fn plugin_version(&self) -> PluginVersionOperate<'_, Conn> { - self.child() + SuperOperate::child(self) } } diff --git a/persistence/database/database_traits/Cargo.toml b/persistence/database/database_traits/Cargo.toml index 1552da3d..54d1cc7e 100644 --- a/persistence/database/database_traits/Cargo.toml +++ b/persistence/database/database_traits/Cargo.toml @@ -14,3 +14,4 @@ get-connect = [] axum-core = { workspace = true } futures.workspace = true http = { workspace = true } +paste = "1.0.15" diff --git a/persistence/database/database_traits/src/database_operates/dao_macros.rs b/persistence/database/database_traits/src/database_operates/dao_macros.rs new file mode 100644 index 00000000..b2eb485a --- /dev/null +++ b/persistence/database/database_traits/src/database_operates/dao_macros.rs @@ -0,0 +1,92 @@ +#[macro_export] +macro_rules! dao_operator { + ($parent:ty=>$curr:ident($cove:ident, err=$err:ty)) => { + $crate::paste!{ + pub struct [<$curr Operate>]<'db,Conn>(&'db Conn); + + impl <'db, Conn> $crate::SubOperate<'db> for [<$curr Operate>]<'db,Conn>{ + type Parent = $parent<'db,Conn>; + + fn from_parent(parent: &'db Self::Parent)->Self{ + Self(parent) + } + } + + impl <'db, Conn> std::ops::Deref for [<$curr Operate>]<'db,Conn>{ + type Target = Conn; + + fn deref(&self) -> &Self::Target { self.0 } + } + + impl<'db, Conn> $parent<'db, Conn> { + pub fn $cove(&self) -> [<$curr Operate>]<'_, Conn> { + $crate::SuperOperate::child(self) + } + } + + pub struct [<$curr Create>]<'db,Conn>(&'db Conn); + pub struct [<$curr Delete>]<'db,Conn>(&'db Conn); + pub struct [<$curr Retrieve>]<'db,Conn>(&'db Conn); + pub struct [<$curr Update>]<'db,Conn>(&'db Conn); + pub struct [<$curr Verify>]<'db,Conn>(&'db Conn); + + impl <'db, Conn> $crate::OperateTrait<'db> for [<$curr Operate>]<'db,Conn>{ + type Create = [<$curr Create>]<'db,Conn>; + type Delete = [<$curr Delete>]<'db,Conn>; + type Retrieve = [<$curr Retrieve>]<'db,Conn>; + type Update = [<$curr Update>]<'db,Conn>; + type Verify = [<$curr Verify>]<'db,Conn>; + + type Error = $err; + + fn create(&self)->Self::Create{ + [<$curr Create>](self.0) + } + + fn delete(&self)->Self::Delete{ + [<$curr Delete>](self.0) + } + + fn retrieve(&self)->Self::Retrieve{ + [<$curr Retrieve>](self.0) + } + + fn update(&self)->Self::Update{ + [<$curr Update>](self.0) + } + + fn verify(&self)->Self::Verify{ + [<$curr Verify>](self.0) + } + } + + impl <'db, Conn> std::ops::Deref for [<$curr Create>]<'db,Conn>{ + type Target = Conn; + + fn deref(&self) -> &Self::Target { self.0 } + } + impl <'db, Conn> std::ops::Deref for [<$curr Delete>]<'db,Conn>{ + type Target = Conn; + + fn deref(&self) -> &Self::Target { self.0 } + } + impl <'db, Conn> std::ops::Deref for [<$curr Retrieve>]<'db,Conn>{ + type Target = Conn; + + fn deref(&self) -> &Self::Target { self.0 } + } + impl <'db, Conn> std::ops::Deref for [<$curr Update>]<'db,Conn>{ + type Target = Conn; + + fn deref(&self) -> &Self::Target { self.0 } + } + impl <'db, Conn> std::ops::Deref for [<$curr Verify>]<'db,Conn>{ + type Target = Conn; + + fn deref(&self) -> &Self::Target { self.0 } + } + + type Result = core::result::Result; + } + }; +} \ No newline at end of file diff --git a/persistence/database/database_traits/src/database_operates/mod.rs b/persistence/database/database_traits/src/database_operates/mod.rs index a9350856..f197fdc9 100644 --- a/persistence/database/database_traits/src/database_operates/mod.rs +++ b/persistence/database/database_traits/src/database_operates/mod.rs @@ -1,6 +1,7 @@ use std::ops::{Deref, DerefMut}; - +mod dao_macros; mod db_op_impls; +pub mod operate_trait; pub mod sub_operate; #[derive(Clone)] @@ -8,6 +9,10 @@ pub struct DatabaseOperate { connect: C, } +impl DatabaseOperate { + pub fn test_new(connect: C) -> Self { Self { connect } } +} + impl DerefMut for DatabaseOperate { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.connect } } diff --git a/persistence/database/database_traits/src/lib.rs b/persistence/database/database_traits/src/lib.rs index 8c9ae27e..20607454 100644 --- a/persistence/database/database_traits/src/lib.rs +++ b/persistence/database/database_traits/src/lib.rs @@ -8,3 +8,7 @@ pub type BoxedResultFuture<'r, T, E> = Pin> + 'r>>; pub type BoxedResultSendFuture<'r, T, E> = Pin> + 'r + Send>>; + +pub use database_operates::sub_operate::{SubOperate, SuperOperate}; +pub use database_operates::operate_trait::OperateTrait; +pub use paste::paste; diff --git a/persistence/database/mongo_connection/src/config.rs b/persistence/database/mongo_connection/src/config.rs index 60bd2a72..e03b80c3 100644 --- a/persistence/database/mongo_connection/src/config.rs +++ b/persistence/database/mongo_connection/src/config.rs @@ -18,6 +18,18 @@ pub struct MongoDbConfig { db_name: String, } +impl Default for MongoDbConfig { + fn default() -> Self { + Self { + username: "ceobe".into(), + password: "114514".into(), + host: host_default(), + port: port_default(), + db_name: "ceobe_canteen".into(), + } + } +} + impl DbConnectConfig for MongoDbConfig { fn scheme(&self) -> &str { "mongodb" } diff --git a/persistence/database/mongo_connection/src/lib.rs b/persistence/database/mongo_connection/src/lib.rs index 4960f7aa..d5ccc2ea 100644 --- a/persistence/database/mongo_connection/src/lib.rs +++ b/persistence/database/mongo_connection/src/lib.rs @@ -24,3 +24,5 @@ pub type MongoDatabaseOperate = database_traits::database_operates::DatabaseOperate; pub use mongodb; + +pub use static_vars::{get_mongo_database,get_mongo_collection}; \ No newline at end of file diff --git a/persistence/migrate/mongo-migration/src/lib.rs b/persistence/migrate/mongo-migration/src/lib.rs index f5044160..60db117d 100644 --- a/persistence/migrate/mongo-migration/src/lib.rs +++ b/persistence/migrate/mongo-migration/src/lib.rs @@ -68,7 +68,7 @@ mod test{ } } - let ret = connect_db_with_migrate::( + let _ = connect_db_with_migrate::( &MongoDbConfig, Migrator ).await.expect("Migrate error"); diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index ae00f5f8..8c2a96b1 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -9,3 +9,4 @@ pub use force::ForceCtrl; pub use platform::{ReleasePlatform, SupportPlatform}; pub use primary::Primary; pub use version::ReleaseVersion; +pub use semver::Version; \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index ca84a84e..9e728386 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -20,7 +20,7 @@ use crate::ceobe::operation::version::models::{ )] pub struct ReleaseVersion { /// 当前要发布的版本号 - version: Version, + pub version: Version, /// 发布的版本更新控制 force: ForceCtrl, /// 发布的版本的说明 @@ -28,7 +28,7 @@ pub struct ReleaseVersion { #[serde(skip_serializing_if = "Option::is_none")] description: Option, /// 该版本发布的平台 - platform: ReleasePlatform, + pub platform: ReleasePlatform, /// 该版本的可用下载源 #[builder(via_mutators)] download_source: Vec, From e7e9d3cc766553717c536f004dde927e2bfb7ca5 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sat, 6 Jul 2024 02:52:09 +0800 Subject: [PATCH 11/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=89=88=E6=9C=AC=E7=9A=84DAO=E5=B1=82=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 89 ++++---- persistence/dao/ceobe-operate/Cargo.toml | 5 + persistence/dao/ceobe-operate/src/lib.rs | 2 + .../src/mongo/release_version/create.rs | 159 ++++++++++++++ .../src/mongo/release_version/mod.rs | 46 ++++ .../src/mongo/release_version/retrieve.rs | 200 ++++++++++++++++++ .../src/database_operates/operate_trait.rs | 24 +++ .../operation/version/models/platform.rs | 2 +- 8 files changed, 484 insertions(+), 43 deletions(-) create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/create.rs create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs create mode 100644 persistence/database/database_traits/src/database_operates/operate_trait.rs diff --git a/README.md b/README.md index 25d4316a..e7566b07 100644 --- a/README.md +++ b/README.md @@ -20,19 +20,24 @@ | `database`/`db` | `logger` | 否 | `bool` | 是否开始数据库操作日志 | 默认关闭 | | `logger`/`log` | `to_stdout` | 否 | `bool` | 同时将日志输出到 Stdout | 默认为 true | | `logger`/`log` | `to_file` | 否 | `String` | 同时将日志输出的文件 | 有值将会同时将日志输出到指定文件 | - | `logger`/`log` | `level` | 是 | `off` 或者
`error`或者
`warm` 或者
`info` 或者
`debug` 或者
`trace` | 日志输出过滤等级 | 无 | + | `logger`/`log` | `level` | 是 | `off` 或者
`error`或者
`warm` 或者
`info` 或者
`debug` + 或者
`trace` | 日志输出过滤等级 | 无 | | `resp_result`/ `rresult` | `body` | 是 | `String` | 响应成功时的响应体字段名称 | 无 | | `resp_result`/ `rresult` | `err-msg` | 是 | `String` | 响应失败时异常字段名称 | 无 | | `resp_result`/ `rresult` | `fix-field` | 是 | `bool` | 响应体固定字段 | 如果无需该字段值将为`null` | - | `resp_result`/ `rresult` | `bool-status` | 否 | `Option` | 使用一个 `bool` 类型标记响应成功与否 | 该字段缺省表示不使用 | - | `resp_result`/ `rresult` | `body-extra-err` | 否 | `Option` | 额外的异常信息在响应体中字段 | 该字段缺省表示不使用 | - | `resp_result`/ `rresult` | `header-extra-err` | 否 | `Option` | 额外的异常信息在响应头中的字段名称 | 该字段缺省表示不使用 | + | `resp_result`/ `rresult` | `bool-status` | 否 | `Option` | 使用一个 `bool` 类型标记响应成功与否 | + 该字段缺省表示不使用 | + | `resp_result`/ `rresult` | `body-extra-err` | 否 | `Option` | 额外的异常信息在响应体中字段 | + 该字段缺省表示不使用 | + | `resp_result`/ `rresult` | `header-extra-err` | 否 | `Option` | 额外的异常信息在响应头中的字段名称 | + 该字段缺省表示不使用 | | `mongodb`/ `mongo` | `username` | 是 | `String` | Mongodb 进行数据库连接使用的用户 | 该用户需要完整 Admin 权限 | | `mongodb`/ `mongo` | `password` | 是 | `String` | Mongodb 进行数据库连接使用的用户密码 | 无 | | `mongodb`/ `mongo` | `host` | 否 | `String` | Mongodb 进行数据库连接使用的 host | 默认为`localhost` | | `mongodb`/ `mongo` | `port` | 否 | `String` | Mongodb 进行数据库连接使用的端口 | 默认为`27017` | | `mongodb`/ `mongo` | `db_name` | 是 | `String` | Mongodb 进行数据库连接使用的数据库 | 无 | - | `user_auth`/ `auth` | `jwt`/`jwt-key` | 否 | `String` | 用户鉴权使用的`Jwt`密钥 | 最大长度不超过 32 位。过长部分将会被截断,过短部分将会被随机数填充 | + | `user_auth`/ `auth` | `jwt`/`jwt-key` | 否 | `String` | 用户鉴权使用的`Jwt`密钥 | 最大长度不超过 32 + 位。过长部分将会被截断,过短部分将会被随机数填充 | | `user_auth`/ `auth` | `header`/`header_name` | 否 | `String` | 获取 token 的 Header | 默认为`Token` | | `user_auth`/ `auth` | `mob_header` | 否 | `String` | 获取 mob_id 的 Header | 默认为`mob-id` | | `admin_user`/ `user` | `username` | 是 | `String` | 默认后台第一个最高权限用户名 | | @@ -116,24 +121,24 @@ | `M` | 数据未变更 | | `A` | 权限认证异常 | | `Q` | 七牛云上传异常 | - | `L` | 日志报告异常 | + | `L` | 日志报告异常 | - 服务异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :--------------------- | + | :--: | :----: | :------: | :--------------------- | | `F` | 0001 | 500 | 服务器发生未预期 Panic | | `F` | 0002 | 500 | 管道发生未预期关闭 | - Io 异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: |:----:| :------: |:------------------| + | :--: |:----:| :------: |:------------------| | `I` | 0001 | 500 | `std::io::Error` | - | `I` | 0002 | 500 | `core::fmt::Error`| + | `I` | 0002 | 500 | `core::fmt::Error`| - 类型转换异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :---------------------- | + | :--: | :----: | :------: | :---------------------- | | `P` | 0001 | 400 | Url 转化异常 | | `P` | 0002 | 400 | 数字转换异常 | | `P` | 0003 | 400 | jwt 转换异常 | @@ -144,34 +149,34 @@ - 数据校验异常 - | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :------------------------------------------ | - | `C` | 0001 | 400 | 范围检查未通过 | - | `C` | 0002 | 400 | 饼学大厦 id 格式不是 {int}.{int} | - | `C` | 0003 | 400 | 错误的 Fraction 值范围(0~5) | - | `C` | 0004 | 400 | `Json` 序列化/反序列化异常 | - | `C` | 0005 | 400 | `Path` 数据加载异常 | - | `C` | 0006 | 400 | 未知的预期确信度等级 | - | `C` | 0007 | 400 | `Query` 加载异常 | - | `C` | 0008 | 409 | 饼学大厦的 Id 已经存在 | - | `C` | 0009 | 400 | BV 号格式错误 | - | `C` | 000A | 400 | 版本号格式错误 | - | `C` | 000B | 409 | 版本号已经被使用 | - | `C` | 000C | 400 | `Bincode` 序列化/反序列化异常 | - | `C` | 000D | 500 | 存在多个可用的资源全可用的记录 | - | `C` | 000E | 400 | 预期为 0 值取得非 0 值 | - | `C` | 000F | 400 | 获取`MultiPart`异常 | - | `C` | 0010 | 400 | 解析`MultiPart`异常 | - | `C` | 0011 | 400 | `MultiPart` Field 不存在 | - | `C` | 0012 | 500 | 平台下存在数据源,无法删除平台 | - | `C` | 0013 | 400 | 未找到平台 | - | `C` | 0014 | 400 | `{origin}` 无法被 `{RHS}` 整除,余数`{rem}` | - | `C` | 0015 | 400 | Json 对象不符合预期 | - + | 前缀 | 异常码 | httpCode | 说明 | + |:-----:|:-----:|:--------:|:------------------------------------| + | `C` | 0001 | 400 | 范围检查未通过 | + | `C` | 0002 | 400 | 饼学大厦 id 格式不是 {int}.{int} | + | `C` | 0003 | 400 | 错误的 Fraction 值范围(0~5) | + | `C` | 0004 | 400 | `Json` 序列化/反序列化异常 | + | `C` | 0005 | 400 | `Path` 数据加载异常 | + | `C` | 0006 | 400 | 未知的预期确信度等级 | + | `C` | 0007 | 400 | `Query` 加载异常 | + | `C` | 0008 | 409 | 饼学大厦的 Id 已经存在 | + | `C` | 0009 | 400 | BV 号格式错误 | + | `C` | 000A | 400 | 版本号格式错误 | + | `C` | 000B | 409 | 版本号已经被使用 | + | `C` | 000C | 400 | `Bincode` 序列化/反序列化异常 | + | `C` | 000D | 500 | 存在多个可用的资源全可用的记录 | + | `C` | 000E | 400 | 预期为 0 值取得非 0 值 | + | `C` | 000F | 400 | 获取`MultiPart`异常 | + | `C` | 0010 | 400 | 解析`MultiPart`异常 | + | `C` | 0011 | 400 | `MultiPart` Field 不存在 | + | `C` | 0012 | 500 | 平台下存在数据源,无法删除平台 | + | `C` | 0013 | 400 | 未找到平台 | + | `C` | 0014 | 400 | `{origin}` 无法被 `{RHS}` 整除,余数`{rem}` | + | `C` | 0015 | 400 | Json 对象不符合预期 | + | `C` | 0016 | 409 | 版本号过旧 | - 数据库异常(SeaOrm) | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :------------------- | + | :--: | :----: | :------: | :------------------- | | `D` | 0001 | 500 | 数据库连接失败 | | `D` | 0002 | 500 | 数据库请求操作失败 | | `D` | 0003 | 500 | 数据库查询失败 | @@ -184,7 +189,7 @@ - 数据库异常(MongoDb) | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :----------------------- | + | :--: | :----: | :------: | :----------------------- | | `G` | 0001 | 500 | 非法参数 | | `G` | 0002 | 500 | 权限不足 | | `G` | 0003 | 500 | `Bson`反序列化失败 | @@ -208,7 +213,7 @@ - Redis 异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :------------------------------- | + | :--: | :----: | :------: | :------------------------------- | | `R` | 0001 | 500 | 无效响应 | | `R` | 0002 | 500 | 权限不足 | | `R` | 0003 | 500 | 类型不匹配 | @@ -230,13 +235,13 @@ - 数据未变更 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :----------------------------- | + | :--: | :----: | :------: | :----------------------------- | | `M` | 0001 | 304 | Ceobe 在当前提供时间戳下无更新 | - 资源查找异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :--------------------------- | + | :--: | :----: | :------: | :--------------------------- | | `S` | 0001 | 404 | 指定饼学大厦未找到 | | `S` | 0002 | 404 | 不存在的路由 | | `S` | 0003 | 500 | 发起请求时出现异常 | @@ -247,7 +252,7 @@ - 权限认证异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :------------------- | + | :--: | :----: | :------: | :------------------- | | `A` | 0001 | 401 | 缺少 Token 字段 | | `A` | 0002 | 401 | 权限不足 | | `A` | 0003 | 404 | Token 对应信息不存在 | @@ -262,13 +267,13 @@ - 七牛云上传异常 | 前缀 | 异常码 | httpCode | 说明 | - | :--: | :----: | :------: | :------------------- | + | :--: | :----: | :------: | :------------------- | | `Q` | 0001 | 500 | 上传七牛云时出现异常 | - 日志报告异常 |前缀 | 异常码 | httpCode | 说明| - | :--: | :----: | :------: | :------------------- | + | :--: | :----: | :------: | :------------------- | | `L` | 0001 | 500 | 与Grpc服务端建立连接失败 | | `L` | 0002 | 500 | Grpc service 返回异常响应 | | `L` | 0003 | 500 | 发送日志时收到失败响应 | diff --git a/persistence/dao/ceobe-operate/Cargo.toml b/persistence/dao/ceobe-operate/Cargo.toml index 585e1bc4..110480d0 100644 --- a/persistence/dao/ceobe-operate/Cargo.toml +++ b/persistence/dao/ceobe-operate/Cargo.toml @@ -12,4 +12,9 @@ thiserror.workspace = true tracing.workspace = true abstract_database.workspace = true page_size.workspace = true +serde = { version = "1.0.201", features = ["derive"] } + +[dev-dependencies] +mongo-migration = { path = "../../migrate/mongo-migration" } +tokio = { workspace = true, features = ["test-util"] } diff --git a/persistence/dao/ceobe-operate/src/lib.rs b/persistence/dao/ceobe-operate/src/lib.rs index 5411357c..66f3476b 100644 --- a/persistence/dao/ceobe-operate/src/lib.rs +++ b/persistence/dao/ceobe-operate/src/lib.rs @@ -8,6 +8,8 @@ use db_ops_prelude::database_operates::sub_operate::{ #[path = "sql/announcement/mod.rs"] pub mod announcement; #[path = "sql/app_version/mod.rs"] pub mod app_version; +#[path="mongo/release_version/mod.rs"] +pub mod release_version; #[path = "sql/desktop_version/mod.rs"] pub mod desktop_version; #[path = "mongo/plugin_version/mod.rs"] diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs new file mode 100644 index 00000000..88056e50 --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -0,0 +1,159 @@ +use db_ops_prelude::{ + mongo_connection::MongoDbCollectionTrait, + mongodb::{ + bson::{doc, to_bson}, + options::FindOneOptions, + }, +}; +use serde::{Deserialize, Serialize}; + +use super::{ + models::{ReleaseVersion, Version}, + Error, ReleaseVersionCreate, Result, +}; + +impl<'db, Conn> ReleaseVersionCreate<'db, Conn> +where + Conn: MongoDbCollectionTrait<'db, ReleaseVersion>, +{ + pub async fn one( + &'db self, release_version: ReleaseVersion, + ) -> Result<()> { + #[derive(Debug, Deserialize, Serialize)] + struct VersionOnly { + version: Version, + } + + let collection = self.get_collection()?; + + // 找到当前平台的最新的发布版本,与当前添加版本比较。新版本必须更新 + let filter = doc! {"platform":to_bson(&release_version.platform)?}; + let exist_latest_version = collection + .with_mapping::() + .doing(|collection| { + collection.find_one( + filter, + FindOneOptions::builder() + .sort(doc! {"$natural": -1i32}) + .projection(doc! {"version":1i32}) + .build(), + ) + }) + .await?; + if let Some(VersionOnly { version }) = exist_latest_version { + if release_version.version <= version { + Err(Error::VersionTooOld(version, release_version.platform))?; + } + } + + collection + .doing(|collection| collection.insert_one(release_version, None)) + .await?; + Ok(()) + } +} +#[cfg(test)] +mod test { + + use abstract_database::ceobe::ToCeobe; + use db_ops_prelude::{ + database_operates::{operate_trait::OperateTrait, DatabaseOperate}, + mongo_connection::{ + database_traits::initial::{connect_db, connect_db_with_migrate}, + get_mongo_collection, DatabaseManage, MongoConnect, + MongoDbConfig, + }, + mongo_models::ceobe::operation::version::models::{ + ForceCtrl, ReleasePlatform::Pocket, ReleaseVersion, Version, + }, + mongodb::bson::doc, + }; + use mongo_migration::Migrator; + use serde::{Deserialize, Serialize}; + + use crate::ToCeobeOperation; + + #[tokio::test] + async fn test_create_order() { + #[derive(Debug, Deserialize, Serialize)] + struct VersionOnly { + version: Version, + } + + connect_db_with_migrate::( + &MongoDbConfig::default(), + Migrator, + ) + .await + .expect("connect to db Error"); + + let conn = DatabaseOperate::test_new(MongoConnect); + let collection = get_mongo_collection::() + .expect("Collection Not Exist"); + + // 开始测试前,清空现有的collection内容 + collection + .delete_many(doc! {}, None) + .await + .expect("clear Collection Error"); + + // 插入一些版本号,按照从小到大,为了方便,这里只插入版本号 + for major in 1..=5 { + let version = Version::new(major, 0, 0); + collection + .with_mapping::() + .insert_one(&VersionOnly { version }, None) + .await + .expect("insert Error"); + } + + // 现在要插入一些新版本 + + // 添加6.0版本,这个是合法的,因为最新的版本是5.0 + let ret = conn + .ceobe() + .operation() + .release_version() + .create() + .one( + ReleaseVersion::builder() + .version(Version::new(6, 0, 0)) + .force( + ForceCtrl::builder() + .previous_force_version(Version::new(1, 0, 0)) + .build(), + ) + .platform(Pocket) + .build(), + ) + .await; + + assert!(ret.is_ok()); + + // 添加5.8.1 版本,这个是非法的,因为最新版本是6.0,必须大于6.0 + let ret = conn + .ceobe() + .operation() + .release_version() + .create() + .one( + ReleaseVersion::builder() + .version(Version::new(5, 8, 1)) + .force( + ForceCtrl::builder() + .previous_force_version(Version::new(1, 0, 0)) + .build(), + ) + .platform(Pocket) + .build(), + ) + .await; + + // 返回Err, 同时Err类型为VersionTooOld + assert!(ret.is_err()); + assert_eq!( + ret.map_err(|e| e.to_string()), + Err("新版本的版本号过旧, 新版本号应大于 6.0.0".to_string()) + ); + } +} diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs new file mode 100644 index 00000000..f467b6a0 --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -0,0 +1,46 @@ +mod create; +mod retrieve; + +use db_ops_prelude::{ + mongo_connection::{database_traits::dao_operator, MongoDbError}, + StatusErr, ThisError, +}; + +use crate::OperationDatabaseOperate; +use db_ops_prelude::{ErrPrefix,HttpCode}; +dao_operator!(OperationDatabaseOperate=>ReleaseVersion(release_version,err=Error)); + +#[derive(Debug, ThisError, StatusErr)] +pub enum Error { + #[error("数据库查询异常{0}")] + Db(#[from] MongoDbError), + + #[error("版本号已经存在 {1:?}:{0}")] + #[status_err(err( + prefix = "ErrPrefix::CHECKER", + err_code = 0x000B, + http_code = "HttpCode::CONFLICT" + ))] + ConflictVersion(models::Version,models::ReleasePlatform), + #[error("版本信息不存在 {1:?}:{0}")] + #[status_err(err(err_code = 0x0004, prefix = "ErrPrefix::NOT_FOUND",))] + VersionNotFind(models::Version,models::ReleasePlatform), + #[error("暂没有版本信息")] + #[status_err(err(err_code = 0x0005, prefix = "ErrPrefix::NOT_FOUND",))] + VersionInfoNoExist, + #[error("新版本的版本号过旧, 新版本号应大于 {1:?}:{0}")] + #[status_err(err( + err_code = 0x00016, + prefix = "ErrPrefix::CHECKER", + http_code = "HttpCode::CONFLICT" + ))] + VersionTooOld(models::Version,models::ReleasePlatform), + #[error("Bson序列化失败")] + #[status_err(err( + err_code = 0x0004, + prefix = "ErrPrefix::MONGO_DB", + ))] + Bson(#[from]db_ops_prelude::mongodb::bson::ser::Error) +} + +use db_ops_prelude::mongo_models::ceobe::operation::version::*; diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs new file mode 100644 index 00000000..213b4a62 --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -0,0 +1,200 @@ +use tracing::info; + +use db_ops_prelude::{ + mongo_connection::MongoDbCollectionTrait, + mongo_models::ceobe::operation::version::models::ReleasePlatform, + mongodb::{ + bson::{doc, to_bson}, + options::FindOneOptions, + }, +}; + +use super::{ + Error, + models::{ReleaseVersion, Version}, ReleaseVersionRetrieve, Result, +}; + +impl<'db, Conn> ReleaseVersionRetrieve<'db, Conn> +where + Conn: MongoDbCollectionTrait<'db, ReleaseVersion>, +{ + /// 根据指定版本号和平台返回对应的版本信息 + pub async fn by_version_platform( + &'db self, version: &Version, platform: ReleasePlatform, + ) -> Result { + info!(release.version = %version, release.platform = ?platform); + let collection = self.get_collection()?; + + let filter = doc! { + "version":to_bson(version)?, + "platform":to_bson(&platform)? + }; + + let ret = collection + .doing(|collection| collection.find_one(filter, None)) + .await? + .ok_or_else(|| { + Error::VersionNotFind(version.to_owned(), platform) + })?; + Ok(ret) + } + + /// 根据平台返回最新的版本信息 + /// FIXME: 这里直接取最新的一个,理论上没问题/测试上也没问题 + pub async fn latest_by_platform( + &'db self, platform: ReleasePlatform, + ) -> Result { + info!( release.platform = ?platform); + let collection = self.get_collection()?; + let filter = doc! { + "platform":to_bson(&platform)? + }; + let sort = doc! { + "$natural": -1i32 + }; + + let ret = collection + .doing(|collection| { + collection.find_one( + filter, + FindOneOptions::builder().sort(sort).build(), + ) + }) + .await? + .ok_or(Error::VersionInfoNoExist)?; + + Ok(ret) + } +} + +#[cfg(test)] +mod test { + use abstract_database::ceobe::ToCeobe; + use db_ops_prelude::{ + database_operates::{DatabaseOperate, operate_trait::OperateTrait}, + mongo_connection::{ + database_traits::initial::connect_db_with_migrate, + DatabaseManage, get_mongo_collection, MongoConnect, + MongoDbConfig, + }, + mongo_models::ceobe::operation::version::models::{ + ForceCtrl, + ReleasePlatform::{Desktop, Pocket}, + ReleaseVersion, Version, + }, + mongodb::bson::doc, + }; + use mongo_migration::Migrator; + + use crate::ToCeobeOperation; + + #[tokio::test] + async fn test_retrieve_version() { + + connect_db_with_migrate::( + &MongoDbConfig::default(), + Migrator, + ) + .await + .expect("connect to db Error"); + + let conn = DatabaseOperate::test_new(MongoConnect); + let collection = get_mongo_collection::() + .expect("Collection Not Exist"); + + // 开始测试前,清空现有的collection内容 + collection + .delete_many(doc! {}, None) + .await + .expect("clear Collection Error"); + + // 当前无任何版本,最新版本返回空 + let latest = conn + .ceobe() + .operation() + .release_version() + .retrieve() + .latest_by_platform(Pocket) + .await; + + assert_eq!( + latest.map_err(|e| e.to_string()), + Err("暂没有版本信息".into()) + ); + + // 现在要插入一些新版本 + let v1 = ReleaseVersion::builder() + .version(Version::new(1, 0, 0)) + .force( + ForceCtrl::builder() + .previous_force_version(Version::new(1, 0, 0)) + .force_update() + .build(), + ) + .platform(Pocket) + .build(); + let v2_1 = ReleaseVersion::builder() + .version(Version::new(2, 1, 0)) + .force( + ForceCtrl::builder() + .previous_force_version(Version::new(1, 0, 0)) + .build(), + ) + .platform(Pocket) + .build(); + + // 添加1.0版本 + conn.ceobe() + .operation() + .release_version() + .create() + .one(v1.clone()) + .await + .unwrap(); + + // 添加2.1 版本 + conn.ceobe() + .operation() + .release_version() + .create() + .one(v2_1.clone()) + .await + .unwrap(); + + // 现在获得最新版本,得到2.1 + let latest = conn + .ceobe() + .operation() + .release_version() + .retrieve() + .latest_by_platform(Pocket) + .await; + assert!(latest.is_ok()); + assert_eq!(latest.unwrap(), v2_1); + + // 指定版本1.0,获得1.0 + let get_v1 = conn + .ceobe() + .operation() + .release_version() + .retrieve() + .by_version_platform(&Version::new(1, 0, 0), Pocket) + .await; + assert!(get_v1.is_ok()); + assert_eq!(get_v1.unwrap(), v1); + + // 指定一个不存在的版本,返回Err + let version_not_exist = conn + .ceobe() + .operation() + .release_version() + .retrieve() + .by_version_platform(&Version::new(1, 0, 0), Desktop) + .await; + + assert_eq!( + version_not_exist.map_err(|e| e.to_string()), + Err("版本信息不存在 Desktop:1.0.0".into()) + ) + } +} diff --git a/persistence/database/database_traits/src/database_operates/operate_trait.rs b/persistence/database/database_traits/src/database_operates/operate_trait.rs new file mode 100644 index 00000000..095e56ac --- /dev/null +++ b/persistence/database/database_traits/src/database_operates/operate_trait.rs @@ -0,0 +1,24 @@ + +pub trait OperateTrait<'db>{ + type Create; + type Delete; + + type Retrieve; + type Update; + + type Verify; + + type Error; + + fn create(&self)->Self::Create; + + fn delete(&self)->Self::Delete; + + fn retrieve(&self)->Self::Retrieve; + + fn update(&self)->Self::Update; + + fn verify(&self)->Self::Verify; + + +} \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index 59616867..1f334fcc 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; /// 下载源对应的平台 -#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone,Copy, Eq, PartialEq)] #[serde(rename_all = "lowercase")] pub enum ReleasePlatform { /// 插件端 From 06c3e0ab0125820b2a4cc06e2a32068ef8750fb0 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sat, 6 Jul 2024 02:55:36 +0800 Subject: [PATCH 12/68] :art: cargo fmt --- persistence/dao/ceobe-operate/src/lib.rs | 4 +- .../src/mongo/plugin_version/mod.rs | 6 +-- .../src/mongo/release_version/mod.rs | 16 +++--- .../src/mongo/release_version/retrieve.rs | 12 ++--- .../src/database_operates/dao_macros.rs | 44 ++++++++--------- .../src/database_operates/operate_trait.rs | 33 ++++++------- .../database/database_traits/src/lib.rs | 6 ++- .../database/mongo_connection/src/lib.rs | 3 +- .../migrate/mongo-migration/src/lib.rs | 49 ++++++++----------- .../ceobe/operation/release_version.rs | 2 +- .../src/ceobe/operation/version/checker.rs | 3 +- .../src/ceobe/operation/version/mod.rs | 2 +- .../version/models/download_source.rs | 16 +++--- .../src/ceobe/operation/version/models/mod.rs | 2 +- .../operation/version/models/platform.rs | 2 +- .../ceobe/operation/version/models/version.rs | 8 +-- 16 files changed, 97 insertions(+), 111 deletions(-) diff --git a/persistence/dao/ceobe-operate/src/lib.rs b/persistence/dao/ceobe-operate/src/lib.rs index 66f3476b..5b115b92 100644 --- a/persistence/dao/ceobe-operate/src/lib.rs +++ b/persistence/dao/ceobe-operate/src/lib.rs @@ -8,12 +8,12 @@ use db_ops_prelude::database_operates::sub_operate::{ #[path = "sql/announcement/mod.rs"] pub mod announcement; #[path = "sql/app_version/mod.rs"] pub mod app_version; -#[path="mongo/release_version/mod.rs"] -pub mod release_version; #[path = "sql/desktop_version/mod.rs"] pub mod desktop_version; #[path = "mongo/plugin_version/mod.rs"] pub mod plugin_version; +#[path = "mongo/release_version/mod.rs"] +pub mod release_version; #[path = "sql/resource/mod.rs"] pub mod resource; #[path = "sql/tool_link/mod.rs"] pub mod tool_link; #[path = "sql/video/mod.rs"] pub mod video; diff --git a/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs index d580472b..9d706330 100644 --- a/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/plugin_version/mod.rs @@ -1,11 +1,11 @@ use std::ops::Deref; +pub use db_ops_prelude::mongo_models::ceobe::operation::plugin_version::*; use db_ops_prelude::{ database_operates::sub_operate::{SubOperate, SuperOperate}, - ErrPrefix, - HttpCode, mongo_connection::MongoDbError, StatusErr, ThisError, + mongo_connection::MongoDbError, + ErrPrefix, HttpCode, StatusErr, ThisError, }; -pub use db_ops_prelude::mongo_models::ceobe::operation::plugin_version::*; use crate::OperationDatabaseOperate; diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs index f467b6a0..829de442 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -3,11 +3,10 @@ mod retrieve; use db_ops_prelude::{ mongo_connection::{database_traits::dao_operator, MongoDbError}, - StatusErr, ThisError, + ErrPrefix, HttpCode, StatusErr, ThisError, }; use crate::OperationDatabaseOperate; -use db_ops_prelude::{ErrPrefix,HttpCode}; dao_operator!(OperationDatabaseOperate=>ReleaseVersion(release_version,err=Error)); #[derive(Debug, ThisError, StatusErr)] @@ -21,10 +20,10 @@ pub enum Error { err_code = 0x000B, http_code = "HttpCode::CONFLICT" ))] - ConflictVersion(models::Version,models::ReleasePlatform), + ConflictVersion(models::Version, models::ReleasePlatform), #[error("版本信息不存在 {1:?}:{0}")] #[status_err(err(err_code = 0x0004, prefix = "ErrPrefix::NOT_FOUND",))] - VersionNotFind(models::Version,models::ReleasePlatform), + VersionNotFind(models::Version, models::ReleasePlatform), #[error("暂没有版本信息")] #[status_err(err(err_code = 0x0005, prefix = "ErrPrefix::NOT_FOUND",))] VersionInfoNoExist, @@ -34,13 +33,10 @@ pub enum Error { prefix = "ErrPrefix::CHECKER", http_code = "HttpCode::CONFLICT" ))] - VersionTooOld(models::Version,models::ReleasePlatform), + VersionTooOld(models::Version, models::ReleasePlatform), #[error("Bson序列化失败")] - #[status_err(err( - err_code = 0x0004, - prefix = "ErrPrefix::MONGO_DB", - ))] - Bson(#[from]db_ops_prelude::mongodb::bson::ser::Error) + #[status_err(err(err_code = 0x0004, prefix = "ErrPrefix::MONGO_DB",))] + Bson(#[from] db_ops_prelude::mongodb::bson::ser::Error), } use db_ops_prelude::mongo_models::ceobe::operation::version::*; diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index 213b4a62..21b95e47 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -1,5 +1,3 @@ -use tracing::info; - use db_ops_prelude::{ mongo_connection::MongoDbCollectionTrait, mongo_models::ceobe::operation::version::models::ReleasePlatform, @@ -8,10 +6,11 @@ use db_ops_prelude::{ options::FindOneOptions, }, }; +use tracing::info; use super::{ - Error, - models::{ReleaseVersion, Version}, ReleaseVersionRetrieve, Result, + models::{ReleaseVersion, Version}, + Error, ReleaseVersionRetrieve, Result, }; impl<'db, Conn> ReleaseVersionRetrieve<'db, Conn> @@ -71,10 +70,10 @@ where mod test { use abstract_database::ceobe::ToCeobe; use db_ops_prelude::{ - database_operates::{DatabaseOperate, operate_trait::OperateTrait}, + database_operates::{operate_trait::OperateTrait, DatabaseOperate}, mongo_connection::{ database_traits::initial::connect_db_with_migrate, - DatabaseManage, get_mongo_collection, MongoConnect, + get_mongo_collection, DatabaseManage, MongoConnect, MongoDbConfig, }, mongo_models::ceobe::operation::version::models::{ @@ -90,7 +89,6 @@ mod test { #[tokio::test] async fn test_retrieve_version() { - connect_db_with_migrate::( &MongoDbConfig::default(), Migrator, diff --git a/persistence/database/database_traits/src/database_operates/dao_macros.rs b/persistence/database/database_traits/src/database_operates/dao_macros.rs index b2eb485a..2688357b 100644 --- a/persistence/database/database_traits/src/database_operates/dao_macros.rs +++ b/persistence/database/database_traits/src/database_operates/dao_macros.rs @@ -3,90 +3,90 @@ macro_rules! dao_operator { ($parent:ty=>$curr:ident($cove:ident, err=$err:ty)) => { $crate::paste!{ pub struct [<$curr Operate>]<'db,Conn>(&'db Conn); - + impl <'db, Conn> $crate::SubOperate<'db> for [<$curr Operate>]<'db,Conn>{ type Parent = $parent<'db,Conn>; - + fn from_parent(parent: &'db Self::Parent)->Self{ Self(parent) } } - + impl <'db, Conn> std::ops::Deref for [<$curr Operate>]<'db,Conn>{ type Target = Conn; - + fn deref(&self) -> &Self::Target { self.0 } } - + impl<'db, Conn> $parent<'db, Conn> { pub fn $cove(&self) -> [<$curr Operate>]<'_, Conn> { $crate::SuperOperate::child(self) } } - + pub struct [<$curr Create>]<'db,Conn>(&'db Conn); pub struct [<$curr Delete>]<'db,Conn>(&'db Conn); pub struct [<$curr Retrieve>]<'db,Conn>(&'db Conn); pub struct [<$curr Update>]<'db,Conn>(&'db Conn); pub struct [<$curr Verify>]<'db,Conn>(&'db Conn); - + impl <'db, Conn> $crate::OperateTrait<'db> for [<$curr Operate>]<'db,Conn>{ type Create = [<$curr Create>]<'db,Conn>; type Delete = [<$curr Delete>]<'db,Conn>; type Retrieve = [<$curr Retrieve>]<'db,Conn>; type Update = [<$curr Update>]<'db,Conn>; type Verify = [<$curr Verify>]<'db,Conn>; - + type Error = $err; - + fn create(&self)->Self::Create{ [<$curr Create>](self.0) } - + fn delete(&self)->Self::Delete{ [<$curr Delete>](self.0) } - + fn retrieve(&self)->Self::Retrieve{ [<$curr Retrieve>](self.0) } - + fn update(&self)->Self::Update{ [<$curr Update>](self.0) } - + fn verify(&self)->Self::Verify{ [<$curr Verify>](self.0) } } - + impl <'db, Conn> std::ops::Deref for [<$curr Create>]<'db,Conn>{ type Target = Conn; - + fn deref(&self) -> &Self::Target { self.0 } } impl <'db, Conn> std::ops::Deref for [<$curr Delete>]<'db,Conn>{ type Target = Conn; - + fn deref(&self) -> &Self::Target { self.0 } } impl <'db, Conn> std::ops::Deref for [<$curr Retrieve>]<'db,Conn>{ type Target = Conn; - + fn deref(&self) -> &Self::Target { self.0 } } impl <'db, Conn> std::ops::Deref for [<$curr Update>]<'db,Conn>{ type Target = Conn; - + fn deref(&self) -> &Self::Target { self.0 } - } + } impl <'db, Conn> std::ops::Deref for [<$curr Verify>]<'db,Conn>{ type Target = Conn; - + fn deref(&self) -> &Self::Target { self.0 } } - + type Result = core::result::Result; } }; -} \ No newline at end of file +} diff --git a/persistence/database/database_traits/src/database_operates/operate_trait.rs b/persistence/database/database_traits/src/database_operates/operate_trait.rs index 095e56ac..158bd098 100644 --- a/persistence/database/database_traits/src/database_operates/operate_trait.rs +++ b/persistence/database/database_traits/src/database_operates/operate_trait.rs @@ -1,24 +1,21 @@ - -pub trait OperateTrait<'db>{ +pub trait OperateTrait<'db> { type Create; type Delete; - + type Retrieve; type Update; - + type Verify; - + type Error; - - fn create(&self)->Self::Create; - - fn delete(&self)->Self::Delete; - - fn retrieve(&self)->Self::Retrieve; - - fn update(&self)->Self::Update; - - fn verify(&self)->Self::Verify; - - -} \ No newline at end of file + + fn create(&self) -> Self::Create; + + fn delete(&self) -> Self::Delete; + + fn retrieve(&self) -> Self::Retrieve; + + fn update(&self) -> Self::Update; + + fn verify(&self) -> Self::Verify; +} diff --git a/persistence/database/database_traits/src/lib.rs b/persistence/database/database_traits/src/lib.rs index 20607454..e6ccf3a7 100644 --- a/persistence/database/database_traits/src/lib.rs +++ b/persistence/database/database_traits/src/lib.rs @@ -9,6 +9,8 @@ pub type BoxedResultFuture<'r, T, E> = pub type BoxedResultSendFuture<'r, T, E> = Pin> + 'r + Send>>; -pub use database_operates::sub_operate::{SubOperate, SuperOperate}; -pub use database_operates::operate_trait::OperateTrait; +pub use database_operates::{ + operate_trait::OperateTrait, + sub_operate::{SubOperate, SuperOperate}, +}; pub use paste::paste; diff --git a/persistence/database/mongo_connection/src/lib.rs b/persistence/database/mongo_connection/src/lib.rs index d5ccc2ea..245ae139 100644 --- a/persistence/database/mongo_connection/src/lib.rs +++ b/persistence/database/mongo_connection/src/lib.rs @@ -24,5 +24,4 @@ pub type MongoDatabaseOperate = database_traits::database_operates::DatabaseOperate; pub use mongodb; - -pub use static_vars::{get_mongo_database,get_mongo_collection}; \ No newline at end of file +pub use static_vars::{get_mongo_collection, get_mongo_database}; diff --git a/persistence/migrate/mongo-migration/src/lib.rs b/persistence/migrate/mongo-migration/src/lib.rs index 60db117d..cc09e21a 100644 --- a/persistence/migrate/mongo-migration/src/lib.rs +++ b/persistence/migrate/mongo-migration/src/lib.rs @@ -32,45 +32,36 @@ impl MigratorTrait for Migrator { } #[cfg(test)] -mod test{ - use serde::Deserialize; +mod test { use database_traits::initial::connect_db_with_migrate; use mongo_connection::{DatabaseManage, DbConnectConfig}; + use serde::Deserialize; + use crate::Migrator; - + #[tokio::test] - async fn test_migrate(){ + async fn test_migrate() { #[derive(Deserialize)] - pub struct MongoDbConfig; - impl DbConnectConfig for MongoDbConfig{ - fn scheme(&self) -> &str { - "mongodb" - } + pub struct MongoDbConfig; + impl DbConnectConfig for MongoDbConfig { + fn scheme(&self) -> &str { "mongodb" } - fn username(&self) -> &str { - "ceobe" - } + fn username(&self) -> &str { "ceobe" } - fn password(&self) -> &str { - "114514" - } + fn password(&self) -> &str { "114514" } - fn host(&self) -> &str { - "localhost" - } + fn host(&self) -> &str { "localhost" } - fn port(&self) -> u16 { - 27017 - } + fn port(&self) -> u16 { 27017 } - fn name(&self) -> &str { - "ceobe_canteen" - } + fn name(&self) -> &str { "ceobe_canteen" } } - - let _ = connect_db_with_migrate::( + + let _ = connect_db_with_migrate::( &MongoDbConfig, - Migrator - ).await.expect("Migrate error"); + Migrator, + ) + .await + .expect("Migrate error"); } -} \ No newline at end of file +} diff --git a/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs b/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs index 57836fe6..f82d493a 100644 --- a/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs +++ b/persistence/migrate/mongo-migration/src/migrations/ceobe/operation/release_version.rs @@ -29,7 +29,7 @@ impl MigrationTrait for Migration { .build(), ) .build(), - None + None, ) .await?; Ok(()) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs b/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs index d99eb444..dedceee7 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/checker.rs @@ -1,4 +1,5 @@ use checker::prefabs::no_check::NoCheck; + use crate::ceobe::operation::version::models::ReleaseVersion; -pub type ReleaseVersionChecker = NoCheck; \ No newline at end of file +pub type ReleaseVersionChecker = NoCheck; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs index f1e56ec4..ed3aa4d7 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/mod.rs @@ -1,2 +1,2 @@ -pub mod models; pub mod checker; +pub mod models; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs index 67fb88e6..0ede7472 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/download_source.rs @@ -1,10 +1,11 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use url::Url; -use crate::ceobe::operation::version::models::platform::SupportPlatform; use super::primary::SkipPrimarySerialize; -use crate::ceobe::operation::version::models::primary::Primary; +use crate::ceobe::operation::version::models::{ + platform::SupportPlatform, primary::Primary, +}; /// 可供使用的下载源 #[derive(Debug, Serialize, Clone, Deserialize, TypedBuilder, PartialEq)] #[builder(mutators( @@ -30,14 +31,14 @@ pub struct DownloadSourceItem { /// 下载源的描述,可选内容 #[builder(default)] #[builder(setter(doc = "下载源的描述,可选内容", into, strip_option))] - #[serde(skip_serializing_if = "Option::is_none",default)] + #[serde(skip_serializing_if = "Option::is_none", default)] description: Option, /// 下载源的主要URL #[builder(setter(doc = "下载源的主要URL"))] primary_url: ResourceUrl, /// 下载源的备用URL,可空 #[builder(via_mutators)] - #[serde(skip_serializing_if = "Vec::is_empty",default)] + #[serde(skip_serializing_if = "Vec::is_empty", default)] spare_urls: Vec, } @@ -54,7 +55,8 @@ pub struct ResourceUrl { #[serde( skip_serializing_if = "SkipPrimarySerialize::should_skip", bound = "for<'d>Name: SkipPrimarySerialize + \ - Serialize+Deserialize<'d>",default + Serialize+Deserialize<'d>", + default )] name: Name, /// 下载源备用URL的URL @@ -63,8 +65,8 @@ pub struct ResourceUrl { #[builder(setter(strip_bool))] manual: bool, #[builder(via_mutators)] - #[serde(skip_serializing_if = "Vec::is_empty",default)] - support_platforms:Vec + #[serde(skip_serializing_if = "Vec::is_empty", default)] + support_platforms: Vec, } #[cfg(test)] diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 8c2a96b1..03d466e0 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -8,5 +8,5 @@ pub use download_source::{DownloadSourceItem, ResourceUrl}; pub use force::ForceCtrl; pub use platform::{ReleasePlatform, SupportPlatform}; pub use primary::Primary; +pub use semver::Version; pub use version::ReleaseVersion; -pub use semver::Version; \ No newline at end of file diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index 1f334fcc..f0c44ed7 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; /// 下载源对应的平台 -#[derive(Serialize, Deserialize, Debug, Clone,Copy, Eq, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, Eq, PartialEq)] #[serde(rename_all = "lowercase")] pub enum ReleasePlatform { /// 插件端 diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index 9e728386..16602328 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -3,7 +3,8 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; use crate::ceobe::operation::version::models::{ - download_source::DownloadSourceItem, force::ForceCtrl, platform::ReleasePlatform, + download_source::DownloadSourceItem, force::ForceCtrl, + platform::ReleasePlatform, }; #[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder, PartialEq)] @@ -40,10 +41,9 @@ mod test { use serde_json::json; use crate::ceobe::operation::version::models::{ - primary::Primary, DownloadSourceItem, ForceCtrl, ReleasePlatform, - ReleaseVersion, ResourceUrl, + platform::SupportPlatform, primary::Primary, DownloadSourceItem, + ForceCtrl, ReleasePlatform, ReleaseVersion, ResourceUrl, }; - use crate::ceobe::operation::version::models::platform::SupportPlatform; #[test] fn test_version_serde() { From a55da0b8f06b481c99834f464dc540cd3417a329 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 10:57:14 +0800 Subject: [PATCH 13/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=97=A7?= =?UTF-8?q?=E7=89=88Version=E5=88=B0=E6=96=B0=E7=89=88=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- persistence/models/mongo-models/Cargo.toml | 2 + .../ceobe/operation/version/models/conv.rs | 258 ++++++++++++++++++ .../ceobe/operation/version/models/force.rs | 10 +- .../src/ceobe/operation/version/models/mod.rs | 2 +- 4 files changed, 270 insertions(+), 2 deletions(-) create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs diff --git a/persistence/models/mongo-models/Cargo.toml b/persistence/models/mongo-models/Cargo.toml index e1b96b53..014deb4c 100644 --- a/persistence/models/mongo-models/Cargo.toml +++ b/persistence/models/mongo-models/Cargo.toml @@ -17,6 +17,8 @@ modify-cache = { path = "../../../libs/modify-cache" } bool_or.workspace = true serde_json.workspace = true semver = { version = "1.0.23", features = ["serde"] } +sql-models = { version = "0.1.0", path = "../sql-models" } +tracing-unwrap.workspace = true [dependencies.sub-model] workspace = true diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs new file mode 100644 index 00000000..e503781b --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs @@ -0,0 +1,258 @@ +use semver::Version; +use sql_models::ceobe_operation::{app_version, desktop_version}; +use tracing_unwrap::ResultExt; + +use crate::ceobe::operation::{ + plugin_version::{self, DownloadResource, SpareLink}, + version::models::{ + DownloadSourceItem, ForceCtrl, Primary, + ReleasePlatform::{Desktop, Plugin, Pocket}, + ReleaseVersion, ResourceUrl, SupportPlatform, + SupportPlatform::{Android, MacOS, Windows}, + }, +}; + +impl From for ReleaseVersion { + fn from( + plugin_version::Checked { + version: + checker::prefabs::version_checker::Version { + major, + minor, + security, + }, + description, + down: + DownloadResource { + crx, + spare_crx, + zip, + spare_zip, + chrome, + edge, + firefox, + spare: SpareLink { url, msg }, + }, + .. + }: plugin_version::Checked, + ) -> Self { + ReleaseVersion::builder() + .version(Version::new(major as _, minor as _, security as _)) + .description(description) + .platform(Plugin) + .force( + ForceCtrl::builder() + .force_update() + .previous_force_version(Version::new( + major as _, + minor as _, + security as _, + )) + .build(), + ) + .add_download_source( + DownloadSourceItem::builder() + .name("CRX") + .primary_url( + ResourceUrl::builder().name(Primary).url(crx).build(), + ) + .extend_spare_url(spare_crx.map(|url| { + ResourceUrl::builder() + .name("CRX备用") + .url(url) + .manual() + .build() + })) + .build(), + ) + .add_download_source( + DownloadSourceItem::builder() + .name("ZIP") + .primary_url( + ResourceUrl::builder().name(Primary).url(zip).build(), + ) + .extend_spare_url(spare_zip.map(|url| { + ResourceUrl::builder() + .name("Zip备用") + .url(url) + .manual() + .build() + })) + .build(), + ) + .extend_download_source( + ["Chrome", "Edge", "FireFox"] + .into_iter() + .zip([chrome, edge, firefox]) + .map(|(name, url)| { + DownloadSourceItem::builder() + .name(name) + .primary_url( + ResourceUrl::builder() + .name(Primary) + .url(url) + .build(), + ) + .build() + }), + ) + .add_download_source( + DownloadSourceItem::builder() + .name("云盘备用") + .description(msg) + .primary_url( + ResourceUrl::builder() + .name(Primary) + .url(url) + .manual() + .build(), + ) + .build(), + ) + .build() + } +} + +impl From for ReleaseVersion { + fn from( + app_version::Checked { + version, + force, + last_force_version, + description, + apk, + spare_apk, + baidu, + baidu_text, + }: app_version::Checked, + ) -> Self { + ReleaseVersion::builder() + // 经过校验的version,没有问题 + .version(version.parse().unwrap_or_log()) + .force( + ForceCtrl::builder() + .set_force_update(force) + .previous_force_version( + last_force_version.parse().unwrap_or_log(), + ) + .build(), + ) + .platform(Pocket) + .description(description) + .add_download_source( + DownloadSourceItem::builder() + .name("安卓下载") + .primary_url( + ResourceUrl::builder().name(Primary).url(apk).build(), + ) + .add_spare_url( + ResourceUrl::builder() + .name("安卓备用下载") + .url(spare_apk) + .manual() + .add_support_platform(Android) + .build(), + ) + .build(), + ) + .add_download_source( + DownloadSourceItem::builder() + .name("百度云盘下载") + .description(baidu_text) + .primary_url( + ResourceUrl::builder() + .name(Primary) + .url(baidu) + .manual() + .build(), + ) + .build(), + ) + .build() + } +} + +impl From for ReleaseVersion { + fn from( + desktop_version::Checked { + version, + force, + last_force_version, + description, + exe, + spare_exe, + dmg, + spare_dmg, + baidu, + baidu_text, + }: desktop_version::Checked, + ) -> Self { + ReleaseVersion::builder() + // 经过校验的version,没有问题 + .version(version.parse().unwrap_or_log()) + .force( + ForceCtrl::builder() + .set_force_update(force) + .previous_force_version( + last_force_version.parse().unwrap_or_log(), + ) + .build(), + ) + .platform(Desktop) + .description(description) + .add_download_source( + DownloadSourceItem::builder() + .name("Windows安装包下载(.exe)") + .primary_url( + ResourceUrl::builder() + .name(Primary) + .url(exe) + .add_support_platform(Windows) + .build(), + ) + .add_spare_url( + ResourceUrl::builder() + .name("Windows安装包备用下载") + .url(spare_exe) + .manual() + .add_support_platform(Windows) + .build(), + ) + .build(), + ) + .add_download_source( + DownloadSourceItem::builder() + .name("MacOS安装包下载(.dmg)") + .primary_url( + ResourceUrl::builder() + .name(Primary) + .url(dmg) + .add_support_platform(MacOS) + .build(), + ) + .add_spare_url( + ResourceUrl::builder() + .name("MacOS安装包备用下载") + .url(spare_dmg) + .manual() + .add_support_platform(MacOS) + .build(), + ) + .build(), + ) + .add_download_source( + DownloadSourceItem::builder() + .name("百度云盘下载") + .description(baidu_text) + .primary_url( + ResourceUrl::builder() + .name(Primary) + .url(baidu) + .manual() + .build(), + ) + .build(), + ) + .build() + } +} diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs index c5da8301..56a7193b 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/force.rs @@ -3,8 +3,16 @@ use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; #[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder, PartialEq)] +#[builder(mutators( + pub fn force_update(&mut self){ + self.force_update = true + } + pub fn set_force_update(&mut self,force:bool){ + self.force_update = force + } +))] pub struct ForceCtrl { - #[builder(setter(strip_bool))] + #[builder(via_mutators)] force_update: bool, previous_force_version: Version, } diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 03d466e0..347a12d4 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -3,7 +3,7 @@ mod force; mod platform; mod primary; mod version; - +mod conv; pub use download_source::{DownloadSourceItem, ResourceUrl}; pub use force::ForceCtrl; pub use platform::{ReleasePlatform, SupportPlatform}; From 2da042a94edd331ff1950a8bc2932fac8d8b244a Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 10:58:30 +0800 Subject: [PATCH 14/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=97=A7?= =?UTF-8?q?=E7=89=88Version=E5=88=B0=E6=96=B0=E7=89=88=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/ceobe-operate/src/mongo/release_version/create.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs index 88056e50..dc587a8c 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -17,12 +17,13 @@ where Conn: MongoDbCollectionTrait<'db, ReleaseVersion>, { pub async fn one( - &'db self, release_version: ReleaseVersion, + &'db self, release_version: impl Into, ) -> Result<()> { #[derive(Debug, Deserialize, Serialize)] struct VersionOnly { version: Version, } + let release_version = release_version.into(); let collection = self.get_collection()?; From e22accc589ab179cc5d188a9d0c6fbd44e442bd9 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 11:52:27 +0800 Subject: [PATCH 15/68] =?UTF-8?q?:alien:=20resp=5Fresult=20=E6=9B=B4?= =?UTF-8?q?=E5=90=8D=E4=B8=BAaxum-resp-result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 6 ++++-- libs/checker/Cargo.toml | 2 +- libs/checker/src/check_prehandle.rs | 2 +- libs/modify-cache/Cargo.toml | 2 +- libs/modify-cache/src/cache_ctrl/control.rs | 2 +- libs/modify-cache/src/cache_ctrl/mod.rs | 2 +- libs/modify-cache/src/check_modify.rs | 2 +- libs/status-err/Cargo.toml | 2 +- libs/status-err/src/codegen.rs | 2 +- macros/status-err-derive/Cargo.toml | 2 +- middle-server/qq-channel-warning/Cargo.toml | 2 +- middle-server/qq-channel-warning/src/grpc_client.rs | 4 ++-- src/bootstrap/init/component_init.rs | 6 +++--- src/bootstrap/middleware/panic_report.rs | 2 +- src/configs/resp_result_config.rs | 4 ++-- src/error/mod.rs | 2 +- src/middleware/authorize/mod.rs | 2 +- src/middleware/authorize/service.rs | 2 +- src/middleware/mob/mod.rs | 2 +- src/middleware/mob/service.rs | 2 +- src/serves/backend/bakery_mansion/controllers.rs | 2 +- src/serves/backend/bakery_mansion/mod.rs | 2 +- src/serves/backend/ceobe_cookie/newest/controllers.rs | 2 +- src/serves/backend/ceobe_cookie/newest/error.rs | 2 +- .../backend/ceobe_operation/announcement/controllers.rs | 2 +- src/serves/backend/ceobe_operation/announcement/error.rs | 2 +- .../backend/ceobe_operation/app_version/controllers.rs | 2 +- .../backend/ceobe_operation/desktop_version/controllers.rs | 2 +- .../backend/ceobe_operation/plugin_version/controllers.rs | 2 +- src/serves/backend/ceobe_operation/resource/controller.rs | 2 +- src/serves/backend/ceobe_operation/resource/error.rs | 2 +- src/serves/backend/ceobe_operation/tool_link/controllers.rs | 4 ++-- src/serves/backend/ceobe_operation/tool_link/error.rs | 2 +- src/serves/backend/ceobe_operation/video/controllers.rs | 2 +- src/serves/backend/ceobe_operation/video/error.rs | 2 +- .../backend/fetcher/datasource_configs/controllers.rs | 4 ++-- src/serves/backend/fetcher/datasource_configs/error.rs | 2 +- src/serves/backend/fetcher/fetcher_configs/controllers.rs | 2 +- src/serves/backend/fetcher/fetcher_configs/error.rs | 2 +- src/serves/backend/fetcher/global_configs/controllers.rs | 2 +- src/serves/backend/fetcher/global_configs/error.rs | 2 +- src/serves/backend/fetcher/platform_configs/controllers.rs | 2 +- src/serves/backend/fetcher/platform_configs/error.rs | 2 +- src/serves/backend/user_auth/controllers.rs | 2 +- src/serves/backend/user_auth/mod.rs | 2 +- src/serves/cdn/bakery_mansion/controllers.rs | 2 +- src/serves/cdn/bakery_mansion/error.rs | 2 +- src/serves/cdn/ceobe/cookie/main_list/controllers.rs | 2 +- src/serves/cdn/ceobe/cookie/main_list/error.rs | 2 +- src/serves/cdn/ceobe/cookie/temp_list/controllers.rs | 2 +- src/serves/cdn/ceobe/cookie/temp_list/error.rs | 2 +- src/serves/cdn/ceobe/operation/announcement/controllers.rs | 2 +- src/serves/cdn/ceobe/operation/announcement/error.rs | 2 +- src/serves/cdn/ceobe/operation/resource/controllers.rs | 2 +- src/serves/cdn/ceobe/operation/resource/error.rs | 2 +- src/serves/cdn/ceobe/operation/video/controllers.rs | 2 +- src/serves/cdn/ceobe/operation/video/error.rs | 2 +- src/serves/frontend/bakery_mansion/controllers.rs | 2 +- src/serves/frontend/bakery_mansion/mod.rs | 2 +- src/serves/frontend/ceobe/cookie/basic_info/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/basic_info/error.rs | 2 +- src/serves/frontend/ceobe/cookie/search/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/search/error.rs | 2 +- src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/terra_comic/error.rs | 2 +- .../frontend/ceobe/operation/announcement/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/announcement/error.rs | 2 +- src/serves/frontend/ceobe/operation/resource/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/resource/error.rs | 2 +- .../frontend/ceobe/operation/tool_link/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/tool_link/error.rs | 2 +- src/serves/frontend/ceobe/operation/version/controllers.rs | 4 ++++ src/serves/frontend/ceobe/operation/version/error.rs | 2 +- src/serves/frontend/ceobe/operation/video/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/video/error.rs | 2 +- src/serves/frontend/ceobe/user/controllers.rs | 2 +- src/serves/frontend/ceobe/user/error.rs | 2 +- src/serves/frontend/config/datasource/controllers.rs | 2 +- src/serves/frontend/config/datasource/error.rs | 2 +- src/serves/frontend/config/fetcher/controllers.rs | 2 +- src/serves/frontend/config/fetcher/error.rs | 2 +- src/serves/inside/analyze/cookie/controllers.rs | 2 +- src/serves/inside/analyze/cookie/error.rs | 2 +- 83 files changed, 95 insertions(+), 89 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d00aea8..9abc0178 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,8 @@ once_cell = "1" reqwest = { version = "0.12", default-features = false, features = [ "rustls-tls", ] } -resp-result = { version = "0.7", package = "axum-resp-result"} +axum-resp-result = { version = "0.7.1"} + sea-orm = { version = "0.12", default-features = false, features = [ "sqlx-mysql", "runtime-tokio-rustls", @@ -160,6 +161,7 @@ bitmap-convert.workspace = true bitmaps.workspace = true persistence = { workspace = true, features = ["prelude", "migrate"] } tencent-cloud-server.workspace = true +semver = { version = "1.0.23", features = ["serde"] } [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = "0.5.4" @@ -187,7 +189,7 @@ path = "./libs/logger" [dependencies.status-err] path = "./libs/status-err" -[dependencies.resp-result] +[dependencies.axum-resp-result] workspace = true [dependencies.checker] diff --git a/libs/checker/Cargo.toml b/libs/checker/Cargo.toml index 12a39d85..c9ff935d 100644 --- a/libs/checker/Cargo.toml +++ b/libs/checker/Cargo.toml @@ -14,7 +14,7 @@ check-obj-macro = { path = "../../macros/check-obj-macro" } num-traits = "0.2" async-trait = { workspace = true } axum = { workspace = true } -resp-result = { workspace = true } +axum-resp-result = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } smallvec = { workspace = true } diff --git a/libs/checker/src/check_prehandle.rs b/libs/checker/src/check_prehandle.rs index 0ca2c374..41ea342e 100644 --- a/libs/checker/src/check_prehandle.rs +++ b/libs/checker/src/check_prehandle.rs @@ -6,7 +6,7 @@ use axum::{ http::request::Parts, Form, Json, }; -use resp_result::{FromRequestFamily, Nil, RespError, RespResult, ToInner}; +use axum_resp_result::{FromRequestFamily, Nil, RespError, RespResult, ToInner}; use crate::{Checker as DataChecker, LiteArgs}; diff --git a/libs/modify-cache/Cargo.toml b/libs/modify-cache/Cargo.toml index e8deb44b..ad14cf11 100644 --- a/libs/modify-cache/Cargo.toml +++ b/libs/modify-cache/Cargo.toml @@ -16,7 +16,7 @@ chrono = { workspace = true } http = "1" axum = { workspace = true, features = ["original-uri"] } async-trait = { workspace = true } -resp-result = { workspace = true } +axum-resp-result = { workspace = true } # utils thiserror = { workspace = true } base64 = "0.13" diff --git a/libs/modify-cache/src/cache_ctrl/control.rs b/libs/modify-cache/src/cache_ctrl/control.rs index f90b3a76..68d9019e 100644 --- a/libs/modify-cache/src/cache_ctrl/control.rs +++ b/libs/modify-cache/src/cache_ctrl/control.rs @@ -1,7 +1,7 @@ use std::{ops::Add, time::Duration}; use http::{header::CACHE_CONTROL, HeaderValue}; -use resp_result::{ExtraFlag, ExtraFlags}; +use axum_resp_result::{ExtraFlag, ExtraFlags}; #[derive(Debug, Default)] /// 可缓存性 diff --git a/libs/modify-cache/src/cache_ctrl/mod.rs b/libs/modify-cache/src/cache_ctrl/mod.rs index 992b30b6..4e704751 100644 --- a/libs/modify-cache/src/cache_ctrl/mod.rs +++ b/libs/modify-cache/src/cache_ctrl/mod.rs @@ -4,7 +4,7 @@ use http::{ header::{HeaderName, CONTENT_LOCATION, VARY}, Uri, }; -use resp_result::{ExtraFlag, ExtraFlags}; +use axum_resp_result::{ExtraFlag, ExtraFlags}; use self::control::CacheControl; diff --git a/libs/modify-cache/src/check_modify.rs b/libs/modify-cache/src/check_modify.rs index 7478b523..de0c85ea 100644 --- a/libs/modify-cache/src/check_modify.rs +++ b/libs/modify-cache/src/check_modify.rs @@ -8,7 +8,7 @@ use http::{ request::Parts, StatusCode, }; -use resp_result::{ExtraFlag, ExtraFlags}; +use axum_resp_result::{ExtraFlag, ExtraFlags}; use tracing::warn; use crate::{ diff --git a/libs/status-err/Cargo.toml b/libs/status-err/Cargo.toml index 53ff34d8..c0e32f6c 100644 --- a/libs/status-err/Cargo.toml +++ b/libs/status-err/Cargo.toml @@ -35,7 +35,7 @@ workspace = true [dependencies.range-limit] path = "../range-limit" -[dependencies.resp-result] +[dependencies.axum-resp-result] workspace = true features = ["extra-error"] diff --git a/libs/status-err/src/codegen.rs b/libs/status-err/src/codegen.rs index 1d37b3b7..5b866e0f 100644 --- a/libs/status-err/src/codegen.rs +++ b/libs/status-err/src/codegen.rs @@ -177,7 +177,7 @@ macro_rules! error_wrapper { macro_rules! resp_error_impl { ($t:ty) => { /// 实现 Resp -error 可以作为RespResult的异常 - impl ::resp_result::RespError for $t { + impl ::axum_resp_result::RespError for $t { fn log_message(&self) -> std::borrow::Cow<'_, str> { $crate::StatusErr::information(self) } diff --git a/macros/status-err-derive/Cargo.toml b/macros/status-err-derive/Cargo.toml index 1cc92e82..fa22ec8c 100644 --- a/macros/status-err-derive/Cargo.toml +++ b/macros/status-err-derive/Cargo.toml @@ -14,4 +14,4 @@ darling = "0.14" [dev-dependencies] status-err = { path = "../../libs/status-err" } -resp-result = { workspace = true } +axum-resp-result = { workspace = true } diff --git a/middle-server/qq-channel-warning/Cargo.toml b/middle-server/qq-channel-warning/Cargo.toml index f59c50b7..b668e922 100644 --- a/middle-server/qq-channel-warning/Cargo.toml +++ b/middle-server/qq-channel-warning/Cargo.toml @@ -11,7 +11,7 @@ axum-starter.workspace = true http.workspace = true http_02 = {package = "http",version = "0.2"} prost = "0.11.9" -resp-result.workspace = true +axum-resp-result.workspace = true status-err = { version = "0.1.0", path = "../../libs/status-err" } thiserror.workspace = true tonic = "0.9.1" diff --git a/middle-server/qq-channel-warning/src/grpc_client.rs b/middle-server/qq-channel-warning/src/grpc_client.rs index e54bd29f..a677fc18 100644 --- a/middle-server/qq-channel-warning/src/grpc_client.rs +++ b/middle-server/qq-channel-warning/src/grpc_client.rs @@ -1,5 +1,5 @@ use axum::extract::{FromRef, FromRequestParts}; -use resp_result::RespResult; +use axum_resp_result::RespResult; use tonic::transport::Channel; use crate::{ @@ -18,7 +18,7 @@ where S: Send, QqChannelGrpcState: FromRef, { - type Rejection = RespResult; + type Rejection = RespResult; fn from_request_parts<'life0, 'life1, 'async_trait>( _parts: &'life0 mut axum::http::request::Parts, state: &'life1 S, diff --git a/src/bootstrap/init/component_init.rs b/src/bootstrap/init/component_init.rs index 6c9b6bbb..b4cfeddb 100644 --- a/src/bootstrap/init/component_init.rs +++ b/src/bootstrap/init/component_init.rs @@ -1,5 +1,5 @@ use axum_starter::prepare; -use resp_result::ConfigTrait; +use axum_resp_result::ConfigTrait; use crate::utils::{ mob_verify, @@ -10,11 +10,11 @@ use crate::utils::{ #[prepare(RResultConfig?)] fn resp_conf( resp_result: &C, -) -> Result<(), resp_result::SetRespResultConfigureError> +) -> Result<(), axum_resp_result::SetRespResultConfigureError> where C: ConfigTrait, { - resp_result::try_set_config(resp_result) + axum_resp_result::try_set_config(resp_result) } /// 鉴权配置 diff --git a/src/bootstrap/middleware/panic_report.rs b/src/bootstrap/middleware/panic_report.rs index 8e6a047f..a00650a5 100644 --- a/src/bootstrap/middleware/panic_report.rs +++ b/src/bootstrap/middleware/panic_report.rs @@ -5,7 +5,7 @@ use qq_channel_warning::{ qq_channel_logger, GrpcConfigTrait, LogRequest, LogType, QqChannelGrpcService, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use tower_http::catch_panic::{CatchPanicLayer, ResponseForPanic}; use tracing::{error, instrument}; diff --git a/src/configs/resp_result_config.rs b/src/configs/resp_result_config.rs index b32154e0..e7f2bc6c 100644 --- a/src/configs/resp_result_config.rs +++ b/src/configs/resp_result_config.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use resp_result::{ConfigTrait, RespConfig, SignType, StatusSign}; +use axum_resp_result::{ConfigTrait, RespConfig, SignType, StatusSign}; #[derive(Debug, serde::Deserialize)] pub struct RespResultConfig { @@ -22,7 +22,7 @@ pub struct RespResultConfig { impl ConfigTrait for RespResultConfig {} -impl resp_result::SerdeConfig for RespResultConfig { +impl axum_resp_result::SerdeConfig for RespResultConfig { fn body_name(&self) -> Cow<'static, str> { self.body_name.clone().into() } fn err_msg_name(&self) -> Cow<'static, str> { diff --git a/src/error/mod.rs b/src/error/mod.rs index 6ceb46d6..81bac1ad 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -4,7 +4,7 @@ use axum::{ body::Body as BoxBody, extract::OriginalUri, response::IntoResponse, }; use http::Method; -use resp_result::RespResult; +use axum_resp_result::RespResult; use status_err::ErrPrefix; use tracing::{error, instrument, warn}; diff --git a/src/middleware/authorize/mod.rs b/src/middleware/authorize/mod.rs index e66e1aca..12c44ff2 100644 --- a/src/middleware/authorize/mod.rs +++ b/src/middleware/authorize/mod.rs @@ -3,7 +3,7 @@ use axum::extract::FromRequestParts; use http::request::Parts; pub use layer::AuthorizeLayer; use persistence::admin; -use resp_result::{Nil, RespResult}; +use axum_resp_result::{Nil, RespResult}; pub use self::error::AuthorizeError; diff --git a/src/middleware/authorize/service.rs b/src/middleware/authorize/service.rs index cb27d323..3576cb05 100644 --- a/src/middleware/authorize/service.rs +++ b/src/middleware/authorize/service.rs @@ -14,7 +14,7 @@ use persistence::{ }, mysql::SqlDatabaseOperate, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use tap::Tap; use tower_http::auth::AsyncAuthorizeRequest; use tracing::{info, warn, Instrument}; diff --git a/src/middleware/mob/mod.rs b/src/middleware/mob/mod.rs index 53eae265..5519767a 100644 --- a/src/middleware/mob/mod.rs +++ b/src/middleware/mob/mod.rs @@ -3,7 +3,7 @@ use axum::extract::FromRequestParts; use http::request::Parts; pub use layer::MobVerifyLayer; use persistence::ceobe_user::models::models::UserMobId; -use resp_result::{Nil, RespResult}; +use axum_resp_result::{Nil, RespResult}; use self::error::MobVerifyError; diff --git a/src/middleware/mob/service.rs b/src/middleware/mob/service.rs index bcb7be27..25997f4b 100644 --- a/src/middleware/mob/service.rs +++ b/src/middleware/mob/service.rs @@ -11,7 +11,7 @@ use persistence::{ ceobe_user::{models::models::UserMobId, ToCeobeUser}, mongodb::MongoDatabaseOperate, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use tap::Tap; use tower_http::auth::AsyncAuthorizeRequest; use tracing::{info, Instrument}; diff --git a/src/serves/backend/bakery_mansion/controllers.rs b/src/serves/backend/bakery_mansion/controllers.rs index 9a4355ad..ee7c2569 100644 --- a/src/serves/backend/bakery_mansion/controllers.rs +++ b/src/serves/backend/bakery_mansion/controllers.rs @@ -1,7 +1,7 @@ use bakery_logic::{impletements::BakeryLogic, view::MansionResp}; use checker::CheckExtract; use persistence::mongodb::MongoDatabaseOperate; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/bakery_mansion/mod.rs b/src/serves/backend/bakery_mansion/mod.rs index 0dca3ea1..8ad2c429 100644 --- a/src/serves/backend/bakery_mansion/mod.rs +++ b/src/serves/backend/bakery_mansion/mod.rs @@ -1,4 +1,4 @@ -use resp_result::RespResult; +use axum_resp_result::RespResult; pub mod controllers; pub(crate) mod error; diff --git a/src/serves/backend/ceobe_cookie/newest/controllers.rs b/src/serves/backend/ceobe_cookie/newest/controllers.rs index 00153ef6..bd45b3c8 100644 --- a/src/serves/backend/ceobe_cookie/newest/controllers.rs +++ b/src/serves/backend/ceobe_cookie/newest/controllers.rs @@ -2,7 +2,7 @@ use ceobe_cookie_logic::impletements::CeobeCookieLogic; use ceobe_qiniu_upload::QiniuManager; use persistence::redis::RedisConnect; use qq_channel_warning::QqChannelGrpcService; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::CookieNewestRResult; diff --git a/src/serves/backend/ceobe_cookie/newest/error.rs b/src/serves/backend/ceobe_cookie/newest/error.rs index 3143eec4..1c0d90e0 100644 --- a/src/serves/backend/ceobe_cookie/newest/error.rs +++ b/src/serves/backend/ceobe_cookie/newest/error.rs @@ -1,5 +1,5 @@ use ceobe_cookie_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/announcement/controllers.rs b/src/serves/backend/ceobe_operation/announcement/controllers.rs index d42536ee..7b158865 100644 --- a/src/serves/backend/ceobe_operation/announcement/controllers.rs +++ b/src/serves/backend/ceobe_operation/announcement/controllers.rs @@ -8,7 +8,7 @@ use checker::{ use persistence::{ ceobe_operate::models::announcement, mysql::SqlDatabaseOperate, }; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_operation/announcement/error.rs b/src/serves/backend/ceobe_operation/announcement/error.rs index cc744c50..3e643f82 100644 --- a/src/serves/backend/ceobe_operation/announcement/error.rs +++ b/src/serves/backend/ceobe_operation/announcement/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::announcement; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::{error_generate, utils::user_authorize::error::AuthError}; diff --git a/src/serves/backend/ceobe_operation/app_version/controllers.rs b/src/serves/backend/ceobe_operation/app_version/controllers.rs index b07af82c..2b79f808 100644 --- a/src/serves/backend/ceobe_operation/app_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/app_version/controllers.rs @@ -3,7 +3,7 @@ use persistence::{ ceobe_operate::{models::app_version, ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::{AppRespResult, CeobeOperationAppVersionError}; diff --git a/src/serves/backend/ceobe_operation/desktop_version/controllers.rs b/src/serves/backend/ceobe_operation/desktop_version/controllers.rs index 4e222d14..a49fe3df 100644 --- a/src/serves/backend/ceobe_operation/desktop_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/desktop_version/controllers.rs @@ -3,7 +3,7 @@ use persistence::{ ceobe_operate::{models::desktop_version, ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::{CeobeOperationDesktopVersionError, DesktopRespResult}; diff --git a/src/serves/backend/ceobe_operation/plugin_version/controllers.rs b/src/serves/backend/ceobe_operation/plugin_version/controllers.rs index 96f29509..0a99e9f4 100644 --- a/src/serves/backend/ceobe_operation/plugin_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/plugin_version/controllers.rs @@ -3,7 +3,7 @@ use persistence::{ ceobe_operate::{plugin_version::Checker, ToCeobe, ToCeobeOperation}, mongodb::MongoDatabaseOperate, }; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::{CeobeOperationPluginVersionError, PluginRespResult}; diff --git a/src/serves/backend/ceobe_operation/resource/controller.rs b/src/serves/backend/ceobe_operation/resource/controller.rs index 821a65e5..2c56e68b 100644 --- a/src/serves/backend/ceobe_operation/resource/controller.rs +++ b/src/serves/backend/ceobe_operation/resource/controller.rs @@ -5,7 +5,7 @@ use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::models::resource, mysql::SqlDatabaseOperate, }; -use resp_result::{resp_try, rtry, RespResult}; +use axum_resp_result::{resp_try, rtry, RespResult}; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_operation/resource/error.rs b/src/serves/backend/ceobe_operation/resource/error.rs index c27951cb..1fd9a8dd 100644 --- a/src/serves/backend/ceobe_operation/resource/error.rs +++ b/src/serves/backend/ceobe_operation/resource/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::JsonRejection; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::resource::CheckError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/tool_link/controllers.rs b/src/serves/backend/ceobe_operation/tool_link/controllers.rs index b2837fd9..175381df 100644 --- a/src/serves/backend/ceobe_operation/tool_link/controllers.rs +++ b/src/serves/backend/ceobe_operation/tool_link/controllers.rs @@ -12,7 +12,7 @@ use checker::CheckExtract; use page_size::response::ListWithPageInfo; use persistence::mysql::SqlDatabaseOperate; use qiniu_cdn_upload::UploadWrap; -use resp_result::{resp_try, MapReject}; +use axum_resp_result::{resp_try, MapReject}; use tracing::instrument; use super::error::{ @@ -89,7 +89,7 @@ impl CeobeOpToolLink { pub async fn upload_avatar( qiniu: QiniuManager, multipart: Result, ) -> OperateToolLinkRResult { - resp_result::resp_try(async move { + resp_try(async move { let mut multipart = multipart?; let field = multipart.next_field().await?.ok_or(FieldNotExist)?; diff --git a/src/serves/backend/ceobe_operation/tool_link/error.rs b/src/serves/backend/ceobe_operation/tool_link/error.rs index 02c35220..06fa27e6 100644 --- a/src/serves/backend/ceobe_operation/tool_link/error.rs +++ b/src/serves/backend/ceobe_operation/tool_link/error.rs @@ -12,7 +12,7 @@ use page_size::request::PageSizeChecker; use persistence::ceobe_operate::models::tool_link::{ self, checkers::tool_link_data::PreCheckCeobeOperationToolLinkChecker, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use status_err::{ErrPrefix, StatusErr}; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/video/controllers.rs b/src/serves/backend/ceobe_operation/video/controllers.rs index aec548ac..e8c9a39a 100644 --- a/src/serves/backend/ceobe_operation/video/controllers.rs +++ b/src/serves/backend/ceobe_operation/video/controllers.rs @@ -10,7 +10,7 @@ use persistence::{ mysql::SqlDatabaseOperate, }; use request_clients::bili_client::QueryBiliVideo; -use resp_result::{resp_try, rtry, RespResult}; +use axum_resp_result::{resp_try, rtry, RespResult}; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_operation/video/error.rs b/src/serves/backend/ceobe_operation/video/error.rs index dbf17dfd..d175048b 100644 --- a/src/serves/backend/ceobe_operation/video/error.rs +++ b/src/serves/backend/ceobe_operation/video/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::video; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::{error_generate, utils::user_authorize::error::AuthError}; diff --git a/src/serves/backend/fetcher/datasource_configs/controllers.rs b/src/serves/backend/fetcher/datasource_configs/controllers.rs index d39c8dd4..215f8517 100644 --- a/src/serves/backend/fetcher/datasource_configs/controllers.rs +++ b/src/serves/backend/fetcher/datasource_configs/controllers.rs @@ -23,7 +23,7 @@ use persistence::{ }; use qiniu_cdn_upload::UploadWrap; use qq_channel_warning::QqChannelGrpcService; -use resp_result::{resp_try, rtry, MapReject}; +use axum_resp_result::{resp_try, rtry, MapReject}; use scheduler_notifier::SchedulerNotifier; use tracing::instrument; @@ -180,7 +180,7 @@ impl FetcherConfigControllers { pub async fn upload_avatar( qiniu: QiniuManager, multipart: Result, ) -> DatasourceConfigRResult { - resp_result::resp_try(async move { + axum_resp_result::resp_try(async move { let mut multipart = multipart?; let field = multipart.next_field().await?.ok_or(FieldNotExist)?; diff --git a/src/serves/backend/fetcher/datasource_configs/error.rs b/src/serves/backend/fetcher/datasource_configs/error.rs index 4100bdc5..d41435e6 100644 --- a/src/serves/backend/fetcher/datasource_configs/error.rs +++ b/src/serves/backend/fetcher/datasource_configs/error.rs @@ -10,7 +10,7 @@ use persistence::fetcher::{ models::datasource_config::checkers::CheckError, platform_config::OperateError as PlatformOperateError, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use status_err::{ErrPrefix, StatusErr}; use crate::error_generate; diff --git a/src/serves/backend/fetcher/fetcher_configs/controllers.rs b/src/serves/backend/fetcher/fetcher_configs/controllers.rs index ceb47f66..e9f20cd1 100644 --- a/src/serves/backend/fetcher/fetcher_configs/controllers.rs +++ b/src/serves/backend/fetcher/fetcher_configs/controllers.rs @@ -4,7 +4,7 @@ use fetcher_logic::{ view::{BackEndFetcherConfig, MaxLiveNumberResp, PlatformFilterReq}, }; use persistence::{mysql::SqlDatabaseOperate, redis::RedisConnect}; -use resp_result::{resp_try, rtry, MapReject}; +use axum_resp_result::{resp_try, rtry, MapReject}; use scheduler_notifier::SchedulerNotifier; use tracing::instrument; diff --git a/src/serves/backend/fetcher/fetcher_configs/error.rs b/src/serves/backend/fetcher/fetcher_configs/error.rs index 2db82bb6..a0b6b0ab 100644 --- a/src/serves/backend/fetcher/fetcher_configs/error.rs +++ b/src/serves/backend/fetcher/fetcher_configs/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; use fetcher_logic::error::LogicError; use persistence::fetcher::config::OperateError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/fetcher/global_configs/controllers.rs b/src/serves/backend/fetcher/global_configs/controllers.rs index dfb31bac..c8f17cab 100644 --- a/src/serves/backend/fetcher/global_configs/controllers.rs +++ b/src/serves/backend/fetcher/global_configs/controllers.rs @@ -1,7 +1,7 @@ use axum::Json; use fetcher_logic::implements::FetcherConfigLogic; use persistence::mysql::SqlDatabaseOperate; -use resp_result::{rtry, MapReject, RespResult}; +use axum_resp_result::{rtry, MapReject, RespResult}; use serde_json::{Map, Value}; use tracing::instrument; diff --git a/src/serves/backend/fetcher/global_configs/error.rs b/src/serves/backend/fetcher/global_configs/error.rs index 486bbf5c..bc885299 100644 --- a/src/serves/backend/fetcher/global_configs/error.rs +++ b/src/serves/backend/fetcher/global_configs/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::JsonRejection; use fetcher_logic::error::LogicError; use persistence::fetcher::models::global_config::checkers::CheckError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/fetcher/platform_configs/controllers.rs b/src/serves/backend/fetcher/platform_configs/controllers.rs index 22ccae85..5c9597d9 100644 --- a/src/serves/backend/fetcher/platform_configs/controllers.rs +++ b/src/serves/backend/fetcher/platform_configs/controllers.rs @@ -13,7 +13,7 @@ use persistence::{ }, mysql::SqlDatabaseOperate, }; -use resp_result::{resp_try, rtry, MapReject}; +use axum_resp_result::{resp_try, rtry, MapReject}; use tracing::instrument; use super::{ diff --git a/src/serves/backend/fetcher/platform_configs/error.rs b/src/serves/backend/fetcher/platform_configs/error.rs index e5f6d42e..214a7d7d 100644 --- a/src/serves/backend/fetcher/platform_configs/error.rs +++ b/src/serves/backend/fetcher/platform_configs/error.rs @@ -4,7 +4,7 @@ use fetcher_logic::error::LogicError; use persistence::fetcher::{ models::platform_config, platform_config::OperateError, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/user_auth/controllers.rs b/src/serves/backend/user_auth/controllers.rs index 09d2ea5a..1f366b49 100644 --- a/src/serves/backend/user_auth/controllers.rs +++ b/src/serves/backend/user_auth/controllers.rs @@ -11,7 +11,7 @@ use persistence::{ mysql::SqlDatabaseOperate, }; use rand::{distributions::Alphanumeric, thread_rng, Rng}; -use resp_result::{resp_try, rtry, MapReject}; +use axum_resp_result::{resp_try, rtry, MapReject}; use tracing::{debug, instrument}; use super::{ diff --git a/src/serves/backend/user_auth/mod.rs b/src/serves/backend/user_auth/mod.rs index bc9fa6c3..aa07873c 100644 --- a/src/serves/backend/user_auth/mod.rs +++ b/src/serves/backend/user_auth/mod.rs @@ -1,7 +1,7 @@ use checker::{JsonCheckExtract, QueryCheckExtract}; use page_size::request::PageSizeChecker; use persistence::admin::models::username::Checker; -use resp_result::RespResult; +use axum_resp_result::RespResult; use self::error::AdminUserError; diff --git a/src/serves/cdn/bakery_mansion/controllers.rs b/src/serves/cdn/bakery_mansion/controllers.rs index 49a14ff9..3effe7a3 100644 --- a/src/serves/cdn/bakery_mansion/controllers.rs +++ b/src/serves/cdn/bakery_mansion/controllers.rs @@ -4,7 +4,7 @@ use bakery_logic::{ }; use checker::CheckExtract; use persistence::mongodb::MongoDatabaseOperate; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::{MansionRResult, MidCheckerPretreatment}; diff --git a/src/serves/cdn/bakery_mansion/error.rs b/src/serves/cdn/bakery_mansion/error.rs index 762aebc3..b0e7a712 100644 --- a/src/serves/cdn/bakery_mansion/error.rs +++ b/src/serves/cdn/bakery_mansion/error.rs @@ -7,7 +7,7 @@ use persistence::bakery::{ checkers::CheckError, preludes::id_checker::MidChecker, }, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/cookie/main_list/controllers.rs b/src/serves/cdn/ceobe/cookie/main_list/controllers.rs index 835b3091..aa42b873 100644 --- a/src/serves/cdn/ceobe/cookie/main_list/controllers.rs +++ b/src/serves/cdn/ceobe/cookie/main_list/controllers.rs @@ -7,7 +7,7 @@ use persistence::{ mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, redis::RedisConnect, }; -use resp_result::{rtry, MapReject}; +use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieMainListError, CeobeCookieRResult}; diff --git a/src/serves/cdn/ceobe/cookie/main_list/error.rs b/src/serves/cdn/ceobe/cookie/main_list/error.rs index bb18894c..582e41a2 100644 --- a/src/serves/cdn/ceobe/cookie/main_list/error.rs +++ b/src/serves/cdn/ceobe/cookie/main_list/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::QueryRejection; use ceobe_cookie_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs b/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs index a0a1966a..e828a7ae 100644 --- a/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs +++ b/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs @@ -4,7 +4,7 @@ use ceobe_cookie_logic::{ view::{CookieListReq, CookieTempListResp}, }; use persistence::{mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate}; -use resp_result::{rtry, MapReject}; +use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieRResult, CeobeCookieTempListError}; diff --git a/src/serves/cdn/ceobe/cookie/temp_list/error.rs b/src/serves/cdn/ceobe/cookie/temp_list/error.rs index 3ec6812b..d07ff740 100644 --- a/src/serves/cdn/ceobe/cookie/temp_list/error.rs +++ b/src/serves/cdn/ceobe/cookie/temp_list/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::QueryRejection; use ceobe_cookie_logic::error::LogicError; use persistence::ceobe_cookie::temp_list::OperateError as TempListOperateError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/operation/announcement/controllers.rs b/src/serves/cdn/ceobe/operation/announcement/controllers.rs index c15d77be..6a7927db 100644 --- a/src/serves/cdn/ceobe/operation/announcement/controllers.rs +++ b/src/serves/cdn/ceobe/operation/announcement/controllers.rs @@ -2,7 +2,7 @@ use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::AnnouncementResp, }; use persistence::mysql::SqlDatabaseOperate; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::AnnouncementRespResult; diff --git a/src/serves/cdn/ceobe/operation/announcement/error.rs b/src/serves/cdn/ceobe/operation/announcement/error.rs index 6c7f0ee5..afaaf8a4 100644 --- a/src/serves/cdn/ceobe/operation/announcement/error.rs +++ b/src/serves/cdn/ceobe/operation/announcement/error.rs @@ -1,5 +1,5 @@ use ceobe_operation_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/operation/resource/controllers.rs b/src/serves/cdn/ceobe/operation/resource/controllers.rs index b5e44dd7..6a9ae88c 100644 --- a/src/serves/cdn/ceobe/operation/resource/controllers.rs +++ b/src/serves/cdn/ceobe/operation/resource/controllers.rs @@ -2,7 +2,7 @@ use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::Resource, }; use persistence::mysql::SqlDatabaseOperate; -use resp_result::{rtry, RespResult}; +use axum_resp_result::{rtry, RespResult}; use tracing::instrument; use super::error::ResourceRespResult; diff --git a/src/serves/cdn/ceobe/operation/resource/error.rs b/src/serves/cdn/ceobe/operation/resource/error.rs index 2c32cc6f..1f855ccb 100644 --- a/src/serves/cdn/ceobe/operation/resource/error.rs +++ b/src/serves/cdn/ceobe/operation/resource/error.rs @@ -1,6 +1,6 @@ use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::resource; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/operation/video/controllers.rs b/src/serves/cdn/ceobe/operation/video/controllers.rs index 1427627a..3b3672e3 100644 --- a/src/serves/cdn/ceobe/operation/video/controllers.rs +++ b/src/serves/cdn/ceobe/operation/video/controllers.rs @@ -2,7 +2,7 @@ use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::VideoItem, }; use persistence::mysql::SqlDatabaseOperate; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::VideoRespResult; diff --git a/src/serves/cdn/ceobe/operation/video/error.rs b/src/serves/cdn/ceobe/operation/video/error.rs index 699bc69a..a4d4b5c9 100644 --- a/src/serves/cdn/ceobe/operation/video/error.rs +++ b/src/serves/cdn/ceobe/operation/video/error.rs @@ -1,5 +1,5 @@ use ceobe_operation_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/bakery_mansion/controllers.rs b/src/serves/frontend/bakery_mansion/controllers.rs index ebdc8217..83e6ff20 100644 --- a/src/serves/frontend/bakery_mansion/controllers.rs +++ b/src/serves/frontend/bakery_mansion/controllers.rs @@ -7,7 +7,7 @@ use persistence::{ bakery::{mansion::ToMansion, ToBakery}, mongodb::MongoDatabaseOperate, }; -use resp_result::{resp_try, FlagWrap}; +use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{ diff --git a/src/serves/frontend/bakery_mansion/mod.rs b/src/serves/frontend/bakery_mansion/mod.rs index 8a5ac390..0b7a2e29 100644 --- a/src/serves/frontend/bakery_mansion/mod.rs +++ b/src/serves/frontend/bakery_mansion/mod.rs @@ -1,4 +1,4 @@ -use resp_result::{FlagRespResult, RespResult}; +use axum_resp_result::{FlagRespResult, RespResult}; pub mod controllers; pub(crate) mod error; diff --git a/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs b/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs index 58cd8a99..5fc7565a 100644 --- a/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs +++ b/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs @@ -2,7 +2,7 @@ use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::CookieNumberResp, }; use persistence::mongodb::MongoDatabaseOperate; -use resp_result::rtry; +use axum_resp_result::rtry; use tracing::instrument; use super::error::CeobeCookieRResult; diff --git a/src/serves/frontend/ceobe/cookie/basic_info/error.rs b/src/serves/frontend/ceobe/cookie/basic_info/error.rs index a165a342..0b7ec7e3 100644 --- a/src/serves/frontend/ceobe/cookie/basic_info/error.rs +++ b/src/serves/frontend/ceobe/cookie/basic_info/error.rs @@ -1,5 +1,5 @@ use ceobe_cookie_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/cookie/search/controllers.rs b/src/serves/frontend/ceobe/cookie/search/controllers.rs index 938156c8..d6530cef 100644 --- a/src/serves/frontend/ceobe/cookie/search/controllers.rs +++ b/src/serves/frontend/ceobe/cookie/search/controllers.rs @@ -4,7 +4,7 @@ use ceobe_cookie_logic::{ view::{CookieListResp, SearchListReq}, }; use persistence::{mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate}; -use resp_result::{rtry, MapReject}; +use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieRResult, CeobeCookieSearchError}; diff --git a/src/serves/frontend/ceobe/cookie/search/error.rs b/src/serves/frontend/ceobe/cookie/search/error.rs index 3f4d52b7..fe1012e3 100644 --- a/src/serves/frontend/ceobe/cookie/search/error.rs +++ b/src/serves/frontend/ceobe/cookie/search/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::QueryRejection; use ceobe_cookie_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs b/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs index e571d5f5..aba72f4b 100644 --- a/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs +++ b/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs @@ -7,7 +7,7 @@ use persistence::{ ceobe_cookie::models::analyze::models::TerraComicEpisodeInfo, mongodb::MongoDatabaseOperate, }; -use resp_result::{rtry, MapReject}; +use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieRResult, CeobeCookieTerraComicError}; diff --git a/src/serves/frontend/ceobe/cookie/terra_comic/error.rs b/src/serves/frontend/ceobe/cookie/terra_comic/error.rs index dd471ed7..73f6a7e0 100644 --- a/src/serves/frontend/ceobe/cookie/terra_comic/error.rs +++ b/src/serves/frontend/ceobe/cookie/terra_comic/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::QueryRejection; use ceobe_cookie_logic::error::LogicError; use persistence::ceobe_cookie::terra_comic::OperateError as TerraComicOperateError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/announcement/controllers.rs b/src/serves/frontend/ceobe/operation/announcement/controllers.rs index f029ed2e..0b174e75 100644 --- a/src/serves/frontend/ceobe/operation/announcement/controllers.rs +++ b/src/serves/frontend/ceobe/operation/announcement/controllers.rs @@ -3,7 +3,7 @@ use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use resp_result::{resp_try, FlagWrap}; +use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{ diff --git a/src/serves/frontend/ceobe/operation/announcement/error.rs b/src/serves/frontend/ceobe/operation/announcement/error.rs index ed9a3daa..06821ba1 100644 --- a/src/serves/frontend/ceobe/operation/announcement/error.rs +++ b/src/serves/frontend/ceobe/operation/announcement/error.rs @@ -1,5 +1,5 @@ use persistence::ceobe_operate::announcement; -use resp_result::FlagRespResult; +use axum_resp_result::FlagRespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/resource/controllers.rs b/src/serves/frontend/ceobe/operation/resource/controllers.rs index 18e7f3d9..c81a7e5a 100644 --- a/src/serves/frontend/ceobe/operation/resource/controllers.rs +++ b/src/serves/frontend/ceobe/operation/resource/controllers.rs @@ -4,7 +4,7 @@ use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use resp_result::{resp_try, FlagWrap}; +use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{error::FlagResourceRespResult, view::Resource}; diff --git a/src/serves/frontend/ceobe/operation/resource/error.rs b/src/serves/frontend/ceobe/operation/resource/error.rs index 0dab55a2..7ffd2803 100644 --- a/src/serves/frontend/ceobe/operation/resource/error.rs +++ b/src/serves/frontend/ceobe/operation/resource/error.rs @@ -1,5 +1,5 @@ use persistence::ceobe_operate::resource; -use resp_result::FlagRespResult; +use axum_resp_result::FlagRespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/tool_link/controllers.rs b/src/serves/frontend/ceobe/operation/tool_link/controllers.rs index 419798c9..517126c0 100644 --- a/src/serves/frontend/ceobe/operation/tool_link/controllers.rs +++ b/src/serves/frontend/ceobe/operation/tool_link/controllers.rs @@ -2,7 +2,7 @@ use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::ToolLinkResp, }; use persistence::mysql::SqlDatabaseOperate; -use resp_result::resp_try; +use axum_resp_result::resp_try; use tracing::instrument; use super::error::OperateToolLinkRResult; diff --git a/src/serves/frontend/ceobe/operation/tool_link/error.rs b/src/serves/frontend/ceobe/operation/tool_link/error.rs index 90416ade..0654dd28 100644 --- a/src/serves/frontend/ceobe/operation/tool_link/error.rs +++ b/src/serves/frontend/ceobe/operation/tool_link/error.rs @@ -1,5 +1,5 @@ use ceobe_operation_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 058f8385..5d83dfce 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -1,5 +1,9 @@ use std::time::Duration; +use axum::extract::Query; +use axum_resp_result::{FlagWrap, MapReject, resp_result, resp_try}; +use tracing::instrument; + use checker::CheckExtract; use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, diff --git a/src/serves/frontend/ceobe/operation/version/error.rs b/src/serves/frontend/ceobe/operation/version/error.rs index 2d7a8d73..493a3236 100644 --- a/src/serves/frontend/ceobe/operation/version/error.rs +++ b/src/serves/frontend/ceobe/operation/version/error.rs @@ -6,7 +6,7 @@ use persistence::{ models::{app_version, plugin_version}, }, }; -use resp_result::FlagRespResult; +use axum_resp_result::FlagRespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/video/controllers.rs b/src/serves/frontend/ceobe/operation/video/controllers.rs index 12282ee1..ba39110d 100644 --- a/src/serves/frontend/ceobe/operation/video/controllers.rs +++ b/src/serves/frontend/ceobe/operation/video/controllers.rs @@ -4,7 +4,7 @@ use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use resp_result::{resp_try, FlagWrap}; +use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{ diff --git a/src/serves/frontend/ceobe/operation/video/error.rs b/src/serves/frontend/ceobe/operation/video/error.rs index ce186f43..b48e0faa 100644 --- a/src/serves/frontend/ceobe/operation/video/error.rs +++ b/src/serves/frontend/ceobe/operation/video/error.rs @@ -1,5 +1,5 @@ use persistence::ceobe_operate::video; -use resp_result::FlagRespResult; +use axum_resp_result::FlagRespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/user/controllers.rs b/src/serves/frontend/ceobe/user/controllers.rs index c4bd6fa9..e656b76f 100644 --- a/src/serves/frontend/ceobe/user/controllers.rs +++ b/src/serves/frontend/ceobe/user/controllers.rs @@ -10,7 +10,7 @@ use persistence::{ mysql::SqlDatabaseOperate, redis::RedisConnect, }; -use resp_result::{rtry, MapReject}; +use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeUserError, CeobeUserRResult}; diff --git a/src/serves/frontend/ceobe/user/error.rs b/src/serves/frontend/ceobe/user/error.rs index f94bf457..c5212875 100644 --- a/src/serves/frontend/ceobe/user/error.rs +++ b/src/serves/frontend/ceobe/user/error.rs @@ -4,7 +4,7 @@ use persistence::ceobe_user::{ models::check::CheckError as CeobeUserPropertyCheckError, property::OperateError, }; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/config/datasource/controllers.rs b/src/serves/frontend/config/datasource/controllers.rs index da84312a..973ef588 100644 --- a/src/serves/frontend/config/datasource/controllers.rs +++ b/src/serves/frontend/config/datasource/controllers.rs @@ -6,7 +6,7 @@ use persistence::{ }, mysql::SqlDatabaseOperate, }; -use resp_result::rtry; +use axum_resp_result::rtry; use tracing::instrument; use crate::{ diff --git a/src/serves/frontend/config/datasource/error.rs b/src/serves/frontend/config/datasource/error.rs index 38d1bdd8..0e41822c 100644 --- a/src/serves/frontend/config/datasource/error.rs +++ b/src/serves/frontend/config/datasource/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::QueryRejection; use persistence::fetcher::datasource_config::OperateError as DatasourceOperateError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/config/fetcher/controllers.rs b/src/serves/frontend/config/fetcher/controllers.rs index 5963b196..3ebac616 100644 --- a/src/serves/frontend/config/fetcher/controllers.rs +++ b/src/serves/frontend/config/fetcher/controllers.rs @@ -5,7 +5,7 @@ use bitmap_convert::{ use bitmaps::Bitmap; use general_request_client::{client::RequestClient, traits::Requester}; use http::{Method, Version}; -use resp_result::resp_try; +use axum_resp_result::resp_try; use scheduler_notifier::SchedulerUrl; use serde_json::{json, Value}; use tap::Tap; diff --git a/src/serves/frontend/config/fetcher/error.rs b/src/serves/frontend/config/fetcher/error.rs index 13f0670b..4bf58ae7 100644 --- a/src/serves/frontend/config/fetcher/error.rs +++ b/src/serves/frontend/config/fetcher/error.rs @@ -1,4 +1,4 @@ -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/inside/analyze/cookie/controllers.rs b/src/serves/inside/analyze/cookie/controllers.rs index dfe0d646..b348b034 100644 --- a/src/serves/inside/analyze/cookie/controllers.rs +++ b/src/serves/inside/analyze/cookie/controllers.rs @@ -9,7 +9,7 @@ use persistence::{ redis::RedisConnect, }; use qq_channel_warning::QqChannelGrpcService; -use resp_result::{resp_try, MapReject}; +use axum_resp_result::{resp_try, MapReject}; use tracing::instrument; use super::error::{AnalyzeCookieError, AnalyzeCookieRResult}; diff --git a/src/serves/inside/analyze/cookie/error.rs b/src/serves/inside/analyze/cookie/error.rs index 916cf5f1..de536aec 100644 --- a/src/serves/inside/analyze/cookie/error.rs +++ b/src/serves/inside/analyze/cookie/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::JsonRejection; use ceobe_cookie_logic::error::LogicError; -use resp_result::RespResult; +use axum_resp_result::RespResult; use crate::error_generate; From 4b9b108001c5d4fcb0bf0d88ff44d4cba305b387 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 11:53:16 +0800 Subject: [PATCH 16/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0ReleaseVer?= =?UTF-8?q?sion=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/plugin_version/models/mod.rs | 2 +- .../ceobe/operation/version/models/conv.rs | 2 +- .../src/ceobe/operation/version/models/mod.rs | 2 + .../operation/version/models/modify_state.rs | 14 +++++ .../app_version/checkers/app_version_data.rs | 2 +- .../checkers/desktop_version_data.rs | 2 +- .../app_version/controllers.rs | 17 ++++-- .../ceobe_operation/app_version/error.rs | 5 +- .../desktop_version/controllers.rs | 16 ++++-- .../ceobe_operation/desktop_version/error.rs | 5 +- .../plugin_version/controllers.rs | 9 +++- .../ceobe_operation/plugin_version/error.rs | 4 +- .../ceobe/operation/version/controllers.rs | 52 +++++++++++++++++-- .../frontend/ceobe/operation/version/error.rs | 4 +- .../ceobe/operation/version/models.rs | 7 +++ 15 files changed, 120 insertions(+), 23 deletions(-) create mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs diff --git a/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs index d322352e..61b2de16 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs @@ -29,7 +29,7 @@ pub struct DownloadResource { #[sub_model(all( vis = "pub", name = "PluginVersionChecked", - extra(derive(Debug, TypedBuilder)) + extra(derive(Debug, TypedBuilder,Clone)) ))] pub struct PluginVersion { pub version: Version, diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs index e503781b..2e70d6ed 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs @@ -7,7 +7,7 @@ use crate::ceobe::operation::{ version::models::{ DownloadSourceItem, ForceCtrl, Primary, ReleasePlatform::{Desktop, Plugin, Pocket}, - ReleaseVersion, ResourceUrl, SupportPlatform, + ReleaseVersion, ResourceUrl, SupportPlatform::{Android, MacOS, Windows}, }, }; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 347a12d4..a21ffe7a 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -4,6 +4,8 @@ mod platform; mod primary; mod version; mod conv; +mod modify_state; + pub use download_source::{DownloadSourceItem, ResourceUrl}; pub use force::ForceCtrl; pub use platform::{ReleasePlatform, SupportPlatform}; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs new file mode 100644 index 00000000..dfcc8f57 --- /dev/null +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs @@ -0,0 +1,14 @@ +use std::borrow::Cow; + +use modify_cache::ModifyState; +use semver::Version; + +use crate::ceobe::operation::version::models::{ReleasePlatform, ReleaseVersion}; + +impl ModifyState for ReleaseVersion { + type Identify = (Version, ReleasePlatform); + + fn get_identify(&self) -> Cow<'_, Self::Identify> { + Cow::Owned((self.version.clone(), self.platform)) + } +} diff --git a/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs b/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs index e086d126..4fc6d9cf 100644 --- a/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs +++ b/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs @@ -12,7 +12,7 @@ use crate::{ get_now_naive_date_time, }; -#[derive(Debug, TypedBuilder)] +#[derive(Debug, TypedBuilder,Clone)] pub struct CeobeOperationAppVersion { pub version: String, pub force: bool, diff --git a/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs b/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs index 85da1d2d..85be2bde 100644 --- a/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs +++ b/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs @@ -12,7 +12,7 @@ use crate::{ get_now_naive_date_time, }; -#[derive(Debug, TypedBuilder)] +#[derive(Debug, TypedBuilder,Clone)] pub struct CeobeOperationDesktopVersion { pub version: String, pub force: bool, diff --git a/src/serves/backend/ceobe_operation/app_version/controllers.rs b/src/serves/backend/ceobe_operation/app_version/controllers.rs index 2b79f808..328cc75e 100644 --- a/src/serves/backend/ceobe_operation/app_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/app_version/controllers.rs @@ -1,7 +1,9 @@ use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::{models::app_version, ToCeobe, ToCeobeOperation}, + mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, + operate::operate_trait::OperateTrait, }; use axum_resp_result::resp_try; use tracing::instrument; @@ -14,17 +16,24 @@ type CreateAppVersionCheck = impl CeobeOpVersion { // 新增一个app版本 - #[instrument(ret, skip(db))] + #[instrument(ret, skip(db, mongo))] pub async fn create_app_version( - db: SqlDatabaseOperate, CheckExtract(version): CreateAppVersionCheck, + db: SqlDatabaseOperate, mongo: MongoDatabaseOperate, + CheckExtract(version): CreateAppVersionCheck, ) -> AppRespResult<()> { resp_try(async { db.ceobe() .operation() .app_version() - .create_one(version) + .create_one(version.clone()) + .await?; + mongo + .ceobe() + .operation() + .release_version() + .create() + .one(version) .await?; - Ok(()) }) .await diff --git a/src/serves/backend/ceobe_operation/app_version/error.rs b/src/serves/backend/ceobe_operation/app_version/error.rs index c09c8241..9111907d 100644 --- a/src/serves/backend/ceobe_operation/app_version/error.rs +++ b/src/serves/backend/ceobe_operation/app_version/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::JsonRejection; -use persistence::ceobe_operate::app_version; -use resp_result::RespResult; +use persistence::ceobe_operate::{app_version, release_version}; +use axum_resp_result::RespResult; use crate::error_generate; @@ -10,6 +10,7 @@ error_generate! { Json = JsonRejection Check = app_version::CheckError DbOperate = app_version::OperateError + ReleaseDbError = release_version::Error } pub(super) type AppRespResult = diff --git a/src/serves/backend/ceobe_operation/desktop_version/controllers.rs b/src/serves/backend/ceobe_operation/desktop_version/controllers.rs index a49fe3df..dbc2e35f 100644 --- a/src/serves/backend/ceobe_operation/desktop_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/desktop_version/controllers.rs @@ -1,10 +1,12 @@ use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::{models::desktop_version, ToCeobe, ToCeobeOperation}, + mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, }; use axum_resp_result::resp_try; use tracing::instrument; +use persistence::operate::operate_trait::OperateTrait; use super::error::{CeobeOperationDesktopVersionError, DesktopRespResult}; use crate::router::CeobeOpVersion; @@ -16,18 +18,24 @@ type CreateDesktopVersionCheck = JsonCheckExtract< impl CeobeOpVersion { // 新增一个桌面端版本 - #[instrument(ret, skip(db))] + #[instrument(ret, skip(db, mongo))] pub async fn create_desktop_version( - db: SqlDatabaseOperate, + db: SqlDatabaseOperate, mongo: MongoDatabaseOperate, CheckExtract(version): CreateDesktopVersionCheck, ) -> DesktopRespResult<()> { resp_try(async { db.ceobe() .operation() .desktop_version() - .create_one(version) + .create_one(version.clone()) + .await?; + mongo + .ceobe() + .operation() + .release_version() + .create() + .one(version) .await?; - Ok(()) }) .await diff --git a/src/serves/backend/ceobe_operation/desktop_version/error.rs b/src/serves/backend/ceobe_operation/desktop_version/error.rs index 1a1c0f60..46479066 100644 --- a/src/serves/backend/ceobe_operation/desktop_version/error.rs +++ b/src/serves/backend/ceobe_operation/desktop_version/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::JsonRejection; -use persistence::ceobe_operate::desktop_version; -use resp_result::RespResult; +use persistence::ceobe_operate::{desktop_version, release_version}; +use axum_resp_result::RespResult; use crate::error_generate; @@ -10,6 +10,7 @@ error_generate! { Json = JsonRejection Check = desktop_version::CheckError DbOperate = desktop_version::OperateError + ReleaseDbOperate = release_version::Error } pub(super) type DesktopRespResult = diff --git a/src/serves/backend/ceobe_operation/plugin_version/controllers.rs b/src/serves/backend/ceobe_operation/plugin_version/controllers.rs index 0a99e9f4..270c94c2 100644 --- a/src/serves/backend/ceobe_operation/plugin_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/plugin_version/controllers.rs @@ -2,6 +2,7 @@ use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::{plugin_version::Checker, ToCeobe, ToCeobeOperation}, mongodb::MongoDatabaseOperate, + operate::operate_trait::OperateTrait, }; use axum_resp_result::resp_try; use tracing::instrument; @@ -22,7 +23,13 @@ impl CeobeOpVersion { db.ceobe() .operation() .plugin_version() - .update_new(version) + .update_new(version.clone()) + .await?; + db.ceobe() + .operation() + .release_version() + .create() + .one(version) .await?; Ok(()) diff --git a/src/serves/backend/ceobe_operation/plugin_version/error.rs b/src/serves/backend/ceobe_operation/plugin_version/error.rs index 2384d63c..f3e947ea 100644 --- a/src/serves/backend/ceobe_operation/plugin_version/error.rs +++ b/src/serves/backend/ceobe_operation/plugin_version/error.rs @@ -1,6 +1,7 @@ use axum::extract::rejection::JsonRejection; use persistence::ceobe_operate::plugin_version::{CheckError, OperateError}; -use resp_result::RespResult; +use axum_resp_result::RespResult; +use persistence::ceobe_operate::release_version; use crate::error_generate; @@ -10,6 +11,7 @@ error_generate! { Json = JsonRejection Check = CheckError DbOperate = OperateError + ReleaseDbOperate = release_version::Error } pub(super) type PluginRespResult = diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 5d83dfce..13df064f 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -6,12 +6,20 @@ use tracing::instrument; use checker::CheckExtract; use persistence::{ - ceobe_operate::{ToCeobe, ToCeobeOperation}, + ceobe_operate::{ + models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, + }, mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, + operate::operate_trait::OperateTrait, +}; + +use crate::{ + router::CeobeOperationVersionFrontend, + serves::frontend::ceobe::operation::version::{ + error::CeobeOperationVersionError, models::QueryReleaseVersion, + }, }; -use resp_result::{resp_try, FlagWrap}; -use tracing::instrument; use super::{ error::FlagVersionRespResult, @@ -22,7 +30,6 @@ use super::{ }, view::{AppVersionView, DesktopVersionView, PluginVersionView}, }; -use crate::router::CeobeOperationVersionFrontend; impl CeobeOperationVersionFrontend { // 获取app对应版本信息 @@ -130,4 +137,41 @@ impl CeobeOperationVersionFrontend { }) .await } + + #[resp_result] + // #[instrument(skip(db, modify))] + pub async fn release_version( + db: MongoDatabaseOperate, mut modify: modify_cache::CheckModify, + MapReject(QueryReleaseVersion { version, platform }): MapReject< + Query, + CeobeOperationVersionError, + >, + ) -> Result>, CeobeOperationVersionError> + { + modify + .cache_headers + .get_control() + .set_max_age(Duration::from_secs(60 * 60)); + let release_info = match version { + None => { + db.ceobe() + .operation() + .release_version() + .retrieve() + .latest_by_platform(platform) + .await? + } + Some(ver) => { + db.ceobe() + .operation() + .release_version() + .retrieve() + .by_version_platform(&ver, platform) + .await? + } + }; + + let (release_info, modify) = modify.check_modify(release_info)?; + Ok(FlagWrap::new(release_info, modify)) + } } diff --git a/src/serves/frontend/ceobe/operation/version/error.rs b/src/serves/frontend/ceobe/operation/version/error.rs index 493a3236..007c802f 100644 --- a/src/serves/frontend/ceobe/operation/version/error.rs +++ b/src/serves/frontend/ceobe/operation/version/error.rs @@ -4,6 +4,7 @@ use persistence::{ ceobe_operate::{ desktop_version, models::{app_version, plugin_version}, + release_version, }, }; use axum_resp_result::FlagRespResult; @@ -19,7 +20,8 @@ error_generate! { Query = QueryRejection AppOperate = ceobe_operate::app_version::OperateError DesktopOperate = ceobe_operate::desktop_version::OperateError - MongoDbError = ceobe_operate::plugin_version::OperateError + ReleaseDbOperate = release_version::Error + PluginDbError = ceobe_operate::plugin_version::OperateError ModifyVerify = modify_cache::Error } diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 8e545013..3fe4527b 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -12,6 +12,7 @@ use persistence::ceobe_operate::{ }; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; +use persistence::ceobe_operate::models::version::models::ReleasePlatform; use super::error::CeobeOperationVersionError; @@ -70,3 +71,9 @@ pub type OptionDesktopVersionCheckerPretreat = QueryCheckExtract< OptionDesktopVersionChecker, CeobeOperationVersionError, >; + +#[derive(Deserialize,Clone,Debug)] +pub struct QueryReleaseVersion{ + pub version:Option, + pub platform:ReleasePlatform +} \ No newline at end of file From 5612ae5818f19c49a02361d244348f7321c05fba Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 12:03:02 +0800 Subject: [PATCH 17/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operation/version/models/platform.rs | 18 +++++++++++++++++ .../ceobe/operation/version/controllers.rs | 20 +++++++++---------- .../ceobe/operation/version/models.rs | 13 ++++++------ 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index f0c44ed7..b90d7b67 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -1,3 +1,5 @@ +use std::fmt::{Display, Formatter}; + use serde::{Deserialize, Serialize}; /// 下载源对应的平台 @@ -12,6 +14,22 @@ pub enum ReleasePlatform { Pocket, } +impl Display for ReleasePlatform { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ReleasePlatform::Plugin => { + write!(f, "plugin") + } + ReleasePlatform::Desktop => { + write!(f, "desktop") + } + ReleasePlatform::Pocket => { + write!(f, "pocket") + } + } + } +} + /// 当前下载源支持的平台 #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] #[non_exhaustive] diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 13df064f..8a07c315 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -1,9 +1,7 @@ use std::time::Duration; use axum::extract::Query; -use axum_resp_result::{FlagWrap, MapReject, resp_result, resp_try}; -use tracing::instrument; - +use axum_resp_result::{resp_result, resp_try, FlagWrap, MapReject}; use checker::CheckExtract; use persistence::{ ceobe_operate::{ @@ -13,13 +11,7 @@ use persistence::{ mysql::SqlDatabaseOperate, operate::operate_trait::OperateTrait, }; - -use crate::{ - router::CeobeOperationVersionFrontend, - serves::frontend::ceobe::operation::version::{ - error::CeobeOperationVersionError, models::QueryReleaseVersion, - }, -}; +use tracing::instrument; use super::{ error::FlagVersionRespResult, @@ -30,6 +22,12 @@ use super::{ }, view::{AppVersionView, DesktopVersionView, PluginVersionView}, }; +use crate::{ + router::CeobeOperationVersionFrontend, + serves::frontend::ceobe::operation::version::{ + error::CeobeOperationVersionError, models::QueryReleaseVersion, + }, +}; impl CeobeOperationVersionFrontend { // 获取app对应版本信息 @@ -139,7 +137,7 @@ impl CeobeOperationVersionFrontend { } #[resp_result] - // #[instrument(skip(db, modify))] + #[instrument(skip_all,fields(platform = %arg_2.0.platform))] pub async fn release_version( db: MongoDatabaseOperate, mut modify: modify_cache::CheckModify, MapReject(QueryReleaseVersion { version, platform }): MapReject< diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 3fe4527b..4d22fc0b 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -7,12 +7,11 @@ use checker::{ }; use persistence::ceobe_operate::{ desktop_version, - models::app_version, + models::{app_version, version::models::ReleasePlatform}, plugin_version::{self, version}, }; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; -use persistence::ceobe_operate::models::version::models::ReleasePlatform; use super::error::CeobeOperationVersionError; @@ -72,8 +71,8 @@ pub type OptionDesktopVersionCheckerPretreat = QueryCheckExtract< CeobeOperationVersionError, >; -#[derive(Deserialize,Clone,Debug)] -pub struct QueryReleaseVersion{ - pub version:Option, - pub platform:ReleasePlatform -} \ No newline at end of file +#[derive(Deserialize, Clone, Debug)] +pub struct QueryReleaseVersion { + pub version: Option, + pub platform: ReleasePlatform, +} From a62184af520844fd6782357ee5e1990e7ae8a46a Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 12:03:57 +0800 Subject: [PATCH 18/68] :art: cargo fmt --- libs/checker/src/check_prehandle.rs | 4 +++- libs/modify-cache/src/cache_ctrl/control.rs | 2 +- libs/modify-cache/src/cache_ctrl/mod.rs | 2 +- libs/modify-cache/src/check_modify.rs | 2 +- .../src/ceobe/operation/plugin_version/models/mod.rs | 2 +- .../mongo-models/src/ceobe/operation/version/models/mod.rs | 4 ++-- .../src/ceobe/operation/version/models/modify_state.rs | 4 +++- .../app_version/checkers/app_version_data.rs | 2 +- .../desktop_version/checkers/desktop_version_data.rs | 2 +- src/bootstrap/init/component_init.rs | 2 +- src/bootstrap/middleware/panic_report.rs | 2 +- src/error/mod.rs | 2 +- src/middleware/authorize/mod.rs | 2 +- src/middleware/authorize/service.rs | 2 +- src/middleware/mob/mod.rs | 2 +- src/middleware/mob/service.rs | 2 +- src/serves/backend/bakery_mansion/controllers.rs | 2 +- src/serves/backend/ceobe_cookie/newest/controllers.rs | 2 +- src/serves/backend/ceobe_cookie/newest/error.rs | 2 +- .../backend/ceobe_operation/announcement/controllers.rs | 2 +- src/serves/backend/ceobe_operation/announcement/error.rs | 2 +- .../backend/ceobe_operation/app_version/controllers.rs | 2 +- src/serves/backend/ceobe_operation/app_version/error.rs | 2 +- .../backend/ceobe_operation/desktop_version/controllers.rs | 4 ++-- src/serves/backend/ceobe_operation/desktop_version/error.rs | 2 +- .../backend/ceobe_operation/plugin_version/controllers.rs | 2 +- src/serves/backend/ceobe_operation/plugin_version/error.rs | 6 ++++-- src/serves/backend/ceobe_operation/resource/controller.rs | 2 +- src/serves/backend/ceobe_operation/resource/error.rs | 2 +- src/serves/backend/ceobe_operation/tool_link/controllers.rs | 2 +- src/serves/backend/ceobe_operation/tool_link/error.rs | 2 +- src/serves/backend/ceobe_operation/video/controllers.rs | 2 +- src/serves/backend/ceobe_operation/video/error.rs | 2 +- .../backend/fetcher/datasource_configs/controllers.rs | 2 +- src/serves/backend/fetcher/datasource_configs/error.rs | 2 +- src/serves/backend/fetcher/fetcher_configs/controllers.rs | 2 +- src/serves/backend/fetcher/fetcher_configs/error.rs | 2 +- src/serves/backend/fetcher/global_configs/controllers.rs | 2 +- src/serves/backend/fetcher/global_configs/error.rs | 2 +- src/serves/backend/fetcher/platform_configs/controllers.rs | 2 +- src/serves/backend/fetcher/platform_configs/error.rs | 2 +- src/serves/backend/user_auth/controllers.rs | 2 +- src/serves/backend/user_auth/mod.rs | 2 +- src/serves/cdn/bakery_mansion/controllers.rs | 2 +- src/serves/cdn/bakery_mansion/error.rs | 2 +- src/serves/cdn/ceobe/cookie/main_list/controllers.rs | 2 +- src/serves/cdn/ceobe/cookie/main_list/error.rs | 2 +- src/serves/cdn/ceobe/cookie/temp_list/controllers.rs | 2 +- src/serves/cdn/ceobe/cookie/temp_list/error.rs | 2 +- src/serves/cdn/ceobe/operation/announcement/controllers.rs | 2 +- src/serves/cdn/ceobe/operation/announcement/error.rs | 2 +- src/serves/cdn/ceobe/operation/resource/controllers.rs | 2 +- src/serves/cdn/ceobe/operation/resource/error.rs | 2 +- src/serves/cdn/ceobe/operation/video/controllers.rs | 2 +- src/serves/cdn/ceobe/operation/video/error.rs | 2 +- src/serves/frontend/bakery_mansion/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/basic_info/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/basic_info/error.rs | 2 +- src/serves/frontend/ceobe/cookie/search/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/search/error.rs | 2 +- src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs | 2 +- src/serves/frontend/ceobe/cookie/terra_comic/error.rs | 2 +- .../frontend/ceobe/operation/announcement/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/announcement/error.rs | 2 +- src/serves/frontend/ceobe/operation/resource/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/resource/error.rs | 2 +- .../frontend/ceobe/operation/tool_link/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/tool_link/error.rs | 2 +- src/serves/frontend/ceobe/operation/version/error.rs | 2 +- src/serves/frontend/ceobe/operation/video/controllers.rs | 2 +- src/serves/frontend/ceobe/operation/video/error.rs | 2 +- src/serves/frontend/ceobe/user/controllers.rs | 2 +- src/serves/frontend/ceobe/user/error.rs | 2 +- src/serves/frontend/config/datasource/controllers.rs | 2 +- src/serves/frontend/config/datasource/error.rs | 2 +- src/serves/frontend/config/fetcher/controllers.rs | 2 +- src/serves/inside/analyze/cookie/controllers.rs | 2 +- src/serves/inside/analyze/cookie/error.rs | 2 +- 78 files changed, 87 insertions(+), 81 deletions(-) diff --git a/libs/checker/src/check_prehandle.rs b/libs/checker/src/check_prehandle.rs index 41ea342e..b62aeb35 100644 --- a/libs/checker/src/check_prehandle.rs +++ b/libs/checker/src/check_prehandle.rs @@ -6,7 +6,9 @@ use axum::{ http::request::Parts, Form, Json, }; -use axum_resp_result::{FromRequestFamily, Nil, RespError, RespResult, ToInner}; +use axum_resp_result::{ + FromRequestFamily, Nil, RespError, RespResult, ToInner, +}; use crate::{Checker as DataChecker, LiteArgs}; diff --git a/libs/modify-cache/src/cache_ctrl/control.rs b/libs/modify-cache/src/cache_ctrl/control.rs index 68d9019e..70b76e4e 100644 --- a/libs/modify-cache/src/cache_ctrl/control.rs +++ b/libs/modify-cache/src/cache_ctrl/control.rs @@ -1,7 +1,7 @@ use std::{ops::Add, time::Duration}; -use http::{header::CACHE_CONTROL, HeaderValue}; use axum_resp_result::{ExtraFlag, ExtraFlags}; +use http::{header::CACHE_CONTROL, HeaderValue}; #[derive(Debug, Default)] /// 可缓存性 diff --git a/libs/modify-cache/src/cache_ctrl/mod.rs b/libs/modify-cache/src/cache_ctrl/mod.rs index 4e704751..3787b897 100644 --- a/libs/modify-cache/src/cache_ctrl/mod.rs +++ b/libs/modify-cache/src/cache_ctrl/mod.rs @@ -1,10 +1,10 @@ use std::{borrow::Cow, ops::Add}; +use axum_resp_result::{ExtraFlag, ExtraFlags}; use http::{ header::{HeaderName, CONTENT_LOCATION, VARY}, Uri, }; -use axum_resp_result::{ExtraFlag, ExtraFlags}; use self::control::CacheControl; diff --git a/libs/modify-cache/src/check_modify.rs b/libs/modify-cache/src/check_modify.rs index de0c85ea..7ac06d87 100644 --- a/libs/modify-cache/src/check_modify.rs +++ b/libs/modify-cache/src/check_modify.rs @@ -2,13 +2,13 @@ use std::convert::Infallible; use async_trait::async_trait; use axum::extract::{FromRequestParts, OriginalUri}; +use axum_resp_result::{ExtraFlag, ExtraFlags}; use http::{ header::{CONTENT_TYPE, ETAG, LAST_MODIFIED}, method::Method, request::Parts, StatusCode, }; -use axum_resp_result::{ExtraFlag, ExtraFlags}; use tracing::warn; use crate::{ diff --git a/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs index 61b2de16..ab46a897 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/plugin_version/models/mod.rs @@ -29,7 +29,7 @@ pub struct DownloadResource { #[sub_model(all( vis = "pub", name = "PluginVersionChecked", - extra(derive(Debug, TypedBuilder,Clone)) + extra(derive(Debug, TypedBuilder, Clone)) ))] pub struct PluginVersion { pub version: Version, diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index a21ffe7a..281d0439 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -1,10 +1,10 @@ +mod conv; mod download_source; mod force; +mod modify_state; mod platform; mod primary; mod version; -mod conv; -mod modify_state; pub use download_source::{DownloadSourceItem, ResourceUrl}; pub use force::ForceCtrl; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs index dfcc8f57..dbbd8f06 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs @@ -3,7 +3,9 @@ use std::borrow::Cow; use modify_cache::ModifyState; use semver::Version; -use crate::ceobe::operation::version::models::{ReleasePlatform, ReleaseVersion}; +use crate::ceobe::operation::version::models::{ + ReleasePlatform, ReleaseVersion, +}; impl ModifyState for ReleaseVersion { type Identify = (Version, ReleasePlatform); diff --git a/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs b/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs index 4fc6d9cf..340c942b 100644 --- a/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs +++ b/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs @@ -12,7 +12,7 @@ use crate::{ get_now_naive_date_time, }; -#[derive(Debug, TypedBuilder,Clone)] +#[derive(Debug, TypedBuilder, Clone)] pub struct CeobeOperationAppVersion { pub version: String, pub force: bool, diff --git a/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs b/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs index 85be2bde..c4299bd4 100644 --- a/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs +++ b/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs @@ -12,7 +12,7 @@ use crate::{ get_now_naive_date_time, }; -#[derive(Debug, TypedBuilder,Clone)] +#[derive(Debug, TypedBuilder, Clone)] pub struct CeobeOperationDesktopVersion { pub version: String, pub force: bool, diff --git a/src/bootstrap/init/component_init.rs b/src/bootstrap/init/component_init.rs index b4cfeddb..19325acf 100644 --- a/src/bootstrap/init/component_init.rs +++ b/src/bootstrap/init/component_init.rs @@ -1,5 +1,5 @@ -use axum_starter::prepare; use axum_resp_result::ConfigTrait; +use axum_starter::prepare; use crate::utils::{ mob_verify, diff --git a/src/bootstrap/middleware/panic_report.rs b/src/bootstrap/middleware/panic_report.rs index a00650a5..53551b95 100644 --- a/src/bootstrap/middleware/panic_report.rs +++ b/src/bootstrap/middleware/panic_report.rs @@ -1,11 +1,11 @@ use axum::response::IntoResponse; +use axum_resp_result::RespResult; use axum_starter::{prepare, PrepareMiddlewareEffect}; use persistence::operate::FromRequestParts; use qq_channel_warning::{ qq_channel_logger, GrpcConfigTrait, LogRequest, LogType, QqChannelGrpcService, }; -use axum_resp_result::RespResult; use tower_http::catch_panic::{CatchPanicLayer, ResponseForPanic}; use tracing::{error, instrument}; diff --git a/src/error/mod.rs b/src/error/mod.rs index 81bac1ad..afcd8e5a 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -3,8 +3,8 @@ use std::any::Any; use axum::{ body::Body as BoxBody, extract::OriginalUri, response::IntoResponse, }; -use http::Method; use axum_resp_result::RespResult; +use http::Method; use status_err::ErrPrefix; use tracing::{error, instrument, warn}; diff --git a/src/middleware/authorize/mod.rs b/src/middleware/authorize/mod.rs index 12c44ff2..f416c47c 100644 --- a/src/middleware/authorize/mod.rs +++ b/src/middleware/authorize/mod.rs @@ -1,9 +1,9 @@ use async_trait::async_trait; use axum::extract::FromRequestParts; +use axum_resp_result::{Nil, RespResult}; use http::request::Parts; pub use layer::AuthorizeLayer; use persistence::admin; -use axum_resp_result::{Nil, RespResult}; pub use self::error::AuthorizeError; diff --git a/src/middleware/authorize/service.rs b/src/middleware/authorize/service.rs index 3576cb05..51e7b6a2 100644 --- a/src/middleware/authorize/service.rs +++ b/src/middleware/authorize/service.rs @@ -5,6 +5,7 @@ use axum::{ extract::FromRequestParts, response::{IntoResponse, Response}, }; +use axum_resp_result::RespResult; use futures::future::BoxFuture; use http::Request; use persistence::{ @@ -14,7 +15,6 @@ use persistence::{ }, mysql::SqlDatabaseOperate, }; -use axum_resp_result::RespResult; use tap::Tap; use tower_http::auth::AsyncAuthorizeRequest; use tracing::{info, warn, Instrument}; diff --git a/src/middleware/mob/mod.rs b/src/middleware/mob/mod.rs index 5519767a..2645e2a8 100644 --- a/src/middleware/mob/mod.rs +++ b/src/middleware/mob/mod.rs @@ -1,9 +1,9 @@ use async_trait::async_trait; use axum::extract::FromRequestParts; +use axum_resp_result::{Nil, RespResult}; use http::request::Parts; pub use layer::MobVerifyLayer; use persistence::ceobe_user::models::models::UserMobId; -use axum_resp_result::{Nil, RespResult}; use self::error::MobVerifyError; diff --git a/src/middleware/mob/service.rs b/src/middleware/mob/service.rs index 25997f4b..ace571c2 100644 --- a/src/middleware/mob/service.rs +++ b/src/middleware/mob/service.rs @@ -3,6 +3,7 @@ use axum::{ extract::FromRequestParts, response::{IntoResponse, Response}, }; +use axum_resp_result::RespResult; use bool_or::TrueOrError; use futures::future::BoxFuture; use http::Request; @@ -11,7 +12,6 @@ use persistence::{ ceobe_user::{models::models::UserMobId, ToCeobeUser}, mongodb::MongoDatabaseOperate, }; -use axum_resp_result::RespResult; use tap::Tap; use tower_http::auth::AsyncAuthorizeRequest; use tracing::{info, Instrument}; diff --git a/src/serves/backend/bakery_mansion/controllers.rs b/src/serves/backend/bakery_mansion/controllers.rs index ee7c2569..9b380a60 100644 --- a/src/serves/backend/bakery_mansion/controllers.rs +++ b/src/serves/backend/bakery_mansion/controllers.rs @@ -1,7 +1,7 @@ +use axum_resp_result::resp_try; use bakery_logic::{impletements::BakeryLogic, view::MansionResp}; use checker::CheckExtract; use persistence::mongodb::MongoDatabaseOperate; -use axum_resp_result::resp_try; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_cookie/newest/controllers.rs b/src/serves/backend/ceobe_cookie/newest/controllers.rs index bd45b3c8..e483c260 100644 --- a/src/serves/backend/ceobe_cookie/newest/controllers.rs +++ b/src/serves/backend/ceobe_cookie/newest/controllers.rs @@ -1,8 +1,8 @@ +use axum_resp_result::resp_try; use ceobe_cookie_logic::impletements::CeobeCookieLogic; use ceobe_qiniu_upload::QiniuManager; use persistence::redis::RedisConnect; use qq_channel_warning::QqChannelGrpcService; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::CookieNewestRResult; diff --git a/src/serves/backend/ceobe_cookie/newest/error.rs b/src/serves/backend/ceobe_cookie/newest/error.rs index 1c0d90e0..638c0c57 100644 --- a/src/serves/backend/ceobe_cookie/newest/error.rs +++ b/src/serves/backend/ceobe_cookie/newest/error.rs @@ -1,5 +1,5 @@ -use ceobe_cookie_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_cookie_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/announcement/controllers.rs b/src/serves/backend/ceobe_operation/announcement/controllers.rs index 7b158865..2a7ebe22 100644 --- a/src/serves/backend/ceobe_operation/announcement/controllers.rs +++ b/src/serves/backend/ceobe_operation/announcement/controllers.rs @@ -1,3 +1,4 @@ +use axum_resp_result::resp_try; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::AnnouncementResp, }; @@ -8,7 +9,6 @@ use checker::{ use persistence::{ ceobe_operate::models::announcement, mysql::SqlDatabaseOperate, }; -use axum_resp_result::resp_try; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_operation/announcement/error.rs b/src/serves/backend/ceobe_operation/announcement/error.rs index 3e643f82..af004ccc 100644 --- a/src/serves/backend/ceobe_operation/announcement/error.rs +++ b/src/serves/backend/ceobe_operation/announcement/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; +use axum_resp_result::RespResult; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::announcement; -use axum_resp_result::RespResult; use crate::{error_generate, utils::user_authorize::error::AuthError}; diff --git a/src/serves/backend/ceobe_operation/app_version/controllers.rs b/src/serves/backend/ceobe_operation/app_version/controllers.rs index 328cc75e..3cd9aedc 100644 --- a/src/serves/backend/ceobe_operation/app_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/app_version/controllers.rs @@ -1,3 +1,4 @@ +use axum_resp_result::resp_try; use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::{models::app_version, ToCeobe, ToCeobeOperation}, @@ -5,7 +6,6 @@ use persistence::{ mysql::SqlDatabaseOperate, operate::operate_trait::OperateTrait, }; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::{AppRespResult, CeobeOperationAppVersionError}; diff --git a/src/serves/backend/ceobe_operation/app_version/error.rs b/src/serves/backend/ceobe_operation/app_version/error.rs index 9111907d..31a47f40 100644 --- a/src/serves/backend/ceobe_operation/app_version/error.rs +++ b/src/serves/backend/ceobe_operation/app_version/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::JsonRejection; -use persistence::ceobe_operate::{app_version, release_version}; use axum_resp_result::RespResult; +use persistence::ceobe_operate::{app_version, release_version}; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/desktop_version/controllers.rs b/src/serves/backend/ceobe_operation/desktop_version/controllers.rs index dbc2e35f..cddabc57 100644 --- a/src/serves/backend/ceobe_operation/desktop_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/desktop_version/controllers.rs @@ -1,12 +1,12 @@ +use axum_resp_result::resp_try; use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::{models::desktop_version, ToCeobe, ToCeobeOperation}, mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, + operate::operate_trait::OperateTrait, }; -use axum_resp_result::resp_try; use tracing::instrument; -use persistence::operate::operate_trait::OperateTrait; use super::error::{CeobeOperationDesktopVersionError, DesktopRespResult}; use crate::router::CeobeOpVersion; diff --git a/src/serves/backend/ceobe_operation/desktop_version/error.rs b/src/serves/backend/ceobe_operation/desktop_version/error.rs index 46479066..29b6f56c 100644 --- a/src/serves/backend/ceobe_operation/desktop_version/error.rs +++ b/src/serves/backend/ceobe_operation/desktop_version/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::JsonRejection; -use persistence::ceobe_operate::{desktop_version, release_version}; use axum_resp_result::RespResult; +use persistence::ceobe_operate::{desktop_version, release_version}; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/plugin_version/controllers.rs b/src/serves/backend/ceobe_operation/plugin_version/controllers.rs index 270c94c2..e151ffc5 100644 --- a/src/serves/backend/ceobe_operation/plugin_version/controllers.rs +++ b/src/serves/backend/ceobe_operation/plugin_version/controllers.rs @@ -1,10 +1,10 @@ +use axum_resp_result::resp_try; use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::{plugin_version::Checker, ToCeobe, ToCeobeOperation}, mongodb::MongoDatabaseOperate, operate::operate_trait::OperateTrait, }; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::{CeobeOperationPluginVersionError, PluginRespResult}; diff --git a/src/serves/backend/ceobe_operation/plugin_version/error.rs b/src/serves/backend/ceobe_operation/plugin_version/error.rs index f3e947ea..9f786b8e 100644 --- a/src/serves/backend/ceobe_operation/plugin_version/error.rs +++ b/src/serves/backend/ceobe_operation/plugin_version/error.rs @@ -1,7 +1,9 @@ use axum::extract::rejection::JsonRejection; -use persistence::ceobe_operate::plugin_version::{CheckError, OperateError}; use axum_resp_result::RespResult; -use persistence::ceobe_operate::release_version; +use persistence::ceobe_operate::{ + plugin_version::{CheckError, OperateError}, + release_version, +}; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/resource/controller.rs b/src/serves/backend/ceobe_operation/resource/controller.rs index 2c56e68b..eac73977 100644 --- a/src/serves/backend/ceobe_operation/resource/controller.rs +++ b/src/serves/backend/ceobe_operation/resource/controller.rs @@ -1,3 +1,4 @@ +use axum_resp_result::{resp_try, rtry, RespResult}; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::Resource, }; @@ -5,7 +6,6 @@ use checker::{CheckExtract, JsonCheckExtract}; use persistence::{ ceobe_operate::models::resource, mysql::SqlDatabaseOperate, }; -use axum_resp_result::{resp_try, rtry, RespResult}; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_operation/resource/error.rs b/src/serves/backend/ceobe_operation/resource/error.rs index 1fd9a8dd..e3fd5e15 100644 --- a/src/serves/backend/ceobe_operation/resource/error.rs +++ b/src/serves/backend/ceobe_operation/resource/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::JsonRejection; +use axum_resp_result::RespResult; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::resource::CheckError; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/tool_link/controllers.rs b/src/serves/backend/ceobe_operation/tool_link/controllers.rs index 175381df..36cdd779 100644 --- a/src/serves/backend/ceobe_operation/tool_link/controllers.rs +++ b/src/serves/backend/ceobe_operation/tool_link/controllers.rs @@ -2,6 +2,7 @@ use axum::{ extract::{multipart::MultipartRejection, Multipart}, Json, }; +use axum_resp_result::{resp_try, MapReject}; use ceobe_cookie_logic::view::AvatarId; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, @@ -12,7 +13,6 @@ use checker::CheckExtract; use page_size::response::ListWithPageInfo; use persistence::mysql::SqlDatabaseOperate; use qiniu_cdn_upload::UploadWrap; -use axum_resp_result::{resp_try, MapReject}; use tracing::instrument; use super::error::{ diff --git a/src/serves/backend/ceobe_operation/tool_link/error.rs b/src/serves/backend/ceobe_operation/tool_link/error.rs index 06fa27e6..08581d6e 100644 --- a/src/serves/backend/ceobe_operation/tool_link/error.rs +++ b/src/serves/backend/ceobe_operation/tool_link/error.rs @@ -2,6 +2,7 @@ use axum::extract::{ multipart::{MultipartError, MultipartRejection}, rejection::{JsonRejection, QueryRejection}, }; +use axum_resp_result::RespResult; use ceobe_operation_logic::error::LogicError; use ceobe_qiniu_upload::Error as QiniuError; use checker::{ @@ -12,7 +13,6 @@ use page_size::request::PageSizeChecker; use persistence::ceobe_operate::models::tool_link::{ self, checkers::tool_link_data::PreCheckCeobeOperationToolLinkChecker, }; -use axum_resp_result::RespResult; use status_err::{ErrPrefix, StatusErr}; use crate::error_generate; diff --git a/src/serves/backend/ceobe_operation/video/controllers.rs b/src/serves/backend/ceobe_operation/video/controllers.rs index e8c9a39a..13f588ec 100644 --- a/src/serves/backend/ceobe_operation/video/controllers.rs +++ b/src/serves/backend/ceobe_operation/video/controllers.rs @@ -1,3 +1,4 @@ +use axum_resp_result::{resp_try, rtry, RespResult}; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::VideoItem, }; @@ -10,7 +11,6 @@ use persistence::{ mysql::SqlDatabaseOperate, }; use request_clients::bili_client::QueryBiliVideo; -use axum_resp_result::{resp_try, rtry, RespResult}; use tencent_cloud_server::cloud_manager::TencentCloudManager; use tracing::instrument; diff --git a/src/serves/backend/ceobe_operation/video/error.rs b/src/serves/backend/ceobe_operation/video/error.rs index d175048b..1260c013 100644 --- a/src/serves/backend/ceobe_operation/video/error.rs +++ b/src/serves/backend/ceobe_operation/video/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; +use axum_resp_result::RespResult; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::video; -use axum_resp_result::RespResult; use crate::{error_generate, utils::user_authorize::error::AuthError}; diff --git a/src/serves/backend/fetcher/datasource_configs/controllers.rs b/src/serves/backend/fetcher/datasource_configs/controllers.rs index 215f8517..d2afe78c 100644 --- a/src/serves/backend/fetcher/datasource_configs/controllers.rs +++ b/src/serves/backend/fetcher/datasource_configs/controllers.rs @@ -2,6 +2,7 @@ use axum::{ extract::{multipart::MultipartRejection, Multipart, Query}, Json, }; +use axum_resp_result::{resp_try, rtry, MapReject}; use ceobe_qiniu_upload::QiniuManager; use checker::CheckExtract; use fetcher_logic::{ @@ -23,7 +24,6 @@ use persistence::{ }; use qiniu_cdn_upload::UploadWrap; use qq_channel_warning::QqChannelGrpcService; -use axum_resp_result::{resp_try, rtry, MapReject}; use scheduler_notifier::SchedulerNotifier; use tracing::instrument; diff --git a/src/serves/backend/fetcher/datasource_configs/error.rs b/src/serves/backend/fetcher/datasource_configs/error.rs index d41435e6..96064a09 100644 --- a/src/serves/backend/fetcher/datasource_configs/error.rs +++ b/src/serves/backend/fetcher/datasource_configs/error.rs @@ -2,6 +2,7 @@ use axum::extract::{ multipart::{MultipartError, MultipartRejection}, rejection::{JsonRejection, QueryRejection}, }; +use axum_resp_result::RespResult; use ceobe_qiniu_upload::Error as QiniuError; use checker::prefabs::num_check::NonZeroUnsignedError; use fetcher_logic::error::LogicError; @@ -10,7 +11,6 @@ use persistence::fetcher::{ models::datasource_config::checkers::CheckError, platform_config::OperateError as PlatformOperateError, }; -use axum_resp_result::RespResult; use status_err::{ErrPrefix, StatusErr}; use crate::error_generate; diff --git a/src/serves/backend/fetcher/fetcher_configs/controllers.rs b/src/serves/backend/fetcher/fetcher_configs/controllers.rs index e9f20cd1..a4d3a673 100644 --- a/src/serves/backend/fetcher/fetcher_configs/controllers.rs +++ b/src/serves/backend/fetcher/fetcher_configs/controllers.rs @@ -1,10 +1,10 @@ use axum::{extract::Query, Json}; +use axum_resp_result::{resp_try, rtry, MapReject}; use fetcher_logic::{ implements::FetcherConfigLogic, view::{BackEndFetcherConfig, MaxLiveNumberResp, PlatformFilterReq}, }; use persistence::{mysql::SqlDatabaseOperate, redis::RedisConnect}; -use axum_resp_result::{resp_try, rtry, MapReject}; use scheduler_notifier::SchedulerNotifier; use tracing::instrument; diff --git a/src/serves/backend/fetcher/fetcher_configs/error.rs b/src/serves/backend/fetcher/fetcher_configs/error.rs index a0b6b0ab..cf32710d 100644 --- a/src/serves/backend/fetcher/fetcher_configs/error.rs +++ b/src/serves/backend/fetcher/fetcher_configs/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; +use axum_resp_result::RespResult; use fetcher_logic::error::LogicError; use persistence::fetcher::config::OperateError; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/fetcher/global_configs/controllers.rs b/src/serves/backend/fetcher/global_configs/controllers.rs index c8f17cab..8d71aac0 100644 --- a/src/serves/backend/fetcher/global_configs/controllers.rs +++ b/src/serves/backend/fetcher/global_configs/controllers.rs @@ -1,7 +1,7 @@ use axum::Json; +use axum_resp_result::{rtry, MapReject, RespResult}; use fetcher_logic::implements::FetcherConfigLogic; use persistence::mysql::SqlDatabaseOperate; -use axum_resp_result::{rtry, MapReject, RespResult}; use serde_json::{Map, Value}; use tracing::instrument; diff --git a/src/serves/backend/fetcher/global_configs/error.rs b/src/serves/backend/fetcher/global_configs/error.rs index bc885299..f50c51b6 100644 --- a/src/serves/backend/fetcher/global_configs/error.rs +++ b/src/serves/backend/fetcher/global_configs/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::JsonRejection; +use axum_resp_result::RespResult; use fetcher_logic::error::LogicError; use persistence::fetcher::models::global_config::checkers::CheckError; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/fetcher/platform_configs/controllers.rs b/src/serves/backend/fetcher/platform_configs/controllers.rs index 5c9597d9..27bec3f1 100644 --- a/src/serves/backend/fetcher/platform_configs/controllers.rs +++ b/src/serves/backend/fetcher/platform_configs/controllers.rs @@ -1,4 +1,5 @@ use axum::Json; +use axum_resp_result::{resp_try, rtry, MapReject}; use checker::CheckExtract; use fetcher_logic::{implements::FetcherConfigLogic, view::OneIdReq}; use futures::future; @@ -13,7 +14,6 @@ use persistence::{ }, mysql::SqlDatabaseOperate, }; -use axum_resp_result::{resp_try, rtry, MapReject}; use tracing::instrument; use super::{ diff --git a/src/serves/backend/fetcher/platform_configs/error.rs b/src/serves/backend/fetcher/platform_configs/error.rs index 214a7d7d..a9c1244b 100644 --- a/src/serves/backend/fetcher/platform_configs/error.rs +++ b/src/serves/backend/fetcher/platform_configs/error.rs @@ -1,10 +1,10 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; +use axum_resp_result::RespResult; use checker::prefabs::num_check::NonZeroUnsignedError; use fetcher_logic::error::LogicError; use persistence::fetcher::{ models::platform_config, platform_config::OperateError, }; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/backend/user_auth/controllers.rs b/src/serves/backend/user_auth/controllers.rs index 1f366b49..9f8c069f 100644 --- a/src/serves/backend/user_auth/controllers.rs +++ b/src/serves/backend/user_auth/controllers.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; use axum::{extract::Query, Json}; +use axum_resp_result::{resp_try, rtry, MapReject}; use checker::CheckExtract; use crypto_str::Encoder; use futures::{future, TryFutureExt}; @@ -11,7 +12,6 @@ use persistence::{ mysql::SqlDatabaseOperate, }; use rand::{distributions::Alphanumeric, thread_rng, Rng}; -use axum_resp_result::{resp_try, rtry, MapReject}; use tracing::{debug, instrument}; use super::{ diff --git a/src/serves/backend/user_auth/mod.rs b/src/serves/backend/user_auth/mod.rs index aa07873c..83dbd999 100644 --- a/src/serves/backend/user_auth/mod.rs +++ b/src/serves/backend/user_auth/mod.rs @@ -1,7 +1,7 @@ +use axum_resp_result::RespResult; use checker::{JsonCheckExtract, QueryCheckExtract}; use page_size::request::PageSizeChecker; use persistence::admin::models::username::Checker; -use axum_resp_result::RespResult; use self::error::AdminUserError; diff --git a/src/serves/cdn/bakery_mansion/controllers.rs b/src/serves/cdn/bakery_mansion/controllers.rs index 3effe7a3..2b6b827b 100644 --- a/src/serves/cdn/bakery_mansion/controllers.rs +++ b/src/serves/cdn/bakery_mansion/controllers.rs @@ -1,10 +1,10 @@ +use axum_resp_result::resp_try; use bakery_logic::{ impletements::BakeryLogic, view::{MansionRecentPredictResp, MansionWithTimeResp}, }; use checker::CheckExtract; use persistence::mongodb::MongoDatabaseOperate; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::{MansionRResult, MidCheckerPretreatment}; diff --git a/src/serves/cdn/bakery_mansion/error.rs b/src/serves/cdn/bakery_mansion/error.rs index b0e7a712..ba96258f 100644 --- a/src/serves/cdn/bakery_mansion/error.rs +++ b/src/serves/cdn/bakery_mansion/error.rs @@ -1,4 +1,5 @@ use axum::extract::rejection::QueryRejection; +use axum_resp_result::RespResult; use bakery_logic::error::LogicError; use checker::QueryCheckExtract; use persistence::bakery::{ @@ -7,7 +8,6 @@ use persistence::bakery::{ checkers::CheckError, preludes::id_checker::MidChecker, }, }; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/cookie/main_list/controllers.rs b/src/serves/cdn/ceobe/cookie/main_list/controllers.rs index aa42b873..aceb9989 100644 --- a/src/serves/cdn/ceobe/cookie/main_list/controllers.rs +++ b/src/serves/cdn/ceobe/cookie/main_list/controllers.rs @@ -1,4 +1,5 @@ use axum::extract::Query; +use axum_resp_result::{rtry, MapReject}; use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::{CookieListReq, CookieListResp}, @@ -7,7 +8,6 @@ use persistence::{ mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, redis::RedisConnect, }; -use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieMainListError, CeobeCookieRResult}; diff --git a/src/serves/cdn/ceobe/cookie/main_list/error.rs b/src/serves/cdn/ceobe/cookie/main_list/error.rs index 582e41a2..f1c5dffb 100644 --- a/src/serves/cdn/ceobe/cookie/main_list/error.rs +++ b/src/serves/cdn/ceobe/cookie/main_list/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::QueryRejection; -use ceobe_cookie_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_cookie_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs b/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs index e828a7ae..1a497278 100644 --- a/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs +++ b/src/serves/cdn/ceobe/cookie/temp_list/controllers.rs @@ -1,10 +1,10 @@ use axum::extract::Query; +use axum_resp_result::{rtry, MapReject}; use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::{CookieListReq, CookieTempListResp}, }; use persistence::{mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate}; -use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieRResult, CeobeCookieTempListError}; diff --git a/src/serves/cdn/ceobe/cookie/temp_list/error.rs b/src/serves/cdn/ceobe/cookie/temp_list/error.rs index d07ff740..fb1a767f 100644 --- a/src/serves/cdn/ceobe/cookie/temp_list/error.rs +++ b/src/serves/cdn/ceobe/cookie/temp_list/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::QueryRejection; +use axum_resp_result::RespResult; use ceobe_cookie_logic::error::LogicError; use persistence::ceobe_cookie::temp_list::OperateError as TempListOperateError; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/operation/announcement/controllers.rs b/src/serves/cdn/ceobe/operation/announcement/controllers.rs index 6a7927db..44d805d8 100644 --- a/src/serves/cdn/ceobe/operation/announcement/controllers.rs +++ b/src/serves/cdn/ceobe/operation/announcement/controllers.rs @@ -1,8 +1,8 @@ +use axum_resp_result::resp_try; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::AnnouncementResp, }; use persistence::mysql::SqlDatabaseOperate; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::AnnouncementRespResult; diff --git a/src/serves/cdn/ceobe/operation/announcement/error.rs b/src/serves/cdn/ceobe/operation/announcement/error.rs index afaaf8a4..8a3a09da 100644 --- a/src/serves/cdn/ceobe/operation/announcement/error.rs +++ b/src/serves/cdn/ceobe/operation/announcement/error.rs @@ -1,5 +1,5 @@ -use ceobe_operation_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_operation_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/operation/resource/controllers.rs b/src/serves/cdn/ceobe/operation/resource/controllers.rs index 6a9ae88c..9f7d6bf5 100644 --- a/src/serves/cdn/ceobe/operation/resource/controllers.rs +++ b/src/serves/cdn/ceobe/operation/resource/controllers.rs @@ -1,8 +1,8 @@ +use axum_resp_result::{rtry, RespResult}; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::Resource, }; use persistence::mysql::SqlDatabaseOperate; -use axum_resp_result::{rtry, RespResult}; use tracing::instrument; use super::error::ResourceRespResult; diff --git a/src/serves/cdn/ceobe/operation/resource/error.rs b/src/serves/cdn/ceobe/operation/resource/error.rs index 1f855ccb..858b875b 100644 --- a/src/serves/cdn/ceobe/operation/resource/error.rs +++ b/src/serves/cdn/ceobe/operation/resource/error.rs @@ -1,6 +1,6 @@ +use axum_resp_result::RespResult; use ceobe_operation_logic::error::LogicError; use persistence::ceobe_operate::resource; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/cdn/ceobe/operation/video/controllers.rs b/src/serves/cdn/ceobe/operation/video/controllers.rs index 3b3672e3..07f99433 100644 --- a/src/serves/cdn/ceobe/operation/video/controllers.rs +++ b/src/serves/cdn/ceobe/operation/video/controllers.rs @@ -1,8 +1,8 @@ +use axum_resp_result::resp_try; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::VideoItem, }; use persistence::mysql::SqlDatabaseOperate; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::VideoRespResult; diff --git a/src/serves/cdn/ceobe/operation/video/error.rs b/src/serves/cdn/ceobe/operation/video/error.rs index a4d4b5c9..9a4815e8 100644 --- a/src/serves/cdn/ceobe/operation/video/error.rs +++ b/src/serves/cdn/ceobe/operation/video/error.rs @@ -1,5 +1,5 @@ -use ceobe_operation_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_operation_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/frontend/bakery_mansion/controllers.rs b/src/serves/frontend/bakery_mansion/controllers.rs index 83e6ff20..4daa58f5 100644 --- a/src/serves/frontend/bakery_mansion/controllers.rs +++ b/src/serves/frontend/bakery_mansion/controllers.rs @@ -1,3 +1,4 @@ +use axum_resp_result::{resp_try, FlagWrap}; use bakery_logic::{ impletements::BakeryLogic, view::MansionRecentPredictResp, }; @@ -7,7 +8,6 @@ use persistence::{ bakery::{mansion::ToMansion, ToBakery}, mongodb::MongoDatabaseOperate, }; -use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{ diff --git a/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs b/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs index 5fc7565a..23a599d2 100644 --- a/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs +++ b/src/serves/frontend/ceobe/cookie/basic_info/controllers.rs @@ -1,8 +1,8 @@ +use axum_resp_result::rtry; use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::CookieNumberResp, }; use persistence::mongodb::MongoDatabaseOperate; -use axum_resp_result::rtry; use tracing::instrument; use super::error::CeobeCookieRResult; diff --git a/src/serves/frontend/ceobe/cookie/basic_info/error.rs b/src/serves/frontend/ceobe/cookie/basic_info/error.rs index 0b7ec7e3..7f15c605 100644 --- a/src/serves/frontend/ceobe/cookie/basic_info/error.rs +++ b/src/serves/frontend/ceobe/cookie/basic_info/error.rs @@ -1,5 +1,5 @@ -use ceobe_cookie_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_cookie_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/cookie/search/controllers.rs b/src/serves/frontend/ceobe/cookie/search/controllers.rs index d6530cef..dd844b9a 100644 --- a/src/serves/frontend/ceobe/cookie/search/controllers.rs +++ b/src/serves/frontend/ceobe/cookie/search/controllers.rs @@ -1,10 +1,10 @@ use axum::extract::Query; +use axum_resp_result::{rtry, MapReject}; use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::{CookieListResp, SearchListReq}, }; use persistence::{mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate}; -use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieRResult, CeobeCookieSearchError}; diff --git a/src/serves/frontend/ceobe/cookie/search/error.rs b/src/serves/frontend/ceobe/cookie/search/error.rs index fe1012e3..7ec41425 100644 --- a/src/serves/frontend/ceobe/cookie/search/error.rs +++ b/src/serves/frontend/ceobe/cookie/search/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::QueryRejection; -use ceobe_cookie_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_cookie_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs b/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs index aba72f4b..fe9517eb 100644 --- a/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs +++ b/src/serves/frontend/ceobe/cookie/terra_comic/controllers.rs @@ -1,4 +1,5 @@ use axum::extract::Query; +use axum_resp_result::{rtry, MapReject}; use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::{TerraCidReq, TerraComicListResp, TerraEntryResp}, @@ -7,7 +8,6 @@ use persistence::{ ceobe_cookie::models::analyze::models::TerraComicEpisodeInfo, mongodb::MongoDatabaseOperate, }; -use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeCookieRResult, CeobeCookieTerraComicError}; diff --git a/src/serves/frontend/ceobe/cookie/terra_comic/error.rs b/src/serves/frontend/ceobe/cookie/terra_comic/error.rs index 73f6a7e0..9aa2057f 100644 --- a/src/serves/frontend/ceobe/cookie/terra_comic/error.rs +++ b/src/serves/frontend/ceobe/cookie/terra_comic/error.rs @@ -1,7 +1,7 @@ use axum::extract::rejection::QueryRejection; +use axum_resp_result::RespResult; use ceobe_cookie_logic::error::LogicError; use persistence::ceobe_cookie::terra_comic::OperateError as TerraComicOperateError; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/announcement/controllers.rs b/src/serves/frontend/ceobe/operation/announcement/controllers.rs index 0b174e75..4ab051ee 100644 --- a/src/serves/frontend/ceobe/operation/announcement/controllers.rs +++ b/src/serves/frontend/ceobe/operation/announcement/controllers.rs @@ -1,9 +1,9 @@ +use axum_resp_result::{resp_try, FlagWrap}; use modify_cache::CacheMode; use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{ diff --git a/src/serves/frontend/ceobe/operation/announcement/error.rs b/src/serves/frontend/ceobe/operation/announcement/error.rs index 06821ba1..89e84aaf 100644 --- a/src/serves/frontend/ceobe/operation/announcement/error.rs +++ b/src/serves/frontend/ceobe/operation/announcement/error.rs @@ -1,5 +1,5 @@ -use persistence::ceobe_operate::announcement; use axum_resp_result::FlagRespResult; +use persistence::ceobe_operate::announcement; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/resource/controllers.rs b/src/serves/frontend/ceobe/operation/resource/controllers.rs index c81a7e5a..4ea3c544 100644 --- a/src/serves/frontend/ceobe/operation/resource/controllers.rs +++ b/src/serves/frontend/ceobe/operation/resource/controllers.rs @@ -1,10 +1,10 @@ use std::time::Duration; +use axum_resp_result::{resp_try, FlagWrap}; use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{error::FlagResourceRespResult, view::Resource}; diff --git a/src/serves/frontend/ceobe/operation/resource/error.rs b/src/serves/frontend/ceobe/operation/resource/error.rs index 7ffd2803..c214c409 100644 --- a/src/serves/frontend/ceobe/operation/resource/error.rs +++ b/src/serves/frontend/ceobe/operation/resource/error.rs @@ -1,5 +1,5 @@ -use persistence::ceobe_operate::resource; use axum_resp_result::FlagRespResult; +use persistence::ceobe_operate::resource; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/tool_link/controllers.rs b/src/serves/frontend/ceobe/operation/tool_link/controllers.rs index 517126c0..9be6a77c 100644 --- a/src/serves/frontend/ceobe/operation/tool_link/controllers.rs +++ b/src/serves/frontend/ceobe/operation/tool_link/controllers.rs @@ -1,8 +1,8 @@ +use axum_resp_result::resp_try; use ceobe_operation_logic::{ impletements::CeobeOperateLogic, view::ToolLinkResp, }; use persistence::mysql::SqlDatabaseOperate; -use axum_resp_result::resp_try; use tracing::instrument; use super::error::OperateToolLinkRResult; diff --git a/src/serves/frontend/ceobe/operation/tool_link/error.rs b/src/serves/frontend/ceobe/operation/tool_link/error.rs index 0654dd28..84ade77d 100644 --- a/src/serves/frontend/ceobe/operation/tool_link/error.rs +++ b/src/serves/frontend/ceobe/operation/tool_link/error.rs @@ -1,5 +1,5 @@ -use ceobe_operation_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_operation_logic::error::LogicError; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/version/error.rs b/src/serves/frontend/ceobe/operation/version/error.rs index 007c802f..83904d17 100644 --- a/src/serves/frontend/ceobe/operation/version/error.rs +++ b/src/serves/frontend/ceobe/operation/version/error.rs @@ -1,4 +1,5 @@ use axum::extract::rejection::QueryRejection; +use axum_resp_result::FlagRespResult; use persistence::{ ceobe_operate, ceobe_operate::{ @@ -7,7 +8,6 @@ use persistence::{ release_version, }, }; -use axum_resp_result::FlagRespResult; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/operation/video/controllers.rs b/src/serves/frontend/ceobe/operation/video/controllers.rs index ba39110d..f518f879 100644 --- a/src/serves/frontend/ceobe/operation/video/controllers.rs +++ b/src/serves/frontend/ceobe/operation/video/controllers.rs @@ -1,10 +1,10 @@ use std::time::Duration; +use axum_resp_result::{resp_try, FlagWrap}; use persistence::{ ceobe_operate::{ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use axum_resp_result::{resp_try, FlagWrap}; use tracing::instrument; use super::{ diff --git a/src/serves/frontend/ceobe/operation/video/error.rs b/src/serves/frontend/ceobe/operation/video/error.rs index b48e0faa..ac0dd81b 100644 --- a/src/serves/frontend/ceobe/operation/video/error.rs +++ b/src/serves/frontend/ceobe/operation/video/error.rs @@ -1,5 +1,5 @@ -use persistence::ceobe_operate::video; use axum_resp_result::FlagRespResult; +use persistence::ceobe_operate::video; use crate::error_generate; diff --git a/src/serves/frontend/ceobe/user/controllers.rs b/src/serves/frontend/ceobe/user/controllers.rs index e656b76f..2d7c10c8 100644 --- a/src/serves/frontend/ceobe/user/controllers.rs +++ b/src/serves/frontend/ceobe/user/controllers.rs @@ -1,4 +1,5 @@ use axum::Json; +use axum_resp_result::{rtry, MapReject}; use ceobe_user_logic::{ implements::CeobeUserLogic, view::{DatasourceCombResp, DatasourceConfig, MobIdReq}, @@ -10,7 +11,6 @@ use persistence::{ mysql::SqlDatabaseOperate, redis::RedisConnect, }; -use axum_resp_result::{rtry, MapReject}; use tracing::instrument; use super::error::{CeobeUserError, CeobeUserRResult}; diff --git a/src/serves/frontend/ceobe/user/error.rs b/src/serves/frontend/ceobe/user/error.rs index c5212875..4f8a26fc 100644 --- a/src/serves/frontend/ceobe/user/error.rs +++ b/src/serves/frontend/ceobe/user/error.rs @@ -1,10 +1,10 @@ use axum::extract::rejection::{JsonRejection, QueryRejection}; +use axum_resp_result::RespResult; use ceobe_user_logic::error::LogicError; use persistence::ceobe_user::{ models::check::CheckError as CeobeUserPropertyCheckError, property::OperateError, }; -use axum_resp_result::RespResult; use crate::error_generate; diff --git a/src/serves/frontend/config/datasource/controllers.rs b/src/serves/frontend/config/datasource/controllers.rs index 973ef588..8227f5bf 100644 --- a/src/serves/frontend/config/datasource/controllers.rs +++ b/src/serves/frontend/config/datasource/controllers.rs @@ -1,3 +1,4 @@ +use axum_resp_result::rtry; use persistence::{ fetcher::{ datasource_config::ToDatasource, @@ -6,7 +7,6 @@ use persistence::{ }, mysql::SqlDatabaseOperate, }; -use axum_resp_result::rtry; use tracing::instrument; use crate::{ diff --git a/src/serves/frontend/config/datasource/error.rs b/src/serves/frontend/config/datasource/error.rs index 0e41822c..1caa0bf7 100644 --- a/src/serves/frontend/config/datasource/error.rs +++ b/src/serves/frontend/config/datasource/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::QueryRejection; -use persistence::fetcher::datasource_config::OperateError as DatasourceOperateError; use axum_resp_result::RespResult; +use persistence::fetcher::datasource_config::OperateError as DatasourceOperateError; use crate::error_generate; diff --git a/src/serves/frontend/config/fetcher/controllers.rs b/src/serves/frontend/config/fetcher/controllers.rs index 3ebac616..00715496 100644 --- a/src/serves/frontend/config/fetcher/controllers.rs +++ b/src/serves/frontend/config/fetcher/controllers.rs @@ -1,11 +1,11 @@ use axum::extract::{Path, State}; +use axum_resp_result::resp_try; use bitmap_convert::{ base70::BitmapBase70Conv, vec_usize::BitmapVecUsizeConv, }; use bitmaps::Bitmap; use general_request_client::{client::RequestClient, traits::Requester}; use http::{Method, Version}; -use axum_resp_result::resp_try; use scheduler_notifier::SchedulerUrl; use serde_json::{json, Value}; use tap::Tap; diff --git a/src/serves/inside/analyze/cookie/controllers.rs b/src/serves/inside/analyze/cookie/controllers.rs index b348b034..02435a13 100644 --- a/src/serves/inside/analyze/cookie/controllers.rs +++ b/src/serves/inside/analyze/cookie/controllers.rs @@ -1,4 +1,5 @@ use axum::Json; +use axum_resp_result::{resp_try, MapReject}; use ceobe_cookie_logic::{ impletements::CeobeCookieLogic, view::NewCookieReq, }; @@ -9,7 +10,6 @@ use persistence::{ redis::RedisConnect, }; use qq_channel_warning::QqChannelGrpcService; -use axum_resp_result::{resp_try, MapReject}; use tracing::instrument; use super::error::{AnalyzeCookieError, AnalyzeCookieRResult}; diff --git a/src/serves/inside/analyze/cookie/error.rs b/src/serves/inside/analyze/cookie/error.rs index de536aec..627af80a 100644 --- a/src/serves/inside/analyze/cookie/error.rs +++ b/src/serves/inside/analyze/cookie/error.rs @@ -1,6 +1,6 @@ use axum::extract::rejection::JsonRejection; -use ceobe_cookie_logic::error::LogicError; use axum_resp_result::RespResult; +use ceobe_cookie_logic::error::LogicError; use crate::error_generate; From 64a389727f39c9fba6ac3852c2137bd4b816c8a5 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 13:23:32 +0800 Subject: [PATCH 19/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=BF=81=E7=A7=BB=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qq-channel-warning/src/grpc_client.rs | 12 +- .../src/mongo/release_version/retrieve.rs | 2 +- .../src/database_operates/db_op_impls.rs | 2 +- .../src/database_operates/mod.rs | 2 +- .../database_traits/src/get_connect.rs | 2 +- .../mongo_connection/src/impl_get_connect.rs | 3 +- .../sql_connection/src/impl_get_connect.rs | 4 +- .../checkers/desktop_version_data.rs | 34 +++- src/bootstrap/mod.rs | 1 + src/bootstrap/postprepare/migrate_version.rs | 184 ++++++++++++++++++ src/bootstrap/postprepare/mod.rs | 4 + src/main.rs | 3 + 12 files changed, 244 insertions(+), 9 deletions(-) create mode 100644 src/bootstrap/postprepare/migrate_version.rs create mode 100644 src/bootstrap/postprepare/mod.rs diff --git a/middle-server/qq-channel-warning/src/grpc_client.rs b/middle-server/qq-channel-warning/src/grpc_client.rs index a677fc18..e2edae80 100644 --- a/middle-server/qq-channel-warning/src/grpc_client.rs +++ b/middle-server/qq-channel-warning/src/grpc_client.rs @@ -13,6 +13,15 @@ pub struct QqChannelGrpcService { client: LogClient, } +impl QqChannelGrpcService { + pub async fn new_with_uri(state: QqChannelGrpcState) -> Result { + LogClient::connect(state.uri) + .await + .map_err(error::Error::Transport) + .map(|client| Self { client }) + } +} + impl FromRequestParts for QqChannelGrpcService where S: Send, @@ -62,8 +71,9 @@ impl QqChannelGrpcService { mod test { use tonic::transport::Channel; + use crate::{LogRequest, LogType, proto_reexport::LogClient}; + use super::QqChannelGrpcService; - use crate::{proto_reexport::LogClient, LogRequest, LogType}; #[tokio::test] async fn test_send() { diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index 21b95e47..a6219933 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -96,7 +96,7 @@ mod test { .await .expect("connect to db Error"); - let conn = DatabaseOperate::test_new(MongoConnect); + let conn = DatabaseOperate::new(MongoConnect); let collection = get_mongo_collection::() .expect("Collection Not Exist"); diff --git a/persistence/database/database_traits/src/database_operates/db_op_impls.rs b/persistence/database/database_traits/src/database_operates/db_op_impls.rs index d39a67c1..fa404089 100644 --- a/persistence/database/database_traits/src/database_operates/db_op_impls.rs +++ b/persistence/database/database_traits/src/database_operates/db_op_impls.rs @@ -1,4 +1,4 @@ -use axum_core::extract::FromRequestParts; +use axum_core::extract::{FromRef, FromRequestParts}; use futures::TryFutureExt; use super::DatabaseOperate; diff --git a/persistence/database/database_traits/src/database_operates/mod.rs b/persistence/database/database_traits/src/database_operates/mod.rs index f197fdc9..1e1b26ae 100644 --- a/persistence/database/database_traits/src/database_operates/mod.rs +++ b/persistence/database/database_traits/src/database_operates/mod.rs @@ -10,7 +10,7 @@ pub struct DatabaseOperate { } impl DatabaseOperate { - pub fn test_new(connect: C) -> Self { Self { connect } } + pub fn new(connect: C) -> Self { Self { connect } } } impl DerefMut for DatabaseOperate { diff --git a/persistence/database/database_traits/src/get_connect.rs b/persistence/database/database_traits/src/get_connect.rs index d03f47ca..32f335ad 100644 --- a/persistence/database/database_traits/src/get_connect.rs +++ b/persistence/database/database_traits/src/get_connect.rs @@ -1,6 +1,6 @@ use std::{error::Error as StdError, future::Future}; -pub use axum_core::extract::FromRequestParts; +pub use axum_core::extract::{FromRequestParts,FromRef}; pub use http::request::Parts; /// 获取数据库连接, 以及后续操作基本trait diff --git a/persistence/database/mongo_connection/src/impl_get_connect.rs b/persistence/database/mongo_connection/src/impl_get_connect.rs index 8255623a..e5d1dc5e 100644 --- a/persistence/database/mongo_connection/src/impl_get_connect.rs +++ b/persistence/database/mongo_connection/src/impl_get_connect.rs @@ -2,7 +2,8 @@ use core::{future::Future, marker::Send, pin::Pin}; use std::convert::Infallible; use database_traits::get_connect::{ - FromRequestParts, GetDatabaseCollection, GetDatabaseConnect, Parts, + FromRef, FromRequestParts, GetDatabaseCollection, GetDatabaseConnect, + Parts, }; use serde::{Deserialize, Serialize}; diff --git a/persistence/database/sql_connection/src/impl_get_connect.rs b/persistence/database/sql_connection/src/impl_get_connect.rs index 05406e7c..8eedd74f 100644 --- a/persistence/database/sql_connection/src/impl_get_connect.rs +++ b/persistence/database/sql_connection/src/impl_get_connect.rs @@ -6,8 +6,8 @@ use std::{ use database_traits::{ get_connect::{ - FromRequestParts, GetDatabaseConnect, GetDatabaseTransaction, Parts, - TransactionOps, + FromRef, FromRequestParts, GetDatabaseConnect, + GetDatabaseTransaction, Parts, TransactionOps, }, BoxedResultSendFuture, }; diff --git a/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs b/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs index c4299bd4..4ab92a71 100644 --- a/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs +++ b/persistence/models/sql-models/src/ceobe_operation/desktop_version/checkers/desktop_version_data.rs @@ -3,10 +3,11 @@ use checker::prefabs::{ url_checker::UrlChecker, version_checker::VersionChecker, }; use sea_orm::{IntoActiveModel, Set}; +use tracing_unwrap::ResultExt; use typed_builder::TypedBuilder; use url::Url; -use super::CheckError; +use super::{super::models::model_desktop_version, CheckError}; use crate::{ ceobe_operation::desktop_version::models::model_desktop_version::ActiveModel, get_now_naive_date_time, @@ -26,6 +27,37 @@ pub struct CeobeOperationDesktopVersion { pub baidu_text: String, } +impl From for CeobeOperationDesktopVersion { + fn from( + model_desktop_version::Model { + version, + force, + last_force_version, + description, + exe, + spare_exe, + dmg, + spare_dmg, + baidu, + baidu_text, + .. + }: model_desktop_version::Model, + ) -> Self { + Self { + version, + force, + last_force_version, + description, + exe: exe.parse().unwrap_or_log(), + spare_exe: spare_exe.parse().unwrap_or_log(), + dmg: dmg.parse().unwrap_or_log(), + spare_dmg: spare_dmg.parse().unwrap_or_log(), + baidu: baidu.parse().unwrap_or_log(), + baidu_text, + } + } +} + #[checker::check_gen( uncheck = CeobeOperationDesktopVersionUncheck, checked = CeobeOperationDesktopVersion, diff --git a/src/bootstrap/mod.rs b/src/bootstrap/mod.rs index 87548e58..f18098be 100644 --- a/src/bootstrap/mod.rs +++ b/src/bootstrap/mod.rs @@ -14,6 +14,7 @@ pub mod decorator; pub mod default_user; pub mod init; pub mod middleware; +pub mod postprepare; #[derive(Debug, Clone, FromRef, FromStateCollector)] pub struct State { diff --git a/src/bootstrap/postprepare/migrate_version.rs b/src/bootstrap/postprepare/migrate_version.rs new file mode 100644 index 00000000..067d578b --- /dev/null +++ b/src/bootstrap/postprepare/migrate_version.rs @@ -0,0 +1,184 @@ +use std::borrow::Cow; + +use axum_resp_result::{resp_result, RespError, RespResult}; +use bson::doc; +use futures::TryStreamExt; +use persistence::{ + ceobe_cookie::ToCeobe, + ceobe_operate::{ + app_version, desktop_version, + plugin_version::{PluginVersion, PluginVersionChecked}, + ToCeobeOperation, + }, + help_crates::sea_orm::{EntityTrait, QueryOrder}, + mongodb::{ + database_traits::OperateTrait, mongodb, + mongodb::options::FindOptions, MongoConnect, MongoDatabaseOperate, + MongoDbError, + }, + mysql::{sea_orm::DbErr, SqlConnect, SqlDatabaseOperate}, + operate::{DatabaseOperate, GetDatabaseConnect}, +}; +use qq_channel_warning::{ + LogRequest, LogType, QqChannelGrpcService, QqChannelGrpcState, +}; +use tracing::{error, info, instrument, warn}; +pub async fn migrate_version(qq_channel: QqChannelGrpcState) { + let qq_channel = QqChannelGrpcService::new_with_uri(qq_channel).await; + let mut qq_channel = match qq_channel { + Ok(qq_channel_warning) => qq_channel_warning, + Err(err) => { + error!(Action="Migrate Version", Error = %err); + return; + } + }; + + let a = raw_migrate_version( + DatabaseOperate::new(SqlConnect), + DatabaseOperate::new(MongoConnect), + ) + .await; + match a { + RespResult::Success(_) => {} + RespResult::Err(err) => { + qq_channel + .send_logger( + LogRequest::builder() + .info(format!("版本迁移时异常: {err}")) + .manual() + .level(LogType::Error) + .build(), + ) + .await + .ok(); + } + } +} + +#[resp_result] +#[instrument(skip_all)] +pub async fn raw_migrate_version( + sql: SqlDatabaseOperate, mongo: MongoDatabaseOperate, +) -> Result<(), Error> { + let mongo_conn = mongo.get_connect(); + + let sql = sql.get_connect(); + // 迁移 AppVersion + let all_app_version = app_version::Entity::find() + .order_by_asc(app_version::Column::CreateAt) + .all(sql) + .await?; + + info!( + Action = "Migrate Version", + Platform = "移动端", + Number = all_app_version.len() + ); + for ver in all_app_version { + let crr_ver = ver.version.clone(); + let result = mongo + .ceobe() + .operation() + .release_version() + .create() + .one(app_version::Checked::from(ver)) + .await; + + if let Err(err) = result { + warn!( + Action = "迁移旧版Version", + Version = crr_ver, + Platform = "移动端", + Error = %err + ); + } + } + + let all_desktop_version = desktop_version::Entity::find() + .order_by_asc(desktop_version::Column::CreateAt) + .all(sql) + .await?; + info!( + Action = "Migrate Version", + Platform = "桌面端", + Number = all_desktop_version.len() + ); + for ver in all_desktop_version { + let crr_ver = ver.version.clone(); + let result = mongo + .ceobe() + .operation() + .release_version() + .create() + .one(desktop_version::Checked::from(ver)) + .await; + + if let Err(err) = result { + warn!( + Action = "迁移旧版Version", + Version = crr_ver, + Platform = "桌面端", + Error = %err + ); + } + } + + let plugin_version_collection = + mongo_conn.get_collection::()?; + + let all_plugin_version = plugin_version_collection + .find( + doc! {}, + FindOptions::builder() + .sort(doc! {"time_record.create_at":1i32}) + .build(), + ) + .await? + .try_collect::>() + .await?; + + info!( + Action = "Migrate Version", + Platform = "插件端", + Number = all_plugin_version.len() + ); + for ver in all_plugin_version { + let crr_ver = ver.version.clone().to_string(); + let result = mongo + .ceobe() + .operation() + .release_version() + .create() + .one(PluginVersionChecked::from(ver)) + .await; + + if let Err(err) = result { + warn!( + Action = "迁移旧版Version", + Version = crr_ver, + Platform = "插件端", + Error = %err + ); + } + } + info!(Action = "Migrate Version", Status = "完成"); + Ok(()) +} + +#[derive(Debug, thiserror::Error)] +enum Error { + #[error(transparent)] + Db(#[from] DbErr), + #[error(transparent)] + Mongo(#[from] MongoDbError), + #[error(transparent)] + MongoErr(#[from] mongodb::error::Error), +} + +impl RespError for Error { + type ExtraMessage = i32; + + fn log_message(&self) -> Cow<'_, str> { self.to_string().into() } + + fn extra_message(&self) -> Self::ExtraMessage { 0 } +} diff --git a/src/bootstrap/postprepare/mod.rs b/src/bootstrap/postprepare/mod.rs new file mode 100644 index 00000000..72498bfd --- /dev/null +++ b/src/bootstrap/postprepare/mod.rs @@ -0,0 +1,4 @@ +mod migrate_version; + + +pub use migrate_version::migrate_version; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f4c7f588..f31af4af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,7 @@ use tower_http::compression::CompressionLayer; use tracing_unwrap::ResultExt; use crate::bootstrap::decorator::Decroator; +use crate::bootstrap::postprepare::migrate_version; mod bootstrap; mod configs; @@ -102,7 +103,9 @@ async fn main_task() { .layer(CompressionLayer::new()) .prepare_middleware::(PrepareRequestTracker) .graceful_shutdown(graceful_shutdown()) + .post_prepare(migrate_version) .preparing() + .await .expect("准备启动服务异常") .launch() From e5ac42795102949284e140e3e883f4ea7fbfbba2 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 13:24:58 +0800 Subject: [PATCH 20/68] :art: cargo fmt + clippy --- .../qq-channel-warning/src/grpc_client.rs | 7 +++-- .../src/mongo/release_version/create.rs | 17 ++++++----- .../src/database_operates/db_op_impls.rs | 2 +- .../database_traits/src/get_connect.rs | 2 +- .../mongo_connection/src/impl_get_connect.rs | 3 +- .../sql_connection/src/impl_get_connect.rs | 4 +-- .../app_version/checkers/app_version_data.rs | 30 ++++++++++++++++++- src/bootstrap/postprepare/mod.rs | 3 +- src/main.rs | 4 +-- 9 files changed, 49 insertions(+), 23 deletions(-) diff --git a/middle-server/qq-channel-warning/src/grpc_client.rs b/middle-server/qq-channel-warning/src/grpc_client.rs index e2edae80..ae82de74 100644 --- a/middle-server/qq-channel-warning/src/grpc_client.rs +++ b/middle-server/qq-channel-warning/src/grpc_client.rs @@ -14,7 +14,9 @@ pub struct QqChannelGrpcService { } impl QqChannelGrpcService { - pub async fn new_with_uri(state: QqChannelGrpcState) -> Result { + pub async fn new_with_uri( + state: QqChannelGrpcState, + ) -> Result { LogClient::connect(state.uri) .await .map_err(error::Error::Transport) @@ -71,9 +73,8 @@ impl QqChannelGrpcService { mod test { use tonic::transport::Channel; - use crate::{LogRequest, LogType, proto_reexport::LogClient}; - use super::QqChannelGrpcService; + use crate::{proto_reexport::LogClient, LogRequest, LogType}; #[tokio::test] async fn test_send() { diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs index dc587a8c..22a10ecb 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -1,3 +1,5 @@ +use serde::{Deserialize, Serialize}; + use db_ops_prelude::{ mongo_connection::MongoDbCollectionTrait, mongodb::{ @@ -5,11 +7,10 @@ use db_ops_prelude::{ options::FindOneOptions, }, }; -use serde::{Deserialize, Serialize}; use super::{ - models::{ReleaseVersion, Version}, - Error, ReleaseVersionCreate, Result, + Error, + models::{ReleaseVersion, Version}, ReleaseVersionCreate, Result, }; impl<'db, Conn> ReleaseVersionCreate<'db, Conn> @@ -55,13 +56,14 @@ where } #[cfg(test)] mod test { + use serde::{Deserialize, Serialize}; use abstract_database::ceobe::ToCeobe; use db_ops_prelude::{ - database_operates::{operate_trait::OperateTrait, DatabaseOperate}, + database_operates::{DatabaseOperate, operate_trait::OperateTrait}, mongo_connection::{ - database_traits::initial::{connect_db, connect_db_with_migrate}, - get_mongo_collection, DatabaseManage, MongoConnect, + database_traits::initial::connect_db_with_migrate, + DatabaseManage, get_mongo_collection, MongoConnect, MongoDbConfig, }, mongo_models::ceobe::operation::version::models::{ @@ -70,7 +72,6 @@ mod test { mongodb::bson::doc, }; use mongo_migration::Migrator; - use serde::{Deserialize, Serialize}; use crate::ToCeobeOperation; @@ -88,7 +89,7 @@ mod test { .await .expect("connect to db Error"); - let conn = DatabaseOperate::test_new(MongoConnect); + let conn = DatabaseOperate::new(MongoConnect); let collection = get_mongo_collection::() .expect("Collection Not Exist"); diff --git a/persistence/database/database_traits/src/database_operates/db_op_impls.rs b/persistence/database/database_traits/src/database_operates/db_op_impls.rs index fa404089..d39a67c1 100644 --- a/persistence/database/database_traits/src/database_operates/db_op_impls.rs +++ b/persistence/database/database_traits/src/database_operates/db_op_impls.rs @@ -1,4 +1,4 @@ -use axum_core::extract::{FromRef, FromRequestParts}; +use axum_core::extract::FromRequestParts; use futures::TryFutureExt; use super::DatabaseOperate; diff --git a/persistence/database/database_traits/src/get_connect.rs b/persistence/database/database_traits/src/get_connect.rs index 32f335ad..8b2fb411 100644 --- a/persistence/database/database_traits/src/get_connect.rs +++ b/persistence/database/database_traits/src/get_connect.rs @@ -1,6 +1,6 @@ use std::{error::Error as StdError, future::Future}; -pub use axum_core::extract::{FromRequestParts,FromRef}; +pub use axum_core::extract::{FromRef, FromRequestParts}; pub use http::request::Parts; /// 获取数据库连接, 以及后续操作基本trait diff --git a/persistence/database/mongo_connection/src/impl_get_connect.rs b/persistence/database/mongo_connection/src/impl_get_connect.rs index e5d1dc5e..8255623a 100644 --- a/persistence/database/mongo_connection/src/impl_get_connect.rs +++ b/persistence/database/mongo_connection/src/impl_get_connect.rs @@ -2,8 +2,7 @@ use core::{future::Future, marker::Send, pin::Pin}; use std::convert::Infallible; use database_traits::get_connect::{ - FromRef, FromRequestParts, GetDatabaseCollection, GetDatabaseConnect, - Parts, + FromRequestParts, GetDatabaseCollection, GetDatabaseConnect, Parts, }; use serde::{Deserialize, Serialize}; diff --git a/persistence/database/sql_connection/src/impl_get_connect.rs b/persistence/database/sql_connection/src/impl_get_connect.rs index 8eedd74f..05406e7c 100644 --- a/persistence/database/sql_connection/src/impl_get_connect.rs +++ b/persistence/database/sql_connection/src/impl_get_connect.rs @@ -6,8 +6,8 @@ use std::{ use database_traits::{ get_connect::{ - FromRef, FromRequestParts, GetDatabaseConnect, - GetDatabaseTransaction, Parts, TransactionOps, + FromRequestParts, GetDatabaseConnect, GetDatabaseTransaction, Parts, + TransactionOps, }, BoxedResultSendFuture, }; diff --git a/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs b/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs index 340c942b..a89d6b8f 100644 --- a/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs +++ b/persistence/models/sql-models/src/ceobe_operation/app_version/checkers/app_version_data.rs @@ -3,10 +3,11 @@ use checker::prefabs::{ url_checker::UrlChecker, version_checker::VersionChecker, }; use sea_orm::{IntoActiveModel, Set}; +use tracing_unwrap::ResultExt; use typed_builder::TypedBuilder; use url::Url; -use super::CheckError; +use super::{super::models::model_app_version, CheckError}; use crate::{ ceobe_operation::app_version::models::model_app_version::ActiveModel, get_now_naive_date_time, @@ -24,6 +25,33 @@ pub struct CeobeOperationAppVersion { pub baidu_text: String, } +impl From for CeobeOperationAppVersion { + fn from( + model_app_version::Model { + version, + force, + last_force_version, + description, + apk, + spare_apk, + baidu, + baidu_text, + .. + }: model_app_version::Model, + ) -> Self { + Self { + version, + force, + last_force_version, + description, + apk: apk.parse().unwrap_or_log(), + spare_apk: spare_apk.parse().unwrap_or_log(), + baidu: baidu.parse().unwrap_or_log(), + baidu_text, + } + } +} + #[checker::check_gen( uncheck = CeobeOperationAppVersionUncheck, checked = CeobeOperationAppVersion, diff --git a/src/bootstrap/postprepare/mod.rs b/src/bootstrap/postprepare/mod.rs index 72498bfd..4cc9939e 100644 --- a/src/bootstrap/postprepare/mod.rs +++ b/src/bootstrap/postprepare/mod.rs @@ -1,4 +1,3 @@ mod migrate_version; - -pub use migrate_version::migrate_version; \ No newline at end of file +pub use migrate_version::migrate_version; diff --git a/src/main.rs b/src/main.rs index f31af4af..68bdc91e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,8 +37,7 @@ use tencent_cloud_server::axum_starter::TencentCloudPrepare; use tower_http::compression::CompressionLayer; use tracing_unwrap::ResultExt; -use crate::bootstrap::decorator::Decroator; -use crate::bootstrap::postprepare::migrate_version; +use crate::bootstrap::{decorator::Decroator, postprepare::migrate_version}; mod bootstrap; mod configs; @@ -105,7 +104,6 @@ async fn main_task() { .graceful_shutdown(graceful_shutdown()) .post_prepare(migrate_version) .preparing() - .await .expect("准备启动服务异常") .launch() From be4aa4f7a57360890a4d331fc9b2c47daa506552 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 16:58:55 +0800 Subject: [PATCH 21/68] :art: cargo fmt --- .../src/mongo/release_version/create.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs index 22a10ecb..6e216173 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -1,5 +1,3 @@ -use serde::{Deserialize, Serialize}; - use db_ops_prelude::{ mongo_connection::MongoDbCollectionTrait, mongodb::{ @@ -7,10 +5,11 @@ use db_ops_prelude::{ options::FindOneOptions, }, }; +use serde::{Deserialize, Serialize}; use super::{ - Error, - models::{ReleaseVersion, Version}, ReleaseVersionCreate, Result, + models::{ReleaseVersion, Version}, + Error, ReleaseVersionCreate, Result, }; impl<'db, Conn> ReleaseVersionCreate<'db, Conn> @@ -56,14 +55,12 @@ where } #[cfg(test)] mod test { - use serde::{Deserialize, Serialize}; - use abstract_database::ceobe::ToCeobe; use db_ops_prelude::{ - database_operates::{DatabaseOperate, operate_trait::OperateTrait}, + database_operates::{operate_trait::OperateTrait, DatabaseOperate}, mongo_connection::{ database_traits::initial::connect_db_with_migrate, - DatabaseManage, get_mongo_collection, MongoConnect, + get_mongo_collection, DatabaseManage, MongoConnect, MongoDbConfig, }, mongo_models::ceobe::operation::version::models::{ @@ -72,6 +69,7 @@ mod test { mongodb::bson::doc, }; use mongo_migration::Migrator; + use serde::{Deserialize, Serialize}; use crate::ToCeobeOperation; From 9a5288418c44364dcf4ecc757f9940f883d66b73 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 17:25:25 +0800 Subject: [PATCH 22/68] =?UTF-8?q?:recycle:=20=E8=B0=83=E6=95=B4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/modify-cache/src/headers.rs | 2 ++ src/bootstrap/postprepare/migrate_version.rs | 4 ++-- .../frontend/ceobe/operation/version/controllers.rs | 3 ++- src/serves/frontend/ceobe/operation/version/models.rs | 11 +++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/modify-cache/src/headers.rs b/libs/modify-cache/src/headers.rs index 4099df3c..f7f397be 100644 --- a/libs/modify-cache/src/headers.rs +++ b/libs/modify-cache/src/headers.rs @@ -9,9 +9,11 @@ use nom::{ IResult, }; +#[derive(Default, Debug)] pub enum ControlHeaders { IfNoneMatch(HashSet), IfModifySince(NaiveDateTime), + #[default] None, } /// function action diff --git a/src/bootstrap/postprepare/migrate_version.rs b/src/bootstrap/postprepare/migrate_version.rs index 067d578b..fbf28ac9 100644 --- a/src/bootstrap/postprepare/migrate_version.rs +++ b/src/bootstrap/postprepare/migrate_version.rs @@ -143,7 +143,7 @@ pub async fn raw_migrate_version( Number = all_plugin_version.len() ); for ver in all_plugin_version { - let crr_ver = ver.version.clone().to_string(); + let crr_ver = ver.version.clone(); let result = mongo .ceobe() .operation() @@ -155,7 +155,7 @@ pub async fn raw_migrate_version( if let Err(err) = result { warn!( Action = "迁移旧版Version", - Version = crr_ver, + Version = %crr_ver, Platform = "插件端", Error = %err ); diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 8a07c315..70586171 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -137,7 +137,8 @@ impl CeobeOperationVersionFrontend { } #[resp_result] - #[instrument(skip_all,fields(platform = %arg_2.0.platform))] + // TODO: 这里把挂载的东西一起带进去可能会好点? + #[instrument(skip_all,fields(version = %arg_2.0))] pub async fn release_version( db: MongoDatabaseOperate, mut modify: modify_cache::CheckModify, MapReject(QueryReleaseVersion { version, platform }): MapReject< diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 4d22fc0b..0e6624b3 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -1,3 +1,5 @@ +use std::fmt::{Display, Formatter}; + use checker::{ prefabs::{ option_checker::OptionChecker, @@ -76,3 +78,12 @@ pub struct QueryReleaseVersion { pub version: Option, pub platform: ReleasePlatform, } + +impl Display for QueryReleaseVersion { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match &self.version { + Some(ver) => write!(f, "{}:{}", self.platform, ver), + None => write!(f, "{}", self.platform), + } + } +} From af8bcaa6c22bef9ec4d1f04f199f31c866082b5f Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 8 Jul 2024 17:26:32 +0800 Subject: [PATCH 23/68] :art: cargo clippy --- src/bootstrap/postprepare/migrate_version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/postprepare/migrate_version.rs b/src/bootstrap/postprepare/migrate_version.rs index fbf28ac9..fe5f358e 100644 --- a/src/bootstrap/postprepare/migrate_version.rs +++ b/src/bootstrap/postprepare/migrate_version.rs @@ -143,7 +143,7 @@ pub async fn raw_migrate_version( Number = all_plugin_version.len() ); for ver in all_plugin_version { - let crr_ver = ver.version.clone(); + let crr_ver = ver.version; let result = mongo .ceobe() .operation() From 1577b7731c3990c1cf2568c941e19a8607667f9d Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 9 Aug 2024 12:00:33 +0800 Subject: [PATCH 24/68] =?UTF-8?q?:recycle:=20=E5=B0=86=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=8E=B7=E5=8F=96=E7=A7=BB=E5=8A=A8=E5=88=B0?= =?UTF-8?q?CDN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/cdn/mod.rs | 2 +- src/router/cdn/operation/mod.rs | 5 ++- src/router/cdn/operation/version.rs | 9 ++++ src/router/mod.rs | 4 +- src/serves/cdn/ceobe/operation/mod.rs | 1 + .../ceobe/operation/version/controllers.rs | 44 +++++++++++++++++++ .../cdn/ceobe/operation/version/error.rs | 10 +++++ src/serves/cdn/ceobe/operation/version/mod.rs | 10 +++++ .../cdn/ceobe/operation/version/models.rs | 18 ++++++++ .../ceobe/operation/version/controllers.rs | 36 --------------- .../frontend/ceobe/operation/version/error.rs | 1 - .../ceobe/operation/version/models.rs | 14 ------ 12 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 src/router/cdn/operation/version.rs create mode 100644 src/serves/cdn/ceobe/operation/version/controllers.rs create mode 100644 src/serves/cdn/ceobe/operation/version/error.rs create mode 100644 src/serves/cdn/ceobe/operation/version/mod.rs create mode 100644 src/serves/cdn/ceobe/operation/version/models.rs diff --git a/src/router/cdn/mod.rs b/src/router/cdn/mod.rs index 51ace32e..9ade5c10 100644 --- a/src/router/cdn/mod.rs +++ b/src/router/cdn/mod.rs @@ -5,7 +5,7 @@ pub use cookie::{CdnCookieMainListFrontend, CdnCookieTempFrontend}; use operation::operation_router; pub use operation::{ CdnOperationAnnouncementFrontend, CdnOperationResourceFrontend, - CdnOperationVideoFrontend, + CdnOperationVideoFrontend,CdnOperationVersion }; use self::cookie::cookie_router; diff --git a/src/router/cdn/operation/mod.rs b/src/router/cdn/operation/mod.rs index 866f79e5..13da4a54 100644 --- a/src/router/cdn/operation/mod.rs +++ b/src/router/cdn/operation/mod.rs @@ -2,20 +2,23 @@ pub use announcement::CdnOperationAnnouncementFrontend; use axum::Router; pub use resource::CdnOperationResourceFrontend; pub use video::CdnOperationVideoFrontend; +pub use version::CdnOperationVersion; use self::{ announcement::announcement_router, resource::resource_router, - video::video_router, + video::video_router, version::version_router }; use crate::router::ServerRoute; mod announcement; mod resource; mod video; +mod version; pub(super) fn operation_router() -> ServerRoute { Router::new() .nest("/video", video_router()) .nest("/announcement", announcement_router()) .nest("/resource", resource_router()) + .nest("/version",version_router()) } diff --git a/src/router/cdn/operation/version.rs b/src/router/cdn/operation/version.rs new file mode 100644 index 00000000..3515a396 --- /dev/null +++ b/src/router/cdn/operation/version.rs @@ -0,0 +1,9 @@ +use axum::Router; +use axum::routing::get; + +pub struct CdnOperationVersion; + +pub(super) fn version_router()->crate::router::ServerRoute{ + Router::new() + .route("/fetch",get(CdnOperationVersion::release_version)) +} \ No newline at end of file diff --git a/src/router/mod.rs b/src/router/mod.rs index 1cbcb7f3..368910da 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -7,7 +7,7 @@ pub use back_end::{ pub use cdn::{ CdnBakeryMansionFrontend, CdnCookieMainListFrontend, CdnCookieTempFrontend, CdnOperationAnnouncementFrontend, - CdnOperationResourceFrontend, CdnOperationVideoFrontend, + CdnOperationResourceFrontend, CdnOperationVideoFrontend,CdnOperationVersion }; pub use front_end::{ BakeryMansionFrontend, CeobeOperationAnnouncementFrontend, @@ -48,7 +48,7 @@ pub fn root_route() -> ServerRoute { panic!("测试 Panic"); } #[cfg(not(debug_assertions))] - resp_result::RespResult::<_, crate::error::NotAnError>::ok( + axum_resp_result::RespResult::<_, crate::error::NotAnError>::ok( "不可以Panic", ) }), diff --git a/src/serves/cdn/ceobe/operation/mod.rs b/src/serves/cdn/ceobe/operation/mod.rs index 77506e24..af3e8ad4 100644 --- a/src/serves/cdn/ceobe/operation/mod.rs +++ b/src/serves/cdn/ceobe/operation/mod.rs @@ -1,3 +1,4 @@ pub mod announcement; pub mod resource; pub mod video; +mod version; diff --git a/src/serves/cdn/ceobe/operation/version/controllers.rs b/src/serves/cdn/ceobe/operation/version/controllers.rs new file mode 100644 index 00000000..991aaaff --- /dev/null +++ b/src/serves/cdn/ceobe/operation/version/controllers.rs @@ -0,0 +1,44 @@ +use axum::extract::Query; +use axum_resp_result::{MapReject, resp_result}; +use tracing::instrument; +use persistence::ceobe_operate::models::version::models::ReleaseVersion; +use persistence::ceobe_operate::{ToCeobe, ToCeobeOperation}; +use persistence::mongodb::MongoDatabaseOperate; +use persistence::operate::operate_trait::OperateTrait; +use crate::router::CdnOperationVersion; +use super::QueryReleaseVersion; +use super::{Result,MapRejecter}; +impl CdnOperationVersion{ + #[resp_result] + // TODO: 这里把挂载的东西一起带进去可能会好点? + #[instrument(skip_all,fields(version = %arg_1.0))] + pub async fn release_version( + db: MongoDatabaseOperate, + MapReject(QueryReleaseVersion { version, platform }): MapRejecter< + Query, + >, + ) -> Result + { + + let release_info = match version { + None => { + db.ceobe() + .operation() + .release_version() + .retrieve() + .latest_by_platform(platform) + .await? + } + Some(ver) => { + db.ceobe() + .operation() + .release_version() + .retrieve() + .by_version_platform(&ver, platform) + .await? + } + }; + + Ok(release_info) + } +} \ No newline at end of file diff --git a/src/serves/cdn/ceobe/operation/version/error.rs b/src/serves/cdn/ceobe/operation/version/error.rs new file mode 100644 index 00000000..21e1fec1 --- /dev/null +++ b/src/serves/cdn/ceobe/operation/version/error.rs @@ -0,0 +1,10 @@ +use axum::extract::rejection::QueryRejection; +use persistence::ceobe_operate::release_version::Error; +use crate::error_generate; + +error_generate! { + pub CeobeOperationVersionError + + Query = QueryRejection + MongoError = Error +} \ No newline at end of file diff --git a/src/serves/cdn/ceobe/operation/version/mod.rs b/src/serves/cdn/ceobe/operation/version/mod.rs new file mode 100644 index 00000000..95a7e731 --- /dev/null +++ b/src/serves/cdn/ceobe/operation/version/mod.rs @@ -0,0 +1,10 @@ +mod controllers; +mod error; +mod models; + +use axum_resp_result::MapReject; +use error::CeobeOperationVersionError as Error; +type Result = core::result::Result; +use models::QueryReleaseVersion; + +type MapRejecter = MapReject; \ No newline at end of file diff --git a/src/serves/cdn/ceobe/operation/version/models.rs b/src/serves/cdn/ceobe/operation/version/models.rs new file mode 100644 index 00000000..1711c09b --- /dev/null +++ b/src/serves/cdn/ceobe/operation/version/models.rs @@ -0,0 +1,18 @@ +use std::fmt::{Display, Formatter}; +use serde::Deserialize; +use persistence::ceobe_operate::models::version::models::ReleasePlatform; + +#[derive(Deserialize, Clone, Debug)] +pub struct QueryReleaseVersion { + pub version: Option, + pub platform: ReleasePlatform, +} + +impl Display for QueryReleaseVersion { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match &self.version { + Some(ver) => write!(f, "{}:{}", self.platform, ver), + None => write!(f, "{}", self.platform), + } + } +} diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 70586171..24c4b2dd 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -136,41 +136,5 @@ impl CeobeOperationVersionFrontend { .await } - #[resp_result] - // TODO: 这里把挂载的东西一起带进去可能会好点? - #[instrument(skip_all,fields(version = %arg_2.0))] - pub async fn release_version( - db: MongoDatabaseOperate, mut modify: modify_cache::CheckModify, - MapReject(QueryReleaseVersion { version, platform }): MapReject< - Query, - CeobeOperationVersionError, - >, - ) -> Result>, CeobeOperationVersionError> - { - modify - .cache_headers - .get_control() - .set_max_age(Duration::from_secs(60 * 60)); - let release_info = match version { - None => { - db.ceobe() - .operation() - .release_version() - .retrieve() - .latest_by_platform(platform) - .await? - } - Some(ver) => { - db.ceobe() - .operation() - .release_version() - .retrieve() - .by_version_platform(&ver, platform) - .await? - } - }; - let (release_info, modify) = modify.check_modify(release_info)?; - Ok(FlagWrap::new(release_info, modify)) - } } diff --git a/src/serves/frontend/ceobe/operation/version/error.rs b/src/serves/frontend/ceobe/operation/version/error.rs index 83904d17..2690950c 100644 --- a/src/serves/frontend/ceobe/operation/version/error.rs +++ b/src/serves/frontend/ceobe/operation/version/error.rs @@ -20,7 +20,6 @@ error_generate! { Query = QueryRejection AppOperate = ceobe_operate::app_version::OperateError DesktopOperate = ceobe_operate::desktop_version::OperateError - ReleaseDbOperate = release_version::Error PluginDbError = ceobe_operate::plugin_version::OperateError ModifyVerify = modify_cache::Error } diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 0e6624b3..043646c0 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -73,17 +73,3 @@ pub type OptionDesktopVersionCheckerPretreat = QueryCheckExtract< CeobeOperationVersionError, >; -#[derive(Deserialize, Clone, Debug)] -pub struct QueryReleaseVersion { - pub version: Option, - pub platform: ReleasePlatform, -} - -impl Display for QueryReleaseVersion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match &self.version { - Some(ver) => write!(f, "{}:{}", self.platform, ver), - None => write!(f, "{}", self.platform), - } - } -} From a5f4c8ab101bde347574d28fef5200d3f345b462 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 9 Aug 2024 12:03:30 +0800 Subject: [PATCH 25/68] :art: cargo fmt --- src/router/cdn/mod.rs | 2 +- src/router/cdn/operation/mod.rs | 8 +++--- src/router/cdn/operation/version.rs | 10 +++----- src/router/mod.rs | 3 ++- src/serves/cdn/ceobe/operation/mod.rs | 2 +- .../ceobe/operation/version/controllers.rs | 25 ++++++++++--------- .../cdn/ceobe/operation/version/error.rs | 3 ++- src/serves/cdn/ceobe/operation/version/mod.rs | 4 +-- .../cdn/ceobe/operation/version/models.rs | 3 ++- .../ceobe/operation/version/controllers.rs | 14 +++-------- .../frontend/ceobe/operation/version/error.rs | 1 - .../ceobe/operation/version/models.rs | 5 ++-- 12 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/router/cdn/mod.rs b/src/router/cdn/mod.rs index 9ade5c10..06c38e00 100644 --- a/src/router/cdn/mod.rs +++ b/src/router/cdn/mod.rs @@ -5,7 +5,7 @@ pub use cookie::{CdnCookieMainListFrontend, CdnCookieTempFrontend}; use operation::operation_router; pub use operation::{ CdnOperationAnnouncementFrontend, CdnOperationResourceFrontend, - CdnOperationVideoFrontend,CdnOperationVersion + CdnOperationVersion, CdnOperationVideoFrontend, }; use self::cookie::cookie_router; diff --git a/src/router/cdn/operation/mod.rs b/src/router/cdn/operation/mod.rs index 13da4a54..5a1bcedd 100644 --- a/src/router/cdn/operation/mod.rs +++ b/src/router/cdn/operation/mod.rs @@ -1,24 +1,24 @@ pub use announcement::CdnOperationAnnouncementFrontend; use axum::Router; pub use resource::CdnOperationResourceFrontend; -pub use video::CdnOperationVideoFrontend; pub use version::CdnOperationVersion; +pub use video::CdnOperationVideoFrontend; use self::{ announcement::announcement_router, resource::resource_router, - video::video_router, version::version_router + version::version_router, video::video_router, }; use crate::router::ServerRoute; mod announcement; mod resource; -mod video; mod version; +mod video; pub(super) fn operation_router() -> ServerRoute { Router::new() .nest("/video", video_router()) .nest("/announcement", announcement_router()) .nest("/resource", resource_router()) - .nest("/version",version_router()) + .nest("/version", version_router()) } diff --git a/src/router/cdn/operation/version.rs b/src/router/cdn/operation/version.rs index 3515a396..c638066b 100644 --- a/src/router/cdn/operation/version.rs +++ b/src/router/cdn/operation/version.rs @@ -1,9 +1,7 @@ -use axum::Router; -use axum::routing::get; +use axum::{routing::get, Router}; pub struct CdnOperationVersion; -pub(super) fn version_router()->crate::router::ServerRoute{ - Router::new() - .route("/fetch",get(CdnOperationVersion::release_version)) -} \ No newline at end of file +pub(super) fn version_router() -> crate::router::ServerRoute { + Router::new().route("/fetch", get(CdnOperationVersion::release_version)) +} diff --git a/src/router/mod.rs b/src/router/mod.rs index 368910da..832179ed 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -7,7 +7,8 @@ pub use back_end::{ pub use cdn::{ CdnBakeryMansionFrontend, CdnCookieMainListFrontend, CdnCookieTempFrontend, CdnOperationAnnouncementFrontend, - CdnOperationResourceFrontend, CdnOperationVideoFrontend,CdnOperationVersion + CdnOperationResourceFrontend, CdnOperationVersion, + CdnOperationVideoFrontend, }; pub use front_end::{ BakeryMansionFrontend, CeobeOperationAnnouncementFrontend, diff --git a/src/serves/cdn/ceobe/operation/mod.rs b/src/serves/cdn/ceobe/operation/mod.rs index af3e8ad4..fdf1329e 100644 --- a/src/serves/cdn/ceobe/operation/mod.rs +++ b/src/serves/cdn/ceobe/operation/mod.rs @@ -1,4 +1,4 @@ pub mod announcement; pub mod resource; -pub mod video; mod version; +pub mod video; diff --git a/src/serves/cdn/ceobe/operation/version/controllers.rs b/src/serves/cdn/ceobe/operation/version/controllers.rs index 991aaaff..1211b428 100644 --- a/src/serves/cdn/ceobe/operation/version/controllers.rs +++ b/src/serves/cdn/ceobe/operation/version/controllers.rs @@ -1,14 +1,17 @@ use axum::extract::Query; -use axum_resp_result::{MapReject, resp_result}; +use axum_resp_result::{resp_result, MapReject}; +use persistence::{ + ceobe_operate::{ + models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, + }, + mongodb::MongoDatabaseOperate, + operate::operate_trait::OperateTrait, +}; use tracing::instrument; -use persistence::ceobe_operate::models::version::models::ReleaseVersion; -use persistence::ceobe_operate::{ToCeobe, ToCeobeOperation}; -use persistence::mongodb::MongoDatabaseOperate; -use persistence::operate::operate_trait::OperateTrait; + +use super::{MapRejecter, QueryReleaseVersion, Result}; use crate::router::CdnOperationVersion; -use super::QueryReleaseVersion; -use super::{Result,MapRejecter}; -impl CdnOperationVersion{ +impl CdnOperationVersion { #[resp_result] // TODO: 这里把挂载的东西一起带进去可能会好点? #[instrument(skip_all,fields(version = %arg_1.0))] @@ -17,9 +20,7 @@ impl CdnOperationVersion{ MapReject(QueryReleaseVersion { version, platform }): MapRejecter< Query, >, - ) -> Result - { - + ) -> Result { let release_info = match version { None => { db.ceobe() @@ -41,4 +42,4 @@ impl CdnOperationVersion{ Ok(release_info) } -} \ No newline at end of file +} diff --git a/src/serves/cdn/ceobe/operation/version/error.rs b/src/serves/cdn/ceobe/operation/version/error.rs index 21e1fec1..179ae448 100644 --- a/src/serves/cdn/ceobe/operation/version/error.rs +++ b/src/serves/cdn/ceobe/operation/version/error.rs @@ -1,5 +1,6 @@ use axum::extract::rejection::QueryRejection; use persistence::ceobe_operate::release_version::Error; + use crate::error_generate; error_generate! { @@ -7,4 +8,4 @@ error_generate! { Query = QueryRejection MongoError = Error -} \ No newline at end of file +} diff --git a/src/serves/cdn/ceobe/operation/version/mod.rs b/src/serves/cdn/ceobe/operation/version/mod.rs index 95a7e731..513448fd 100644 --- a/src/serves/cdn/ceobe/operation/version/mod.rs +++ b/src/serves/cdn/ceobe/operation/version/mod.rs @@ -4,7 +4,7 @@ mod models; use axum_resp_result::MapReject; use error::CeobeOperationVersionError as Error; -type Result = core::result::Result; +type Result = core::result::Result; use models::QueryReleaseVersion; -type MapRejecter = MapReject; \ No newline at end of file +type MapRejecter = MapReject; diff --git a/src/serves/cdn/ceobe/operation/version/models.rs b/src/serves/cdn/ceobe/operation/version/models.rs index 1711c09b..bf69e25b 100644 --- a/src/serves/cdn/ceobe/operation/version/models.rs +++ b/src/serves/cdn/ceobe/operation/version/models.rs @@ -1,6 +1,7 @@ use std::fmt::{Display, Formatter}; -use serde::Deserialize; + use persistence::ceobe_operate::models::version::models::ReleasePlatform; +use serde::Deserialize; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion { diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 24c4b2dd..2d0c7a4c 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -1,15 +1,11 @@ use std::time::Duration; -use axum::extract::Query; -use axum_resp_result::{resp_result, resp_try, FlagWrap, MapReject}; +use axum_resp_result::{resp_try, FlagWrap}; use checker::CheckExtract; use persistence::{ - ceobe_operate::{ - models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, - }, + ceobe_operate::{ToCeobe, ToCeobeOperation}, mongodb::MongoDatabaseOperate, mysql::SqlDatabaseOperate, - operate::operate_trait::OperateTrait, }; use tracing::instrument; @@ -24,9 +20,7 @@ use super::{ }; use crate::{ router::CeobeOperationVersionFrontend, - serves::frontend::ceobe::operation::version::{ - error::CeobeOperationVersionError, models::QueryReleaseVersion, - }, + serves::frontend::ceobe::operation::version::models::QueryReleaseVersion, }; impl CeobeOperationVersionFrontend { @@ -135,6 +129,4 @@ impl CeobeOperationVersionFrontend { }) .await } - - } diff --git a/src/serves/frontend/ceobe/operation/version/error.rs b/src/serves/frontend/ceobe/operation/version/error.rs index 2690950c..32e751dd 100644 --- a/src/serves/frontend/ceobe/operation/version/error.rs +++ b/src/serves/frontend/ceobe/operation/version/error.rs @@ -5,7 +5,6 @@ use persistence::{ ceobe_operate::{ desktop_version, models::{app_version, plugin_version}, - release_version, }, }; diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 043646c0..0bf47623 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -1,4 +1,4 @@ -use std::fmt::{Display, Formatter}; +use std::fmt::Display; use checker::{ prefabs::{ @@ -9,7 +9,7 @@ use checker::{ }; use persistence::ceobe_operate::{ desktop_version, - models::{app_version, version::models::ReleasePlatform}, + models::app_version, plugin_version::{self, version}, }; use serde::{Deserialize, Serialize}; @@ -72,4 +72,3 @@ pub type OptionDesktopVersionCheckerPretreat = QueryCheckExtract< OptionDesktopVersionChecker, CeobeOperationVersionError, >; - From 606b8a306749b362dc2fa2566eaf152fbd310d05 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Fri, 9 Aug 2024 12:38:23 +0800 Subject: [PATCH 26/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E5=8F=AF?= =?UTF-8?q?=E6=92=A4=E5=9B=9E=E7=9A=84=E7=89=88=E6=9C=AC=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/mongo/release_version/delete.rs | 40 +++++++++++++++++++ .../src/mongo/release_version/mod.rs | 2 + .../src/mongo/release_version/retrieve.rs | 3 +- .../ceobe/operation/version/models/version.rs | 2 + 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs new file mode 100644 index 00000000..fc67817a --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs @@ -0,0 +1,40 @@ +use db_ops_prelude::{ + mongo_connection::MongoDbCollectionTrait, + mongo_models::ceobe::operation::version::models::{ + ReleasePlatform, ReleaseVersion, Version, + }, + mongodb::bson::{doc, to_bson}, +}; + +use super::Result; +impl<'db, Conn> super::ReleaseVersionDelete<'db, Conn> +where + Conn: MongoDbCollectionTrait<'db, ReleaseVersion>, +{ + /// 撤回一个已经发布的版本 + pub async fn yank( + &'db self, platform: &ReleasePlatform, version: &Version, + ) -> Result<()> { + let collection = self.get_collection()?; + + collection + .doing(|collection| { + collection.find_one_and_update( + doc! { + "platform": to_bson(platform)?, + "version": to_bson(version)?, + "yanked":false + }, + doc! { + "$set":{ + "yanked": true + } + }, + None, + ) + }) + .await?; + + Ok(()) + } +} diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs index 829de442..460b2033 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -1,5 +1,6 @@ mod create; mod retrieve; +mod delete; use db_ops_prelude::{ mongo_connection::{database_traits::dao_operator, MongoDbError}, @@ -34,6 +35,7 @@ pub enum Error { http_code = "HttpCode::CONFLICT" ))] VersionTooOld(models::Version, models::ReleasePlatform), + #[error("Bson序列化失败")] #[status_err(err(err_code = 0x0004, prefix = "ErrPrefix::MONGO_DB",))] Bson(#[from] db_ops_prelude::mongodb::bson::ser::Error), diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index a6219933..e19ff7a1 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -46,7 +46,8 @@ where info!( release.platform = ?platform); let collection = self.get_collection()?; let filter = doc! { - "platform":to_bson(&platform)? + "platform":to_bson(&platform)?, + "yanked": false }; let sort = doc! { "$natural": -1i32 diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index 16602328..f31f3dca 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -33,6 +33,8 @@ pub struct ReleaseVersion { /// 该版本的可用下载源 #[builder(via_mutators)] download_source: Vec, + #[builder(default=false)] + yanked: bool, } #[cfg(test)] From 08a9053e086522180d1f9ef52e338bb5a4fcd853 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 18:57:51 +0800 Subject: [PATCH 27/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E7=8B=AC=E7=AB=8Bcontroller=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 + libs/serve_utils/src/controller_trait.rs | 59 ++++++++++++++++++ libs/serve_utils/src/router_extra.rs | 23 +++++++ libs/serve_utils/src/view_traits.rs | 78 ++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 libs/serve_utils/src/controller_trait.rs create mode 100644 libs/serve_utils/src/router_extra.rs create mode 100644 libs/serve_utils/src/view_traits.rs diff --git a/Cargo.toml b/Cargo.toml index 9abc0178..780a4c09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ "./logic/*", "./global/*", "./service/*", + "http_service/ceobe_operation/*", ] [workspace.dependencies] @@ -108,6 +109,7 @@ hex = "0.4" serde_qs = "0.13.0" request-clients = { version = "0.1.0", path = "middle-server/request-clients" } mime = "0.3.16" +serve-utils = {version = "0.1.0", path="libs/serve_utils"} [dependencies] diff --git a/libs/serve_utils/src/controller_trait.rs b/libs/serve_utils/src/controller_trait.rs new file mode 100644 index 00000000..940a526d --- /dev/null +++ b/libs/serve_utils/src/controller_trait.rs @@ -0,0 +1,59 @@ +use std::{convert::Infallible, marker::PhantomData}; + +use axum::{routing::Route, Router}; +use axum_core::{extract::Request, response::IntoResponse}; +use axum_resp_result::{MapReject, ToInner}; +use tower::{Layer, Service}; + +pub trait ControllerRouter +where + S: Clone + Send + Sync + 'static, +{ + const BASE_URI: &'static str; + + fn route(self) -> Router { Router::new() } + + fn layer(self, layer: L) -> LayeredController + where + L: Layer + Clone + Send + 'static, + L::Service: Service + Clone + Send + 'static, + >::Response: IntoResponse + 'static, + >::Error: Into + 'static, + >::Future: Send + 'static, + { + LayeredController::new(ControllerRouter::route(self).layer(layer)) + } +} + +pub struct LayeredController { + inner: Router, + __phantom: PhantomData, +} + +impl LayeredController { + fn new(router: Router) -> Self { + Self { + inner: router, + __phantom: Default::default(), + } + } +} + +impl ControllerRouter for LayeredController +where + S: Clone + Send + Sync + 'static, + C: ControllerRouter, +{ + const BASE_URI: &'static str = >::BASE_URI; + + fn route(self) -> Router { self.inner } +} + +pub trait ControllerError { + type Error; +} + +pub type HandlerResult = + Result::Error>; +pub type HandlerMapReject = + MapReject::Error>; diff --git a/libs/serve_utils/src/router_extra.rs b/libs/serve_utils/src/router_extra.rs new file mode 100644 index 00000000..3a493d0f --- /dev/null +++ b/libs/serve_utils/src/router_extra.rs @@ -0,0 +1,23 @@ +use axum::Router; +use crate::ControllerRouter; + +pub trait ControllerRouterExt{ + fn nest_controller(self,controller:C)->Self; + + fn merge_controller(self,controller:C)->Self; + +} + +impl ControllerRouterExt for Router +where + C: ControllerRouter, + S: Send + Sync + 'static + Clone +{ + fn nest_controller(self, controller: C) -> Self { + self.nest(C::BASE_URI,>::route(controller)) + } + + fn merge_controller(self, controller: C) -> Self { + self.merge(>::route(controller)) + } +} \ No newline at end of file diff --git a/libs/serve_utils/src/view_traits.rs b/libs/serve_utils/src/view_traits.rs new file mode 100644 index 00000000..235091f1 --- /dev/null +++ b/libs/serve_utils/src/view_traits.rs @@ -0,0 +1,78 @@ +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +use crate::view_traits::_private::SealTrait; + +pub trait OptionViewField: _private::SealTrait { + fn need_serde(&self) -> bool; +} + +mod _private { + pub trait SealTrait {} +} + +#[derive(Serialize, Deserialize, Default, Debug, Clone, Copy)] +pub struct SkipField; + +impl OptionViewField for SkipField { + fn need_serde(&self) -> bool { false } +} + +impl SealTrait for SkipField {} + +#[derive(Debug, Clone)] +#[repr(transparent)] +pub struct ValueField(pub T); + +impl<'de, T: Deserialize<'de>> Deserialize<'de> for ValueField { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value = ::deserialize(deserializer)?; + Ok(Self(value)) + } +} + +impl Serialize for ValueField { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + ::serialize(&self.0, serializer) + } +} + +impl SealTrait for ValueField {} + +impl OptionViewField for ValueField { + fn need_serde(&self) -> bool { true } +} + +#[derive(Debug, Clone)] +pub struct OptionValueField(pub Option); + +impl<'de, T: Deserialize<'de>> Deserialize for OptionValueField { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value = + as Deserialize<'de>>::deserialize(deserializer)?; + Ok(Self(value)) + } +} + +impl Serialize for OptionValueField { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + Serialize::serialize(&self.0, serializer) + } +} + +impl OptionViewField for OptionValueField { + fn need_serde(&self) -> bool { self.0.is_some() } +} + +impl SealTrait for OptionValueField {} From d5c1f6643ee4bc1757ef9bf43ace68edc40d451c Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 18:58:06 +0800 Subject: [PATCH 28/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E7=8B=AC=E7=AB=8Bcontroller=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/serve_utils/Cargo.toml | 14 ++++++++++++++ libs/serve_utils/src/lib.rs | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 libs/serve_utils/Cargo.toml create mode 100644 libs/serve_utils/src/lib.rs diff --git a/libs/serve_utils/Cargo.toml b/libs/serve_utils/Cargo.toml new file mode 100644 index 00000000..13d138cf --- /dev/null +++ b/libs/serve_utils/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "serve_utils" +version = "0.1.0" +edition = "2021" + +[dependencies] +axum.workspace = true +axum-core.workspace = true +axum-resp-result.workspace = true +serde.workspace = true +status-err = { version = "0.1.0", path = "../status-err" } +thiserror.workspace = true +tower = "0.5.0" +tracing.workspace = true diff --git a/libs/serve_utils/src/lib.rs b/libs/serve_utils/src/lib.rs new file mode 100644 index 00000000..1b2fdca0 --- /dev/null +++ b/libs/serve_utils/src/lib.rs @@ -0,0 +1,13 @@ +mod controller_trait; +mod router_extra; +mod view_traits; + +pub use axum_resp_result; +pub use controller_trait::{ + ControllerError, ControllerRouter, HandlerMapReject, HandlerResult,LayeredController +}; +pub use router_extra::ControllerRouterExt; +pub use status_err; +pub use thiserror::Error as ThisError; +pub use tracing; +pub use view_traits::{OptionViewField, SkipField, ValueField,OptionValueField}; From 254b43401c9b63038eb8b555cd77228ee0cbefb9 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 19:57:17 +0800 Subject: [PATCH 29/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E7=BB=88?= =?UTF-8?q?=E7=AB=AF=E5=8C=BA=E5=88=86=E8=B7=AF=E7=94=B1=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 4 +- libs/serve_utils/Cargo.toml | 2 +- libs/serve_utils/src/controller_trait.rs | 13 +++-- libs/serve_utils/src/endpoint_type.rs | 18 +++++++ libs/serve_utils/src/lib.rs | 13 ++++- libs/serve_utils/src/router_extra.rs | 64 ++++++++++++++++++------ 6 files changed, 91 insertions(+), 23 deletions(-) create mode 100644 libs/serve_utils/src/endpoint_type.rs diff --git a/Cargo.toml b/Cargo.toml index 780a4c09..1f8b98e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,7 +110,7 @@ serde_qs = "0.13.0" request-clients = { version = "0.1.0", path = "middle-server/request-clients" } mime = "0.3.16" serve-utils = {version = "0.1.0", path="libs/serve_utils"} - +tower = { version = "0.4", features = ["limit"] } [dependencies] # async @@ -141,7 +141,7 @@ reqwest = { workspace = true } sha2 = { workspace = true } tap = { workspace = true } thiserror = { workspace = true } -tower = { version = "0.4", features = ["limit"] } +tower.workspace = true tower-http = { version = "0.5", features = ["trace", "catch-panic", "set-header", "compression-full", "auth", "add-extension", "cors"] } typed-builder = { workspace = true } url = { workspace = true } diff --git a/libs/serve_utils/Cargo.toml b/libs/serve_utils/Cargo.toml index 13d138cf..ef252762 100644 --- a/libs/serve_utils/Cargo.toml +++ b/libs/serve_utils/Cargo.toml @@ -10,5 +10,5 @@ axum-resp-result.workspace = true serde.workspace = true status-err = { version = "0.1.0", path = "../status-err" } thiserror.workspace = true -tower = "0.5.0" +tower.workspace = true tracing.workspace = true diff --git a/libs/serve_utils/src/controller_trait.rs b/libs/serve_utils/src/controller_trait.rs index 940a526d..5215c4a2 100644 --- a/libs/serve_utils/src/controller_trait.rs +++ b/libs/serve_utils/src/controller_trait.rs @@ -5,9 +5,13 @@ use axum_core::{extract::Request, response::IntoResponse}; use axum_resp_result::{MapReject, ToInner}; use tower::{Layer, Service}; -pub trait ControllerRouter +use crate::EndpointType; + +pub trait ControllerRouter where S: Clone + Send + Sync + 'static, + E: EndpointType, + Self: Sized, { const BASE_URI: &'static str; @@ -39,12 +43,13 @@ impl LayeredController { } } -impl ControllerRouter for LayeredController +impl ControllerRouter for LayeredController where S: Clone + Send + Sync + 'static, - C: ControllerRouter, + C: ControllerRouter, + E: EndpointType, { - const BASE_URI: &'static str = >::BASE_URI; + const BASE_URI: &'static str = >::BASE_URI; fn route(self) -> Router { self.inner } } diff --git a/libs/serve_utils/src/endpoint_type.rs b/libs/serve_utils/src/endpoint_type.rs new file mode 100644 index 00000000..9f1272c4 --- /dev/null +++ b/libs/serve_utils/src/endpoint_type.rs @@ -0,0 +1,18 @@ + +pub trait EndpointType{} + +pub struct UserEnd; + +impl EndpointType for UserEnd {} + +pub struct AdminEnd; + +impl EndpointType for AdminEnd {} + +pub struct CDN; + +impl EndpointType for CDN {} + +pub struct Internal; + +impl EndpointType for Internal {} \ No newline at end of file diff --git a/libs/serve_utils/src/lib.rs b/libs/serve_utils/src/lib.rs index 1b2fdca0..a63cdac5 100644 --- a/libs/serve_utils/src/lib.rs +++ b/libs/serve_utils/src/lib.rs @@ -1,13 +1,22 @@ mod controller_trait; +mod endpoint_type; mod router_extra; mod view_traits; pub use axum_resp_result; pub use controller_trait::{ - ControllerError, ControllerRouter, HandlerMapReject, HandlerResult,LayeredController + ControllerError, ControllerRouter, HandlerMapReject, HandlerResult, + LayeredController, }; +pub use endpoint_type::EndpointType; pub use router_extra::ControllerRouterExt; pub use status_err; pub use thiserror::Error as ThisError; pub use tracing; -pub use view_traits::{OptionViewField, SkipField, ValueField,OptionValueField}; +pub use view_traits::{ + OptionValueField, OptionViewField, SkipField, ValueField, +}; + +pub mod endpoint { + pub use crate::endpoint_type::{AdminEnd, Internal, UserEnd, CDN}; +} diff --git a/libs/serve_utils/src/router_extra.rs b/libs/serve_utils/src/router_extra.rs index 3a493d0f..3490d118 100644 --- a/libs/serve_utils/src/router_extra.rs +++ b/libs/serve_utils/src/router_extra.rs @@ -1,23 +1,59 @@ use axum::Router; -use crate::ControllerRouter; -pub trait ControllerRouterExt{ - fn nest_controller(self,controller:C)->Self; - - fn merge_controller(self,controller:C)->Self; - +use crate::{ControllerRouter, EndpointType}; + +pub trait ControllerRouterExt { + fn nest_controller(self, controller: C, _endpoint: E) -> Self; + + fn merge_controller(self, controller: C, _endpoint: E) -> Self; } -impl ControllerRouterExt for Router +impl ControllerRouterExt for Router where - C: ControllerRouter, - S: Send + Sync + 'static + Clone + C: ControllerRouter, + E: EndpointType, + S: Send + Sync + 'static + Clone, { - fn nest_controller(self, controller: C) -> Self { - self.nest(C::BASE_URI,>::route(controller)) + fn nest_controller(self, controller: C, _endpoint: E) -> Self { + self.nest( + C::BASE_URI, + >::route(controller), + ) } - fn merge_controller(self, controller: C) -> Self { - self.merge(>::route(controller)) + fn merge_controller(self, controller: C, _endpoint: E) -> Self { + self.merge(>::route(controller)) } -} \ No newline at end of file +} + +#[cfg(test)] +mod test { + use axum::Router; + use crate::{endpoint::AdminEnd, ControllerRouter, ControllerRouterExt}; + use crate::endpoint_type::UserEnd; + + pub struct TestController; + + impl ControllerRouter + for TestController + { + const BASE_URI: &'static str = "/admin/test"; + } + + impl ControllerRouter + for TestController + { + const BASE_URI: &'static str = "/test"; + } + #[test] + fn test_ctrl(){ + let _:Router = Router::new() + .nest_controller(TestController,UserEnd) + .nest_controller(TestController,AdminEnd) + // .nest_controller(TestController,CDN) + + ; + + + } +} From 8daad45fa744c8aeb705f63a35cdf2adbfc68a1d Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 20:28:44 +0800 Subject: [PATCH 30/68] =?UTF-8?q?:recycle:=20=E8=B0=83=E6=95=B4=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/serve_utils/src/view_traits.rs | 31 +++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/libs/serve_utils/src/view_traits.rs b/libs/serve_utils/src/view_traits.rs index 235091f1..070cc403 100644 --- a/libs/serve_utils/src/view_traits.rs +++ b/libs/serve_utils/src/view_traits.rs @@ -3,18 +3,37 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::view_traits::_private::SealTrait; pub trait OptionViewField: _private::SealTrait { - fn need_serde(&self) -> bool; + fn skip_serde(&self) -> bool; } mod _private { pub trait SealTrait {} } -#[derive(Serialize, Deserialize, Default, Debug, Clone, Copy)] +#[derive(Default, Debug, Clone, Copy)] pub struct SkipField; +impl Serialize for SkipField { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_none() + } +} + +impl<'de> Deserialize<'de> for SkipField { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let _ = <() as Deserialize<'de>>::deserialize(deserializer)?; + Ok(Self) + } +} + impl OptionViewField for SkipField { - fn need_serde(&self) -> bool { false } + fn skip_serde(&self) -> bool { true } } impl SealTrait for SkipField {} @@ -45,13 +64,13 @@ impl Serialize for ValueField { impl SealTrait for ValueField {} impl OptionViewField for ValueField { - fn need_serde(&self) -> bool { true } + fn skip_serde(&self) -> bool { false } } #[derive(Debug, Clone)] pub struct OptionValueField(pub Option); -impl<'de, T: Deserialize<'de>> Deserialize for OptionValueField { +impl<'de, T: Deserialize<'de>> Deserialize<'de> for OptionValueField { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -72,7 +91,7 @@ impl Serialize for OptionValueField { } impl OptionViewField for OptionValueField { - fn need_serde(&self) -> bool { self.0.is_some() } + fn skip_serde(&self) -> bool { self.0.is_none() } } impl SealTrait for OptionValueField {} From b31b1c2bbcf599e122b08e05afccf93f2f8924fd Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 20:42:38 +0800 Subject: [PATCH 31/68] =?UTF-8?q?:recycle:=20=E5=B0=86=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=9A=84=E7=BB=9F=E4=B8=80=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E4=B8=80=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 7 +++- .../release_version_service/Cargo.toml | 15 ++++++++ .../release_version_service/src/error.rs | 18 +++++++++ .../release_version_service/src/handlers.rs | 36 ++++++++++++++++++ .../src/handlers/admin_end.rs | 38 +++++++++++++++++++ .../src/handlers/cdn.rs | 19 ++++------ .../release_version_service/src/lib.rs | 6 +++ .../release_version_service/src/view.rs | 34 +++++++++++++++++ libs/serve_utils/src/controller_trait.rs | 6 +-- libs/serve_utils/src/lib.rs | 1 + .../src/mongo/release_version/delete.rs | 12 +++--- src/router/cdn/mod.rs | 2 +- src/router/cdn/operation/mod.rs | 8 ++-- src/router/cdn/operation/version.rs | 7 ---- src/router/mod.rs | 2 +- src/serves/cdn/ceobe/operation/mod.rs | 1 - .../cdn/ceobe/operation/version/error.rs | 11 ------ src/serves/cdn/ceobe/operation/version/mod.rs | 10 ----- .../cdn/ceobe/operation/version/models.rs | 19 ---------- .../ceobe/operation/version/controllers.rs | 2 +- .../ceobe/operation/version/models.rs | 1 - 21 files changed, 176 insertions(+), 79 deletions(-) create mode 100644 http_service/ceobe_operation/release_version_service/Cargo.toml create mode 100644 http_service/ceobe_operation/release_version_service/src/error.rs create mode 100644 http_service/ceobe_operation/release_version_service/src/handlers.rs create mode 100644 http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs rename src/serves/cdn/ceobe/operation/version/controllers.rs => http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs (65%) create mode 100644 http_service/ceobe_operation/release_version_service/src/lib.rs create mode 100644 http_service/ceobe_operation/release_version_service/src/view.rs delete mode 100644 src/router/cdn/operation/version.rs delete mode 100644 src/serves/cdn/ceobe/operation/version/error.rs delete mode 100644 src/serves/cdn/ceobe/operation/version/mod.rs delete mode 100644 src/serves/cdn/ceobe/operation/version/models.rs diff --git a/Cargo.toml b/Cargo.toml index 1f8b98e2..16f65bbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,6 +111,9 @@ request-clients = { version = "0.1.0", path = "middle-server/request-clients" } mime = "0.3.16" serve-utils = {version = "0.1.0", path="libs/serve_utils"} tower = { version = "0.4", features = ["limit"] } +status-err={path = "./libs/status-err"} + + [dependencies] # async @@ -164,6 +167,8 @@ bitmaps.workspace = true persistence = { workspace = true, features = ["prelude", "migrate"] } tencent-cloud-server.workspace = true semver = { version = "1.0.23", features = ["serde"] } +release_version_service = { version = "0.1.0", path = "http_service/ceobe_operation/release_version_service" } +serve_utils = { version = "0.1.0", path = "libs/serve_utils" } [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = "0.5.4" @@ -189,7 +194,7 @@ path = "./libs/range-limit" path = "./libs/logger" [dependencies.status-err] -path = "./libs/status-err" +workspace = true [dependencies.axum-resp-result] workspace = true diff --git a/http_service/ceobe_operation/release_version_service/Cargo.toml b/http_service/ceobe_operation/release_version_service/Cargo.toml new file mode 100644 index 00000000..06a7c599 --- /dev/null +++ b/http_service/ceobe_operation/release_version_service/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "release_version_service" +version = "0.1.0" +edition = "2021" + +[dependencies] +persistence = { workspace = true, features = ["model-ceobe-operate", "help-crates"] } +semver = "1.0.23" +serve_utils = { version = "0.1.0", path = "../../../libs/serve_utils" } +serde = { version = "1.0.201", features = ["derive"] } +thiserror.workspace = true +status-err.workspace = true +http.workspace = true +axum-resp-result.workspace = true +tracing.workspace = true \ No newline at end of file diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs new file mode 100644 index 00000000..bee653b1 --- /dev/null +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -0,0 +1,18 @@ +use persistence::ceobe_operate::release_version::Error as MongoError; +use serve_utils::{ + axum::extract::rejection::QueryRejection, status_err::StatusErr, + ControllerError, ThisError, +}; + +#[derive(Debug, ThisError, StatusErr)] +#[status_err(resp_err)] +pub enum Error { + #[error(transparent)] + MongoError(#[from] MongoError), + #[error(transparent)] + Query(#[from] QueryRejection), +} + +impl ControllerError for crate::ReleaseVersionController { + type Error = Error; +} diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs new file mode 100644 index 00000000..7587dc6f --- /dev/null +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -0,0 +1,36 @@ +use serve_utils::{ + axum::{routing::get, Router}, + endpoint::CDN, + ControllerRouter, HandlerMapReject, HandlerResult, +}; +use serve_utils::axum::routing::post; +use serve_utils::endpoint::AdminEnd; + +mod cdn; +mod admin_end; + +pub(crate) type Result = HandlerResult; +pub(crate) type MapRejecter = + HandlerMapReject; + +impl ControllerRouter + for crate::ReleaseVersionController +{ + const BASE_URI: &'static str = "/version"; + + fn route(self) -> Router { + Router::new().route("/fetch", get(Self::release_version)) + } +} + + +impl ControllerRouter +for crate::ReleaseVersionController +{ + const BASE_URI: &'static str = "/version"; + + fn route(self) -> Router { + Router::new().route("/yank", post(Self::yank_version)) + } +} + diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs new file mode 100644 index 00000000..c74833f2 --- /dev/null +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -0,0 +1,38 @@ +use persistence::{ + ceobe_operate::{ToCeobe, ToCeobeOperation}, + mongodb::MongoDatabaseOperate, + operate::operate_trait::OperateTrait, +}; +use serve_utils::{ + axum::extract::Query, + axum_resp_result::{resp_result, MapReject}, + tracing::instrument, + ValueField, +}; + +use crate::{ + handlers::{MapRejecter, Result}, + view::QueryReleaseVersion, +}; + +impl crate::ReleaseVersionController { + #[resp_result] + #[instrument(skip_all,fields(version = %arg_1.0))] + pub async fn yank_version( + db: MongoDatabaseOperate, + MapReject(QueryReleaseVersion { + version: ValueField(version), + platform, + }): MapRejecter< + Query>>, + >, + ) -> Result<()> { + db.ceobe() + .operation() + .release_version() + .delete() + .yank(&platform, &version) + .await?; + Ok(()) + } +} diff --git a/src/serves/cdn/ceobe/operation/version/controllers.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs similarity index 65% rename from src/serves/cdn/ceobe/operation/version/controllers.rs rename to http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index 1211b428..d15c949b 100644 --- a/src/serves/cdn/ceobe/operation/version/controllers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -1,23 +1,18 @@ -use axum::extract::Query; -use axum_resp_result::{resp_result, MapReject}; use persistence::{ - ceobe_operate::{ - models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, - }, + ceobe_operate::{ToCeobe, ToCeobeOperation}, mongodb::MongoDatabaseOperate, operate::operate_trait::OperateTrait, }; -use tracing::instrument; - -use super::{MapRejecter, QueryReleaseVersion, Result}; -use crate::router::CdnOperationVersion; -impl CdnOperationVersion { +use persistence::ceobe_operate::models::version::models::ReleaseVersion; +use serve_utils::{axum::extract::Query, axum_resp_result::{resp_result, MapReject}, OptionValueField, tracing::instrument}; +use crate::view::QueryReleaseVersion; +use super::{MapRejecter, Result}; +impl crate::ReleaseVersionController { #[resp_result] - // TODO: 这里把挂载的东西一起带进去可能会好点? #[instrument(skip_all,fields(version = %arg_1.0))] pub async fn release_version( db: MongoDatabaseOperate, - MapReject(QueryReleaseVersion { version, platform }): MapRejecter< + MapReject(QueryReleaseVersion { version:OptionValueField(version), platform }): MapRejecter< Query, >, ) -> Result { diff --git a/http_service/ceobe_operation/release_version_service/src/lib.rs b/http_service/ceobe_operation/release_version_service/src/lib.rs new file mode 100644 index 00000000..c5b0dec8 --- /dev/null +++ b/http_service/ceobe_operation/release_version_service/src/lib.rs @@ -0,0 +1,6 @@ +mod handlers; +mod error; +mod view; + +pub struct ReleaseVersionController; + diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs new file mode 100644 index 00000000..a1fb1830 --- /dev/null +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -0,0 +1,34 @@ +use std::fmt::{Display, Formatter}; + +use persistence::ceobe_operate::models::version::models::ReleasePlatform; +use semver::Version; +use serde::Deserialize; +use serve_utils::{OptionValueField, OptionViewField, ValueField}; + +#[derive(Deserialize, Clone, Debug)] +pub struct QueryReleaseVersion< + Version: OptionViewField = OptionValueField, +> { + #[serde(skip_serializing_if = "OptionViewField::skip_serde")] + pub version: Version, + pub platform: ReleasePlatform, +} + +impl Display for QueryReleaseVersion> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}->{}", self.platform, self.version.0) + } +} + +impl Display for QueryReleaseVersion> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match &self.version.0 { + None => { + write!(f, "{}", self.platform) + } + Some(ver) => { + write!(f, "{}->{}", self.platform, ver) + } + } + } +} diff --git a/libs/serve_utils/src/controller_trait.rs b/libs/serve_utils/src/controller_trait.rs index 5215c4a2..5967819f 100644 --- a/libs/serve_utils/src/controller_trait.rs +++ b/libs/serve_utils/src/controller_trait.rs @@ -58,7 +58,5 @@ pub trait ControllerError { type Error; } -pub type HandlerResult = - Result::Error>; -pub type HandlerMapReject = - MapReject::Error>; +pub type HandlerResult = Result::Error>; +pub type HandlerMapReject = MapReject::Error>; diff --git a/libs/serve_utils/src/lib.rs b/libs/serve_utils/src/lib.rs index a63cdac5..1a04bef0 100644 --- a/libs/serve_utils/src/lib.rs +++ b/libs/serve_utils/src/lib.rs @@ -3,6 +3,7 @@ mod endpoint_type; mod router_extra; mod view_traits; +pub use axum; pub use axum_resp_result; pub use controller_trait::{ ControllerError, ControllerRouter, HandlerMapReject, HandlerResult, diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs index fc67817a..24af5e50 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs @@ -16,15 +16,15 @@ where &'db self, platform: &ReleasePlatform, version: &Version, ) -> Result<()> { let collection = self.get_collection()?; - + let filter = doc! { + "platform": to_bson(platform)?, + "version": to_bson(version)?, + "yanked":false + }; collection .doing(|collection| { collection.find_one_and_update( - doc! { - "platform": to_bson(platform)?, - "version": to_bson(version)?, - "yanked":false - }, + filter, doc! { "$set":{ "yanked": true diff --git a/src/router/cdn/mod.rs b/src/router/cdn/mod.rs index 06c38e00..86e547c3 100644 --- a/src/router/cdn/mod.rs +++ b/src/router/cdn/mod.rs @@ -5,7 +5,7 @@ pub use cookie::{CdnCookieMainListFrontend, CdnCookieTempFrontend}; use operation::operation_router; pub use operation::{ CdnOperationAnnouncementFrontend, CdnOperationResourceFrontend, - CdnOperationVersion, CdnOperationVideoFrontend, + CdnOperationVideoFrontend, }; use self::cookie::cookie_router; diff --git a/src/router/cdn/operation/mod.rs b/src/router/cdn/operation/mod.rs index 5a1bcedd..adcbce13 100644 --- a/src/router/cdn/operation/mod.rs +++ b/src/router/cdn/operation/mod.rs @@ -1,18 +1,18 @@ pub use announcement::CdnOperationAnnouncementFrontend; use axum::Router; +use release_version_service::ReleaseVersionController; pub use resource::CdnOperationResourceFrontend; -pub use version::CdnOperationVersion; +use serve_utils::{endpoint::CDN, ControllerRouterExt}; pub use video::CdnOperationVideoFrontend; use self::{ announcement::announcement_router, resource::resource_router, - version::version_router, video::video_router, + video::video_router, }; use crate::router::ServerRoute; mod announcement; mod resource; -mod version; mod video; pub(super) fn operation_router() -> ServerRoute { @@ -20,5 +20,5 @@ pub(super) fn operation_router() -> ServerRoute { .nest("/video", video_router()) .nest("/announcement", announcement_router()) .nest("/resource", resource_router()) - .nest("/version", version_router()) + .nest_controller(ReleaseVersionController, CDN) } diff --git a/src/router/cdn/operation/version.rs b/src/router/cdn/operation/version.rs deleted file mode 100644 index c638066b..00000000 --- a/src/router/cdn/operation/version.rs +++ /dev/null @@ -1,7 +0,0 @@ -use axum::{routing::get, Router}; - -pub struct CdnOperationVersion; - -pub(super) fn version_router() -> crate::router::ServerRoute { - Router::new().route("/fetch", get(CdnOperationVersion::release_version)) -} diff --git a/src/router/mod.rs b/src/router/mod.rs index 832179ed..2c4cfaff 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -7,7 +7,7 @@ pub use back_end::{ pub use cdn::{ CdnBakeryMansionFrontend, CdnCookieMainListFrontend, CdnCookieTempFrontend, CdnOperationAnnouncementFrontend, - CdnOperationResourceFrontend, CdnOperationVersion, + CdnOperationResourceFrontend, CdnOperationVideoFrontend, }; pub use front_end::{ diff --git a/src/serves/cdn/ceobe/operation/mod.rs b/src/serves/cdn/ceobe/operation/mod.rs index fdf1329e..77506e24 100644 --- a/src/serves/cdn/ceobe/operation/mod.rs +++ b/src/serves/cdn/ceobe/operation/mod.rs @@ -1,4 +1,3 @@ pub mod announcement; pub mod resource; -mod version; pub mod video; diff --git a/src/serves/cdn/ceobe/operation/version/error.rs b/src/serves/cdn/ceobe/operation/version/error.rs deleted file mode 100644 index 179ae448..00000000 --- a/src/serves/cdn/ceobe/operation/version/error.rs +++ /dev/null @@ -1,11 +0,0 @@ -use axum::extract::rejection::QueryRejection; -use persistence::ceobe_operate::release_version::Error; - -use crate::error_generate; - -error_generate! { - pub CeobeOperationVersionError - - Query = QueryRejection - MongoError = Error -} diff --git a/src/serves/cdn/ceobe/operation/version/mod.rs b/src/serves/cdn/ceobe/operation/version/mod.rs deleted file mode 100644 index 513448fd..00000000 --- a/src/serves/cdn/ceobe/operation/version/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -mod controllers; -mod error; -mod models; - -use axum_resp_result::MapReject; -use error::CeobeOperationVersionError as Error; -type Result = core::result::Result; -use models::QueryReleaseVersion; - -type MapRejecter = MapReject; diff --git a/src/serves/cdn/ceobe/operation/version/models.rs b/src/serves/cdn/ceobe/operation/version/models.rs deleted file mode 100644 index bf69e25b..00000000 --- a/src/serves/cdn/ceobe/operation/version/models.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::fmt::{Display, Formatter}; - -use persistence::ceobe_operate::models::version::models::ReleasePlatform; -use serde::Deserialize; - -#[derive(Deserialize, Clone, Debug)] -pub struct QueryReleaseVersion { - pub version: Option, - pub platform: ReleasePlatform, -} - -impl Display for QueryReleaseVersion { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - match &self.version { - Some(ver) => write!(f, "{}:{}", self.platform, ver), - None => write!(f, "{}", self.platform), - } - } -} diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index 2d0c7a4c..bb7da815 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -20,7 +20,7 @@ use super::{ }; use crate::{ router::CeobeOperationVersionFrontend, - serves::frontend::ceobe::operation::version::models::QueryReleaseVersion, + }; impl CeobeOperationVersionFrontend { diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 0bf47623..6c07c7f5 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -1,4 +1,3 @@ -use std::fmt::Display; use checker::{ prefabs::{ From 974436e4fd40636dfb490dbc2f152d0359e8f0cc Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 21:19:42 +0800 Subject: [PATCH 32/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=9F=A5=E7=9C=8B=E4=B8=8E=E6=B7=BB=E5=8A=A0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/Cargo.toml | 3 +- .../release_version_service/src/error.rs | 3 ++ .../release_version_service/src/handlers.rs | 22 +++++---- .../src/handlers/admin_end.rs | 42 +++++++++++++++-- .../release_version_service/src/view.rs | 46 ++++++++++++++++++- libs/serve_utils/src/view_traits.rs | 2 +- .../src/mongo/release_version/retrieve.rs | 37 ++++++++++++++- src/router/back_end/ceobe_operation/mod.rs | 5 ++ 8 files changed, 140 insertions(+), 20 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/Cargo.toml b/http_service/ceobe_operation/release_version_service/Cargo.toml index 06a7c599..6bac114b 100644 --- a/http_service/ceobe_operation/release_version_service/Cargo.toml +++ b/http_service/ceobe_operation/release_version_service/Cargo.toml @@ -12,4 +12,5 @@ thiserror.workspace = true status-err.workspace = true http.workspace = true axum-resp-result.workspace = true -tracing.workspace = true \ No newline at end of file +tracing.workspace = true +serde_json.workspace = true diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index bee653b1..90083e06 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -3,6 +3,7 @@ use serve_utils::{ axum::extract::rejection::QueryRejection, status_err::StatusErr, ControllerError, ThisError, }; +use serve_utils::axum::extract::rejection::JsonRejection; #[derive(Debug, ThisError, StatusErr)] #[status_err(resp_err)] @@ -11,6 +12,8 @@ pub enum Error { MongoError(#[from] MongoError), #[error(transparent)] Query(#[from] QueryRejection), + #[error(transparent)] + Json(#[from]JsonRejection) } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 7587dc6f..918b5da7 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -1,13 +1,14 @@ use serve_utils::{ - axum::{routing::get, Router}, - endpoint::CDN, + axum::{ + routing::{get, post}, + Router, + }, + endpoint::{AdminEnd, CDN}, ControllerRouter, HandlerMapReject, HandlerResult, }; -use serve_utils::axum::routing::post; -use serve_utils::endpoint::AdminEnd; -mod cdn; mod admin_end; +mod cdn; pub(crate) type Result = HandlerResult; pub(crate) type MapRejecter = @@ -23,14 +24,15 @@ impl ControllerRouter } } - impl ControllerRouter -for crate::ReleaseVersionController + for crate::ReleaseVersionController { - const BASE_URI: &'static str = "/version"; + const BASE_URI: &'static str = "/release_version"; fn route(self) -> Router { - Router::new().route("/yank", post(Self::yank_version)) + Router::new() + .route("/yank", post(Self::yank_version)) + .route("/create", post(Self::new_version)) + .route("/all", get(Self::all_version)) } } - diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index c74833f2..2f21876c 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -1,18 +1,20 @@ use persistence::{ - ceobe_operate::{ToCeobe, ToCeobeOperation}, + ceobe_operate::{ + models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, + }, mongodb::MongoDatabaseOperate, operate::operate_trait::OperateTrait, }; use serve_utils::{ - axum::extract::Query, + axum::{extract::Query, Json}, axum_resp_result::{resp_result, MapReject}, tracing::instrument, - ValueField, + SkipField, ValueField, }; use crate::{ handlers::{MapRejecter, Result}, - view::QueryReleaseVersion, + view::{QueryReleaseVersion, QueryVersionFilter}, }; impl crate::ReleaseVersionController { @@ -35,4 +37,36 @@ impl crate::ReleaseVersionController { .await?; Ok(()) } + + #[resp_result] + #[instrument(skip_all)] + pub async fn all_version( + db: MongoDatabaseOperate, + MapReject(filter): MapRejecter>>, + ) -> Result> { + let filter = filter.unwrap_or_default(); + let ret = db + .ceobe() + .operation() + .release_version() + .retrieve() + .all(filter.platform, filter.yanked) + .await?; + Ok(ret) + } + + #[resp_result] + #[instrument(skip_all,fields(version = %(arg_1.0.version)))] + pub async fn new_version( + db: MongoDatabaseOperate, + MapReject(release): MapRejecter>, + ) -> Result<()> { + db.ceobe() + .operation() + .release_version() + .create() + .one(release) + .await?; + Ok(()) + } } diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index a1fb1830..df53ae2e 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -1,8 +1,9 @@ use std::fmt::{Display, Formatter}; -use persistence::ceobe_operate::models::version::models::ReleasePlatform; use semver::Version; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; + +use persistence::ceobe_operate::models::version::models::ReleasePlatform; use serve_utils::{OptionValueField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] @@ -32,3 +33,44 @@ impl Display for QueryReleaseVersion> { } } } + +#[derive(Debug, Deserialize,Default)] +pub struct QueryVersionFilter { + pub platform: Option, + pub yanked: bool, +} + +impl Display for QueryVersionFilter { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match &self.platform { + None => { + write!(f, "{{yanked: {} }}", self.yanked) + } + Some(plat) => { + write!( + f, + "{{yanked: {}, platform: {}}}", + self.yanked, plat + ) + } + } + } +} + +#[cfg(test)] +mod test { + use serve_utils::SkipField; + + use crate::view::QueryReleaseVersion; + + #[test] + fn test_de() { + let js = serde_json::json!({ + "platform":"desktop" + }); + let v = serde_json::from_value::>(js) + .expect("Err"); + + println!("{v:?}") + } +} diff --git a/libs/serve_utils/src/view_traits.rs b/libs/serve_utils/src/view_traits.rs index 070cc403..835bf32b 100644 --- a/libs/serve_utils/src/view_traits.rs +++ b/libs/serve_utils/src/view_traits.rs @@ -27,7 +27,7 @@ impl<'de> Deserialize<'de> for SkipField { where D: Deserializer<'de>, { - let _ = <() as Deserialize<'de>>::deserialize(deserializer)?; + let _ = as Deserialize<'de>>::deserialize(deserializer)?; Ok(Self) } } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index e19ff7a1..7207ac8b 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -1,9 +1,10 @@ use db_ops_prelude::{ - mongo_connection::MongoDbCollectionTrait, + futures::TryStreamExt, + mongo_connection::{MongoDbCollectionTrait, MongoDbError}, mongo_models::ceobe::operation::version::models::ReleasePlatform, mongodb::{ bson::{doc, to_bson}, - options::FindOneOptions, + options::{FindOneOptions, FindOptions}, }, }; use tracing::info; @@ -65,6 +66,38 @@ where Ok(ret) } + + pub async fn all( + &'db self, platform: Option, yanked: bool, + ) -> Result> { + let collection = self.get_collection()?; + let filter = match platform { + None => { + doc! {"yanked": yanked} + } + Some(plat) => { + doc! { + "platform":to_bson(&plat)?, + "yanked": yanked + } + } + }; + let sort = doc! { + "$natural": -1i32 + }; + + let ret = collection + .doing(|collection| { + collection + .find(filter, FindOptions::builder().sort(sort).build()) + }) + .await? + .try_collect() + .await + .map_err(MongoDbError::Mongo)?; + + Ok(ret) + } } #[cfg(test)] diff --git a/src/router/back_end/ceobe_operation/mod.rs b/src/router/back_end/ceobe_operation/mod.rs index b91c9a17..80cd9bb8 100644 --- a/src/router/back_end/ceobe_operation/mod.rs +++ b/src/router/back_end/ceobe_operation/mod.rs @@ -1,6 +1,10 @@ pub use announcement::CeobeOperationAnnouncement; use axum::Router; +use persistence::ceobe_operate::models::version::models::ReleaseVersion; +use release_version_service::ReleaseVersionController; pub use resource::CeobeOpResource; +use serve_utils::ControllerRouterExt; +use serve_utils::endpoint::AdminEnd; pub use tool_link::CeobeOpToolLink; pub use version::CeobeOpVersion; pub use video::CeobeOperationVideo; @@ -28,6 +32,7 @@ pub(super) fn ceobe_operation_router() -> crate::router::ServerRoute { .nest("/video", video_router()) .nest("/version", version_router()) .nest("/resource", resource_router()) + .nest_controller(ReleaseVersionController,AdminEnd) .route_layer(AuthorizeLayer::::new()) .merge( Router::new() From 66c4720ad9927c83d76f4eeea8acfd0e07b5afbe Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 19 Aug 2024 21:24:10 +0800 Subject: [PATCH 33/68] :art: cargo clippy & cargo fmt --- .../release_version_service/src/error.rs | 8 +++---- .../src/handlers/admin_end.rs | 2 +- .../src/handlers/cdn.rs | 22 +++++++++++++------ .../release_version_service/src/lib.rs | 3 +-- .../release_version_service/src/view.rs | 13 ++++------- libs/serve_utils/src/controller_trait.rs | 4 ++-- libs/serve_utils/src/endpoint_type.rs | 5 ++--- libs/serve_utils/src/router_extra.rs | 14 ++++++------ .../src/mongo/release_version/mod.rs | 4 ++-- .../ceobe/operation/version/models/version.rs | 2 +- src/router/back_end/ceobe_operation/mod.rs | 6 ++--- src/router/cdn/mod.rs | 2 +- src/router/cdn/operation/mod.rs | 2 +- src/router/mod.rs | 3 +-- .../ceobe/operation/version/controllers.rs | 5 +---- .../ceobe/operation/version/models.rs | 1 - 16 files changed, 45 insertions(+), 51 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index 90083e06..2284ac96 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -1,19 +1,19 @@ use persistence::ceobe_operate::release_version::Error as MongoError; use serve_utils::{ - axum::extract::rejection::QueryRejection, status_err::StatusErr, + axum::extract::rejection::{JsonRejection, QueryRejection}, + status_err::StatusErr, ControllerError, ThisError, }; -use serve_utils::axum::extract::rejection::JsonRejection; #[derive(Debug, ThisError, StatusErr)] #[status_err(resp_err)] pub enum Error { #[error(transparent)] - MongoError(#[from] MongoError), + Mongo(#[from] MongoError), #[error(transparent)] Query(#[from] QueryRejection), #[error(transparent)] - Json(#[from]JsonRejection) + Json(#[from] JsonRejection), } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index 2f21876c..5ac4dd43 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -9,7 +9,7 @@ use serve_utils::{ axum::{extract::Query, Json}, axum_resp_result::{resp_result, MapReject}, tracing::instrument, - SkipField, ValueField, + ValueField, }; use crate::{ diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index d15c949b..4ecc3bf2 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -1,20 +1,28 @@ use persistence::{ - ceobe_operate::{ToCeobe, ToCeobeOperation}, + ceobe_operate::{ + models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, + }, mongodb::MongoDatabaseOperate, operate::operate_trait::OperateTrait, }; -use persistence::ceobe_operate::models::version::models::ReleaseVersion; -use serve_utils::{axum::extract::Query, axum_resp_result::{resp_result, MapReject}, OptionValueField, tracing::instrument}; -use crate::view::QueryReleaseVersion; +use serve_utils::{ + axum::extract::Query, + axum_resp_result::{resp_result, MapReject}, + tracing::instrument, + OptionValueField, +}; + use super::{MapRejecter, Result}; +use crate::view::QueryReleaseVersion; impl crate::ReleaseVersionController { #[resp_result] #[instrument(skip_all,fields(version = %arg_1.0))] pub async fn release_version( db: MongoDatabaseOperate, - MapReject(QueryReleaseVersion { version:OptionValueField(version), platform }): MapRejecter< - Query, - >, + MapReject(QueryReleaseVersion { + version: OptionValueField(version), + platform, + }): MapRejecter>, ) -> Result { let release_info = match version { None => { diff --git a/http_service/ceobe_operation/release_version_service/src/lib.rs b/http_service/ceobe_operation/release_version_service/src/lib.rs index c5b0dec8..f5e8bb2a 100644 --- a/http_service/ceobe_operation/release_version_service/src/lib.rs +++ b/http_service/ceobe_operation/release_version_service/src/lib.rs @@ -1,6 +1,5 @@ -mod handlers; mod error; +mod handlers; mod view; pub struct ReleaseVersionController; - diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index df53ae2e..06c417f9 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -1,9 +1,8 @@ use std::fmt::{Display, Formatter}; -use semver::Version; -use serde::{Deserialize, Serialize}; - use persistence::ceobe_operate::models::version::models::ReleasePlatform; +use semver::Version; +use serde::Deserialize; use serve_utils::{OptionValueField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] @@ -34,7 +33,7 @@ impl Display for QueryReleaseVersion> { } } -#[derive(Debug, Deserialize,Default)] +#[derive(Debug, Deserialize, Default)] pub struct QueryVersionFilter { pub platform: Option, pub yanked: bool, @@ -47,11 +46,7 @@ impl Display for QueryVersionFilter { write!(f, "{{yanked: {} }}", self.yanked) } Some(plat) => { - write!( - f, - "{{yanked: {}, platform: {}}}", - self.yanked, plat - ) + write!(f, "{{yanked: {}, platform: {}}}", self.yanked, plat) } } } diff --git a/libs/serve_utils/src/controller_trait.rs b/libs/serve_utils/src/controller_trait.rs index 5967819f..756c2afa 100644 --- a/libs/serve_utils/src/controller_trait.rs +++ b/libs/serve_utils/src/controller_trait.rs @@ -2,7 +2,7 @@ use std::{convert::Infallible, marker::PhantomData}; use axum::{routing::Route, Router}; use axum_core::{extract::Request, response::IntoResponse}; -use axum_resp_result::{MapReject, ToInner}; +use axum_resp_result::MapReject; use tower::{Layer, Service}; use crate::EndpointType; @@ -17,7 +17,7 @@ where fn route(self) -> Router { Router::new() } - fn layer(self, layer: L) -> LayeredController + fn layer(self, layer: L) -> LayeredController where L: Layer + Clone + Send + 'static, L::Service: Service + Clone + Send + 'static, diff --git a/libs/serve_utils/src/endpoint_type.rs b/libs/serve_utils/src/endpoint_type.rs index 9f1272c4..77ff66e3 100644 --- a/libs/serve_utils/src/endpoint_type.rs +++ b/libs/serve_utils/src/endpoint_type.rs @@ -1,5 +1,4 @@ - -pub trait EndpointType{} +pub trait EndpointType {} pub struct UserEnd; @@ -15,4 +14,4 @@ impl EndpointType for CDN {} pub struct Internal; -impl EndpointType for Internal {} \ No newline at end of file +impl EndpointType for Internal {} diff --git a/libs/serve_utils/src/router_extra.rs b/libs/serve_utils/src/router_extra.rs index 3490d118..11a7329a 100644 --- a/libs/serve_utils/src/router_extra.rs +++ b/libs/serve_utils/src/router_extra.rs @@ -29,8 +29,11 @@ where #[cfg(test)] mod test { use axum::Router; - use crate::{endpoint::AdminEnd, ControllerRouter, ControllerRouterExt}; - use crate::endpoint_type::UserEnd; + + use crate::{ + endpoint::AdminEnd, endpoint_type::UserEnd, ControllerRouter, + ControllerRouterExt, + }; pub struct TestController; @@ -41,19 +44,16 @@ mod test { } impl ControllerRouter - for TestController + for TestController { const BASE_URI: &'static str = "/test"; } #[test] - fn test_ctrl(){ + fn test_ctrl() { let _:Router = Router::new() .nest_controller(TestController,UserEnd) .nest_controller(TestController,AdminEnd) // .nest_controller(TestController,CDN) - ; - - } } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs index 460b2033..4646f20a 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -1,6 +1,6 @@ mod create; -mod retrieve; mod delete; +mod retrieve; use db_ops_prelude::{ mongo_connection::{database_traits::dao_operator, MongoDbError}, @@ -35,7 +35,7 @@ pub enum Error { http_code = "HttpCode::CONFLICT" ))] VersionTooOld(models::Version, models::ReleasePlatform), - + #[error("Bson序列化失败")] #[status_err(err(err_code = 0x0004, prefix = "ErrPrefix::MONGO_DB",))] Bson(#[from] db_ops_prelude::mongodb::bson::ser::Error), diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index f31f3dca..7b297b14 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -33,7 +33,7 @@ pub struct ReleaseVersion { /// 该版本的可用下载源 #[builder(via_mutators)] download_source: Vec, - #[builder(default=false)] + #[builder(default = false)] yanked: bool, } diff --git a/src/router/back_end/ceobe_operation/mod.rs b/src/router/back_end/ceobe_operation/mod.rs index 80cd9bb8..93a59549 100644 --- a/src/router/back_end/ceobe_operation/mod.rs +++ b/src/router/back_end/ceobe_operation/mod.rs @@ -1,10 +1,8 @@ pub use announcement::CeobeOperationAnnouncement; use axum::Router; -use persistence::ceobe_operate::models::version::models::ReleaseVersion; use release_version_service::ReleaseVersionController; pub use resource::CeobeOpResource; -use serve_utils::ControllerRouterExt; -use serve_utils::endpoint::AdminEnd; +use serve_utils::{endpoint::AdminEnd, ControllerRouterExt}; pub use tool_link::CeobeOpToolLink; pub use version::CeobeOpVersion; pub use video::CeobeOperationVideo; @@ -32,7 +30,7 @@ pub(super) fn ceobe_operation_router() -> crate::router::ServerRoute { .nest("/video", video_router()) .nest("/version", version_router()) .nest("/resource", resource_router()) - .nest_controller(ReleaseVersionController,AdminEnd) + .nest_controller(ReleaseVersionController, AdminEnd) .route_layer(AuthorizeLayer::::new()) .merge( Router::new() diff --git a/src/router/cdn/mod.rs b/src/router/cdn/mod.rs index 86e547c3..51ace32e 100644 --- a/src/router/cdn/mod.rs +++ b/src/router/cdn/mod.rs @@ -5,7 +5,7 @@ pub use cookie::{CdnCookieMainListFrontend, CdnCookieTempFrontend}; use operation::operation_router; pub use operation::{ CdnOperationAnnouncementFrontend, CdnOperationResourceFrontend, - CdnOperationVideoFrontend, + CdnOperationVideoFrontend, }; use self::cookie::cookie_router; diff --git a/src/router/cdn/operation/mod.rs b/src/router/cdn/operation/mod.rs index adcbce13..4c920d9c 100644 --- a/src/router/cdn/operation/mod.rs +++ b/src/router/cdn/operation/mod.rs @@ -7,7 +7,7 @@ pub use video::CdnOperationVideoFrontend; use self::{ announcement::announcement_router, resource::resource_router, - video::video_router, + video::video_router, }; use crate::router::ServerRoute; diff --git a/src/router/mod.rs b/src/router/mod.rs index 2c4cfaff..38094c5d 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -7,8 +7,7 @@ pub use back_end::{ pub use cdn::{ CdnBakeryMansionFrontend, CdnCookieMainListFrontend, CdnCookieTempFrontend, CdnOperationAnnouncementFrontend, - CdnOperationResourceFrontend, - CdnOperationVideoFrontend, + CdnOperationResourceFrontend, CdnOperationVideoFrontend, }; pub use front_end::{ BakeryMansionFrontend, CeobeOperationAnnouncementFrontend, diff --git a/src/serves/frontend/ceobe/operation/version/controllers.rs b/src/serves/frontend/ceobe/operation/version/controllers.rs index bb7da815..6ca1c83a 100644 --- a/src/serves/frontend/ceobe/operation/version/controllers.rs +++ b/src/serves/frontend/ceobe/operation/version/controllers.rs @@ -18,10 +18,7 @@ use super::{ }, view::{AppVersionView, DesktopVersionView, PluginVersionView}, }; -use crate::{ - router::CeobeOperationVersionFrontend, - -}; +use crate::router::CeobeOperationVersionFrontend; impl CeobeOperationVersionFrontend { // 获取app对应版本信息 diff --git a/src/serves/frontend/ceobe/operation/version/models.rs b/src/serves/frontend/ceobe/operation/version/models.rs index 6c07c7f5..8e545013 100644 --- a/src/serves/frontend/ceobe/operation/version/models.rs +++ b/src/serves/frontend/ceobe/operation/version/models.rs @@ -1,4 +1,3 @@ - use checker::{ prefabs::{ option_checker::OptionChecker, From b3ed8ecd256fc29fe7da1bd5988b5372c1989753 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 15:55:10 +0800 Subject: [PATCH 34/68] :art: cargo fmt --- persistence/models/mongo-models/src/ceobe/operation/mod.rs | 2 +- persistence/persistence/src/lib.rs | 2 +- src/router/back_end/ceobe_operation/mod.rs | 1 - src/router/cdn/operation/mod.rs | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/persistence/models/mongo-models/src/ceobe/operation/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/mod.rs index fc08bb57..cbe05be4 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/mod.rs @@ -1,3 +1,3 @@ pub mod plugin_version; -pub mod version; pub mod tool_link; +pub mod version; diff --git a/persistence/persistence/src/lib.rs b/persistence/persistence/src/lib.rs index 194397c6..ff9e8b1f 100644 --- a/persistence/persistence/src/lib.rs +++ b/persistence/persistence/src/lib.rs @@ -25,7 +25,7 @@ pub mod ceobe_operate { pub use dao_ceobe_operate::*; pub mod models { - pub use mongo_models::ceobe::operation::{plugin_version,version}; + pub use mongo_models::ceobe::operation::{plugin_version, version}; pub use sql_models::ceobe_operation::*; } diff --git a/src/router/back_end/ceobe_operation/mod.rs b/src/router/back_end/ceobe_operation/mod.rs index 8bf1f3f6..9ab7325b 100644 --- a/src/router/back_end/ceobe_operation/mod.rs +++ b/src/router/back_end/ceobe_operation/mod.rs @@ -33,7 +33,6 @@ pub(super) fn ceobe_operation_router() -> crate::router::ServerRoute { .nest("/toolLink", tool_link_router()) .nest_controller(ReleaseVersionController, AdminEnd) .route_layer(AuthorizeLayer::::new()) - } new_auth_level! { diff --git a/src/router/cdn/operation/mod.rs b/src/router/cdn/operation/mod.rs index 23d6cd63..6aaf3cf5 100644 --- a/src/router/cdn/operation/mod.rs +++ b/src/router/cdn/operation/mod.rs @@ -2,8 +2,8 @@ pub use announcement::CdnOperationAnnouncementFrontend; use axum::Router; use release_version_service::ReleaseVersionController; pub use resource::CdnOperationResourceFrontend; -pub use tool_link::CdnOperateToolLinkFrontend; use serve_utils::{endpoint::CDN, ControllerRouterExt}; +pub use tool_link::CdnOperateToolLinkFrontend; pub use video::CdnOperationVideoFrontend; use self::{ From da3f2ae459ae29233576e308505fc77adf71048c Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:18:50 +0800 Subject: [PATCH 35/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E8=85=BE?= =?UTF-8?q?=E8=AE=AF=E4=BA=91=E7=BC=93=E5=AD=98=E5=88=B7=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/Cargo.toml | 1 + .../release_version_service/src/error.rs | 3 +++ .../src/handlers/admin_end.rs | 16 ++++++++++++---- .../release_version_service/src/handlers/cdn.rs | 2 -- .../release_version_service/src/view.rs | 9 +++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/Cargo.toml b/http_service/ceobe_operation/release_version_service/Cargo.toml index 6bac114b..be81031d 100644 --- a/http_service/ceobe_operation/release_version_service/Cargo.toml +++ b/http_service/ceobe_operation/release_version_service/Cargo.toml @@ -14,3 +14,4 @@ http.workspace = true axum-resp-result.workspace = true tracing.workspace = true serde_json.workspace = true +tencent-cloud-server.workspace = true diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index 2284ac96..e0090ff4 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -4,6 +4,7 @@ use serve_utils::{ status_err::StatusErr, ControllerError, ThisError, }; +use tencent_cloud_server::error::TcCloudError; #[derive(Debug, ThisError, StatusErr)] #[status_err(resp_err)] @@ -14,6 +15,8 @@ pub enum Error { Query(#[from] QueryRejection), #[error(transparent)] Json(#[from] JsonRejection), + #[error(transparent)] + TencentCDN(#[from]TcCloudError) } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index 5ac4dd43..8519a689 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -11,17 +11,18 @@ use serve_utils::{ tracing::instrument, ValueField, }; +use tencent_cloud_server::cloud_manager::TencentCloudManager; use crate::{ handlers::{MapRejecter, Result}, - view::{QueryReleaseVersion, QueryVersionFilter}, + view::{QueryReleaseVersion, QueryVersionFilter, TencentCDNPath}, }; impl crate::ReleaseVersionController { #[resp_result] - #[instrument(skip_all,fields(version = %arg_1.0))] + #[instrument(skip_all,fields(version = %arg_2.0))] pub async fn yank_version( - db: MongoDatabaseOperate, + db: MongoDatabaseOperate, tencent_cloud: TencentCloudManager, MapReject(QueryReleaseVersion { version: ValueField(version), platform, @@ -35,6 +36,9 @@ impl crate::ReleaseVersionController { .delete() .yank(&platform, &version) .await?; + tencent_cloud + .purge_urls_cache(&Some(TencentCDNPath::LATEST_VERSION)) + .await?; Ok(()) } @@ -56,9 +60,10 @@ impl crate::ReleaseVersionController { } #[resp_result] - #[instrument(skip_all,fields(version = %(arg_1.0.version)))] + #[instrument(skip_all,fields(version = %(arg_2.0.version)))] pub async fn new_version( db: MongoDatabaseOperate, + tencent_cloud: TencentCloudManager, MapReject(release): MapRejecter>, ) -> Result<()> { db.ceobe() @@ -67,6 +72,9 @@ impl crate::ReleaseVersionController { .create() .one(release) .await?; + tencent_cloud + .purge_urls_cache(&Some(TencentCDNPath::LATEST_VERSION)) + .await?; Ok(()) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index 4ecc3bf2..d284f4d9 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -11,7 +11,6 @@ use serve_utils::{ tracing::instrument, OptionValueField, }; - use super::{MapRejecter, Result}; use crate::view::QueryReleaseVersion; impl crate::ReleaseVersionController { @@ -42,7 +41,6 @@ impl crate::ReleaseVersionController { .await? } }; - Ok(release_info) } } diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 06c417f9..08b73409 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -4,6 +4,7 @@ use persistence::ceobe_operate::models::version::models::ReleasePlatform; use semver::Version; use serde::Deserialize; use serve_utils::{OptionValueField, OptionViewField, ValueField}; +use tencent_cloud_server::cdn::purge_urls_cache::{PurgeCachePath, PurgeUrlsCache}; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< @@ -52,6 +53,14 @@ impl Display for QueryVersionFilter { } } +pub struct TencentCDNPath; + +impl TencentCDNPath{ + pub const LATEST_VERSION:PurgeCachePath = PurgeCachePath::new("/cdn/operate/version/fetch"); + + +} + #[cfg(test)] mod test { use serve_utils::SkipField; From 38b268fd27116c636884c7dc37805766ddc6c1ba Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:20:11 +0800 Subject: [PATCH 36/68] =?UTF-8?q?:fire:=20=E5=88=A0=E9=99=A4=E4=B8=8D?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E7=9A=84modify-state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/ceobe/operation/version/models/mod.rs | 1 - .../operation/version/models/modify_state.rs | 16 ---------------- 2 files changed, 17 deletions(-) delete mode 100644 persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs index 281d0439..9fc19a51 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/mod.rs @@ -1,7 +1,6 @@ mod conv; mod download_source; mod force; -mod modify_state; mod platform; mod primary; mod version; diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs deleted file mode 100644 index dbbd8f06..00000000 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/modify_state.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::borrow::Cow; - -use modify_cache::ModifyState; -use semver::Version; - -use crate::ceobe::operation::version::models::{ - ReleasePlatform, ReleaseVersion, -}; - -impl ModifyState for ReleaseVersion { - type Identify = (Version, ReleasePlatform); - - fn get_identify(&self) -> Cow<'_, Self::Identify> { - Cow::Owned((self.version.clone(), self.platform)) - } -} From ec2330ad4bcc5b6867da7abc1c06041370ce4d8f Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:21:48 +0800 Subject: [PATCH 37/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8ZIP=E5=AE=89=E8=A3=85=E7=9A=84=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mongo-models/src/ceobe/operation/version/models/platform.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs index b90d7b67..1815eed4 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/platform.rs @@ -49,6 +49,8 @@ pub enum SupportPlatform { Safari, /// 微软的Internet Explorer 浏览器 IE, + /// 其他使用ZIP安装的浏览器 + BrowserZIP, // pocket Android, Ios, From d03a276a93142d229cedb7fa0a12ea5bc832b4f0 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:32:33 +0800 Subject: [PATCH 38/68] =?UTF-8?q?:recycle:=20=E5=B0=86=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84=E5=AE=9E=E7=8E=B0=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0`verify`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/mongo/release_version/create.rs | 26 ++-------- .../src/mongo/release_version/mod.rs | 1 + .../src/mongo/release_version/verify.rs | 48 +++++++++++++++++++ 3 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs index 6e216173..87017716 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -6,7 +6,7 @@ use db_ops_prelude::{ }, }; use serde::{Deserialize, Serialize}; - +use crate::release_version::verify::suitable_version; use super::{ models::{ReleaseVersion, Version}, Error, ReleaseVersionCreate, Result, @@ -19,33 +19,13 @@ where pub async fn one( &'db self, release_version: impl Into, ) -> Result<()> { - #[derive(Debug, Deserialize, Serialize)] - struct VersionOnly { - version: Version, - } + let release_version = release_version.into(); let collection = self.get_collection()?; // 找到当前平台的最新的发布版本,与当前添加版本比较。新版本必须更新 - let filter = doc! {"platform":to_bson(&release_version.platform)?}; - let exist_latest_version = collection - .with_mapping::() - .doing(|collection| { - collection.find_one( - filter, - FindOneOptions::builder() - .sort(doc! {"$natural": -1i32}) - .projection(doc! {"version":1i32}) - .build(), - ) - }) - .await?; - if let Some(VersionOnly { version }) = exist_latest_version { - if release_version.version <= version { - Err(Error::VersionTooOld(version, release_version.platform))?; - } - } + suitable_version(&collection,&release_version).await?; collection .doing(|collection| collection.insert_one(release_version, None)) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs index aa142084..012f4bd8 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -1,6 +1,7 @@ mod create; mod delete; mod retrieve; +mod verify; use db_ops_prelude::{ mongo_connection::{database_traits::dao_operator, MongoDbError}, diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs new file mode 100644 index 00000000..e182919b --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs @@ -0,0 +1,48 @@ +use db_ops_prelude::{ + mongo_connection::CollectionGuard, + mongo_models::ceobe::operation::version::models::{ + ReleaseVersion, Version, + }, + mongodb::{ + bson::{doc, to_bson}, + options::FindOneOptions, + }, +}; +use serde::{Deserialize, Serialize}; + +use super::{Error,Result}; +pub(super) async fn suitable_version( + collection: &CollectionGuard, + release_version: &ReleaseVersion, +) -> Result<()> { + #[derive(Debug, Deserialize, Serialize)] + struct VersionOnly { + version: Version, + } + + // 找到当前平台的最新的发布版本,与当前添加版本比较。新版本必须更新 + let filter = doc! { + "platform":to_bson(&release_version.platform)? + }; + let exist_latest_version = collection + .with_mapping::() + .doing(|collection| { + collection.find_one( + filter, + FindOneOptions::builder() + .sort(doc! {"$natural": -1i32}) + .projection(doc! {"version":1i32}) + .build(), + ) + }) + .await?; + + match exist_latest_version { + Some(VersionOnly { version }) + if release_version.version <= version => + { + Err(Error::VersionTooOld(version, release_version.platform)) + } + _ => Ok(()), + } +} From 5932412cfd3d9d054fde4c875a541a7f40af3056 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:39:17 +0800 Subject: [PATCH 39/68] =?UTF-8?q?:pencil2:=20=E8=B0=83=E6=95=B4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=BD=AC=E6=8D=A2=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mongo-models/src/ceobe/operation/version/models/conv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs index 2e70d6ed..08b245f0 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/conv.rs @@ -67,13 +67,13 @@ impl From for ReleaseVersion { ) .add_download_source( DownloadSourceItem::builder() - .name("ZIP") + .name("ZIP 包下载") .primary_url( ResourceUrl::builder().name(Primary).url(zip).build(), ) .extend_spare_url(spare_zip.map(|url| { ResourceUrl::builder() - .name("Zip备用") + .name("ZIP备用") .url(url) .manual() .build() From d902d8846e35bd899c21b55405991ba23b6ca895 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:45:04 +0800 Subject: [PATCH 40/68] :art: cargo clippy + cargo fmt --- .../release_version_service/src/error.rs | 2 +- .../release_version_service/src/handlers.rs | 11 +++++++++-- .../src/handlers/admin_end.rs | 3 +-- .../release_version_service/src/handlers/cdn.rs | 1 + .../release_version_service/src/view.rs | 9 ++++----- .../tencent-cloud-server/src/axum_starter.rs | 1 + .../src/mongo/release_version/create.rs | 17 ++++------------- .../src/mongo/release_version/verify.rs | 2 +- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index e0090ff4..afbc0ce5 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -16,7 +16,7 @@ pub enum Error { #[error(transparent)] Json(#[from] JsonRejection), #[error(transparent)] - TencentCDN(#[from]TcCloudError) + TencentCDN(#[from] TcCloudError), } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 918b5da7..1bed796e 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -1,3 +1,4 @@ +use persistence::operate::FromRef; use serve_utils::{ axum::{ routing::{get, post}, @@ -6,6 +7,9 @@ use serve_utils::{ endpoint::{AdminEnd, CDN}, ControllerRouter, HandlerMapReject, HandlerResult, }; +use tencent_cloud_server::axum_starter::{ + PartTencentCloudManagerState, RequestClient, +}; mod admin_end; mod cdn; @@ -24,8 +28,11 @@ impl ControllerRouter } } -impl ControllerRouter - for crate::ReleaseVersionController +impl ControllerRouter for crate::ReleaseVersionController +where + S: Send + Clone + Sync + 'static, + PartTencentCloudManagerState: FromRef, + RequestClient: FromRef, { const BASE_URI: &'static str = "/release_version"; diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index 8519a689..c4346c16 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -62,8 +62,7 @@ impl crate::ReleaseVersionController { #[resp_result] #[instrument(skip_all,fields(version = %(arg_2.0.version)))] pub async fn new_version( - db: MongoDatabaseOperate, - tencent_cloud: TencentCloudManager, + db: MongoDatabaseOperate, tencent_cloud: TencentCloudManager, MapReject(release): MapRejecter>, ) -> Result<()> { db.ceobe() diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index d284f4d9..e57b6105 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -11,6 +11,7 @@ use serve_utils::{ tracing::instrument, OptionValueField, }; + use super::{MapRejecter, Result}; use crate::view::QueryReleaseVersion; impl crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 08b73409..233afda3 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -4,7 +4,7 @@ use persistence::ceobe_operate::models::version::models::ReleasePlatform; use semver::Version; use serde::Deserialize; use serve_utils::{OptionValueField, OptionViewField, ValueField}; -use tencent_cloud_server::cdn::purge_urls_cache::{PurgeCachePath, PurgeUrlsCache}; +use tencent_cloud_server::cdn::purge_urls_cache::PurgeCachePath; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< @@ -55,10 +55,9 @@ impl Display for QueryVersionFilter { pub struct TencentCDNPath; -impl TencentCDNPath{ - pub const LATEST_VERSION:PurgeCachePath = PurgeCachePath::new("/cdn/operate/version/fetch"); - - +impl TencentCDNPath { + pub const LATEST_VERSION: PurgeCachePath = + PurgeCachePath::new("/cdn/operate/version/fetch"); } #[cfg(test)] diff --git a/middle-server/tencent-cloud-server/src/axum_starter.rs b/middle-server/tencent-cloud-server/src/axum_starter.rs index 9075763c..4e87756e 100644 --- a/middle-server/tencent-cloud-server/src/axum_starter.rs +++ b/middle-server/tencent-cloud-server/src/axum_starter.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use axum_starter::{prepare, state::AddState}; +pub use general_request_client::client::RequestClient; use secrecy::SecretString; pub use crate::cloud_manager::PartTencentCloudManagerState; diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs index 87017716..044bc20f 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -1,16 +1,8 @@ -use db_ops_prelude::{ - mongo_connection::MongoDbCollectionTrait, - mongodb::{ - bson::{doc, to_bson}, - options::FindOneOptions, - }, -}; +use db_ops_prelude::mongo_connection::MongoDbCollectionTrait; use serde::{Deserialize, Serialize}; + +use super::{models::ReleaseVersion, ReleaseVersionCreate, Result}; use crate::release_version::verify::suitable_version; -use super::{ - models::{ReleaseVersion, Version}, - Error, ReleaseVersionCreate, Result, -}; impl<'db, Conn> ReleaseVersionCreate<'db, Conn> where @@ -19,13 +11,12 @@ where pub async fn one( &'db self, release_version: impl Into, ) -> Result<()> { - let release_version = release_version.into(); let collection = self.get_collection()?; // 找到当前平台的最新的发布版本,与当前添加版本比较。新版本必须更新 - suitable_version(&collection,&release_version).await?; + suitable_version(&collection, &release_version).await?; collection .doing(|collection| collection.insert_one(release_version, None)) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs index e182919b..15271705 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs @@ -10,7 +10,7 @@ use db_ops_prelude::{ }; use serde::{Deserialize, Serialize}; -use super::{Error,Result}; +use super::{Error, Result}; pub(super) async fn suitable_version( collection: &CollectionGuard, release_version: &ReleaseVersion, From 52b0b995aea1d8dcdc8bd5625c003f3070fe1b49 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Sun, 25 Aug 2024 16:51:49 +0800 Subject: [PATCH 41/68] :art: cargo clippy + cargo fmt --- .../dao/ceobe-operate/src/mongo/release_version/create.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs index 044bc20f..323f04b7 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/create.rs @@ -1,5 +1,4 @@ use db_ops_prelude::mongo_connection::MongoDbCollectionTrait; -use serde::{Deserialize, Serialize}; use super::{models::ReleaseVersion, ReleaseVersionCreate, Result}; use crate::release_version::verify::suitable_version; From b1e7e35fa6882851544a56837d179eda6354b98e Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 4 Sep 2024 16:13:38 +0800 Subject: [PATCH 42/68] =?UTF-8?q?:recycle:=20=E4=B8=BA`CheckExtract`=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20`ToInner`=20=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E8=83=BD=E5=A4=9F=E7=94=A8=E4=BA=8E`MapReject`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/checker/Cargo.toml | 2 +- libs/checker/src/check_prehandle.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/checker/Cargo.toml b/libs/checker/Cargo.toml index c9ff935d..7ee09319 100644 --- a/libs/checker/Cargo.toml +++ b/libs/checker/Cargo.toml @@ -14,7 +14,7 @@ check-obj-macro = { path = "../../macros/check-obj-macro" } num-traits = "0.2" async-trait = { workspace = true } axum = { workspace = true } -axum-resp-result = { workspace = true } +axum-resp-result.workspace = true serde_json = { workspace = true } thiserror = { workspace = true } smallvec = { workspace = true } diff --git a/libs/checker/src/check_prehandle.rs b/libs/checker/src/check_prehandle.rs index b62aeb35..fcecacbe 100644 --- a/libs/checker/src/check_prehandle.rs +++ b/libs/checker/src/check_prehandle.rs @@ -112,6 +112,16 @@ where type Checker = C; } +impl ToInner for CheckExtract +where + C: CheckFetchFamily + Sized, + ::Unchecked: Send, +{ + type Inner = ::Checked; + + fn to_inner(self) -> Self::Inner { self.0 } +} + pub type JsonCheckExtract = CheckExtract::Unchecked>, C, E>; From 489aafa5a4ecab86be57738d749aaa331f26f7e6 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 4 Sep 2024 16:15:20 +0800 Subject: [PATCH 43/68] =?UTF-8?q?:sparkles:=20=E4=B8=BA`release=5Fversion?= =?UTF-8?q?=5Fservice`=20=E6=8F=90=E4=BE=9B=E7=9A=84`AdminEnd`=20=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=E5=8F=AF=E9=80=89=E7=9A=84?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=94=AF=E6=8C=81=E4=B8=8E=E6=80=BB=E9=87=8F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/Cargo.toml | 2 + .../release_version_service/src/handlers.rs | 1 + .../src/handlers/admin_end.rs | 30 ++++++++- .../src/mongo/release_version/retrieve.rs | 64 ++++++++++++++----- 4 files changed, 77 insertions(+), 20 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/Cargo.toml b/http_service/ceobe_operation/release_version_service/Cargo.toml index be81031d..a3291c33 100644 --- a/http_service/ceobe_operation/release_version_service/Cargo.toml +++ b/http_service/ceobe_operation/release_version_service/Cargo.toml @@ -15,3 +15,5 @@ axum-resp-result.workspace = true tracing.workspace = true serde_json.workspace = true tencent-cloud-server.workspace = true +checker = { version = "0.1.0", path = "../../../libs/checker" } +page_size.workspace = true diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 1bed796e..e88aeba4 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -41,5 +41,6 @@ where .route("/yank", post(Self::yank_version)) .route("/create", post(Self::new_version)) .route("/all", get(Self::all_version)) + .route("/total_num",get(Self::released_version_num)) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index c4346c16..c11b4d3a 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -1,3 +1,5 @@ +use checker::{prefabs::option_checker::OptionChecker, QueryCheckExtract}; +use page_size::request::PageSizeChecker; use persistence::{ ceobe_operate::{ models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, @@ -7,13 +9,14 @@ use persistence::{ }; use serve_utils::{ axum::{extract::Query, Json}, - axum_resp_result::{resp_result, MapReject}, + axum_resp_result::{MapReject, resp_result}, tracing::instrument, ValueField, }; use tencent_cloud_server::cloud_manager::TencentCloudManager; use crate::{ + error::Error, handlers::{MapRejecter, Result}, view::{QueryReleaseVersion, QueryVersionFilter, TencentCDNPath}, }; @@ -46,7 +49,10 @@ impl crate::ReleaseVersionController { #[instrument(skip_all)] pub async fn all_version( db: MongoDatabaseOperate, - MapReject(filter): MapRejecter>>, + MapReject(paginator): MapRejecter< + QueryCheckExtract, Error>, + >, + MapReject(filter): MapRejecter>>, ) -> Result> { let filter = filter.unwrap_or_default(); let ret = db @@ -54,7 +60,25 @@ impl crate::ReleaseVersionController { .operation() .release_version() .retrieve() - .all(filter.platform, filter.yanked) + .all(filter.platform, paginator, filter.yanked) + .await?; + + Ok(ret) + } + + #[resp_result] + #[instrument(skip_all)] + pub async fn released_version_num( + db: MongoDatabaseOperate, + MapReject(filter): MapRejecter>>, + ) -> Result { + let filter = filter.unwrap_or_default(); + let ret = db + .ceobe() + .operation() + .release_version() + .retrieve() + .total_num(filter.platform, filter.yanked) .await?; Ok(ret) } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index 7207ac8b..b46f8316 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -3,10 +3,11 @@ use db_ops_prelude::{ mongo_connection::{MongoDbCollectionTrait, MongoDbError}, mongo_models::ceobe::operation::version::models::ReleasePlatform, mongodb::{ - bson::{doc, to_bson}, + bson::{doc, to_bson, Document}, options::{FindOneOptions, FindOptions}, }, }; +use page_size::request::Paginator; use tracing::info; use super::{ @@ -68,29 +69,29 @@ where } pub async fn all( - &'db self, platform: Option, yanked: bool, + &'db self, platform: Option, + paginate: impl Into>, yanked: bool, ) -> Result> { let collection = self.get_collection()?; - let filter = match platform { - None => { - doc! {"yanked": yanked} - } - Some(plat) => { - doc! { - "platform":to_bson(&plat)?, - "yanked": yanked - } - } - }; + let filter = generate_platform_filter_document(platform, yanked)?; let sort = doc! { "$natural": -1i32 }; + let options = FindOptions::builder().sort(sort); + + let options = if let Some(paginator) = paginate.into() { + options + .limit((paginator.limit() as i64).into()) + .skip(paginator.offset() as _) + .build() + } + else { + options.build() + }; + let ret = collection - .doing(|collection| { - collection - .find(filter, FindOptions::builder().sort(sort).build()) - }) + .doing(|collection| collection.find(filter, options)) .await? .try_collect() .await @@ -98,6 +99,35 @@ where Ok(ret) } + + pub async fn total_num( + &'db self, platform: Option, yanked: bool, + ) -> Result { + let collection = self.get_collection()?; + let filter = generate_platform_filter_document(platform, yanked)?; + + let ret = collection + .doing(|collection| collection.count_documents(filter, None)) + .await?; + + Ok(ret as _) + } +} + +fn generate_platform_filter_document( + platform: Option, yanked: bool, +) -> Result { + Ok(match platform { + None => { + doc! {"yanked": yanked} + } + Some(plat) => { + doc! { + "platform":to_bson(&plat)?, + "yanked": yanked + } + } + }) } #[cfg(test)] From 33eb780b313fa960145cb10fc6aa48a22399d9d2 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 4 Sep 2024 16:27:05 +0800 Subject: [PATCH 44/68] =?UTF-8?q?:rotating=5Flight:=20=E4=BF=AE=E5=A4=8Dch?= =?UTF-8?q?ecker=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ceobe_operation/release_version_service/src/error.rs | 3 +++ .../release_version_service/src/handlers/admin_end.rs | 6 +++--- libs/checker/src/check_prehandle.rs | 1 - .../dao/ceobe-operate/src/mongo/release_version/retrieve.rs | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index afbc0ce5..181d742b 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -1,3 +1,4 @@ +use checker::prefabs::num_check::NonZeroUnsignedError; use persistence::ceobe_operate::release_version::Error as MongoError; use serve_utils::{ axum::extract::rejection::{JsonRejection, QueryRejection}, @@ -17,6 +18,8 @@ pub enum Error { Json(#[from] JsonRejection), #[error(transparent)] TencentCDN(#[from] TcCloudError), + #[error(transparent)] + InvalidPaginator(#[from]NonZeroUnsignedError) } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index c11b4d3a..aa33463e 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -1,4 +1,4 @@ -use checker::{prefabs::option_checker::OptionChecker, QueryCheckExtract}; +use checker::{CheckExtract, prefabs::option_checker::OptionChecker, QueryCheckExtract}; use page_size::request::PageSizeChecker; use persistence::{ ceobe_operate::{ @@ -49,9 +49,9 @@ impl crate::ReleaseVersionController { #[instrument(skip_all)] pub async fn all_version( db: MongoDatabaseOperate, - MapReject(paginator): MapRejecter< + CheckExtract(paginator): QueryCheckExtract, Error>, - >, + MapReject(filter): MapRejecter>>, ) -> Result> { let filter = filter.unwrap_or_default(); diff --git a/libs/checker/src/check_prehandle.rs b/libs/checker/src/check_prehandle.rs index fcecacbe..028edbeb 100644 --- a/libs/checker/src/check_prehandle.rs +++ b/libs/checker/src/check_prehandle.rs @@ -115,7 +115,6 @@ where impl ToInner for CheckExtract where C: CheckFetchFamily + Sized, - ::Unchecked: Send, { type Inner = ::Checked; diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index b46f8316..2dfc910a 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -82,8 +82,8 @@ where let options = if let Some(paginator) = paginate.into() { options - .limit((paginator.limit() as i64).into()) - .skip(paginator.offset() as _) + .limit(Some(paginator.limit() as i64)) + .skip(paginator.offset()) .build() } else { From b90fa9ce72201b320f1e86baeb160be597748546 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 4 Sep 2024 16:27:36 +0800 Subject: [PATCH 45/68] :art: cargo fmt --- .../release_version_service/src/error.rs | 2 +- .../release_version_service/src/handlers.rs | 2 +- .../src/handlers/admin_end.rs | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index 181d742b..1b9efe01 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -19,7 +19,7 @@ pub enum Error { #[error(transparent)] TencentCDN(#[from] TcCloudError), #[error(transparent)] - InvalidPaginator(#[from]NonZeroUnsignedError) + InvalidPaginator(#[from] NonZeroUnsignedError), } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index e88aeba4..a3a93425 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -41,6 +41,6 @@ where .route("/yank", post(Self::yank_version)) .route("/create", post(Self::new_version)) .route("/all", get(Self::all_version)) - .route("/total_num",get(Self::released_version_num)) + .route("/total_num", get(Self::released_version_num)) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index aa33463e..03985670 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -1,4 +1,6 @@ -use checker::{CheckExtract, prefabs::option_checker::OptionChecker, QueryCheckExtract}; +use checker::{ + prefabs::option_checker::OptionChecker, CheckExtract, QueryCheckExtract, +}; use page_size::request::PageSizeChecker; use persistence::{ ceobe_operate::{ @@ -9,7 +11,7 @@ use persistence::{ }; use serve_utils::{ axum::{extract::Query, Json}, - axum_resp_result::{MapReject, resp_result}, + axum_resp_result::{resp_result, MapReject}, tracing::instrument, ValueField, }; @@ -49,9 +51,10 @@ impl crate::ReleaseVersionController { #[instrument(skip_all)] pub async fn all_version( db: MongoDatabaseOperate, - CheckExtract(paginator): - QueryCheckExtract, Error>, - + CheckExtract(paginator): QueryCheckExtract< + OptionChecker, + Error, + >, MapReject(filter): MapRejecter>>, ) -> Result> { let filter = filter.unwrap_or_default(); From 42fb01b72ca542245d371e758f02977f0bca3db8 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 4 Sep 2024 16:31:35 +0800 Subject: [PATCH 46/68] :art: cargo fmt --- src/serves/cdn/ceobe/operation/tool_link/error.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/serves/cdn/ceobe/operation/tool_link/error.rs b/src/serves/cdn/ceobe/operation/tool_link/error.rs index 5f7da1cf..858f868c 100644 --- a/src/serves/cdn/ceobe/operation/tool_link/error.rs +++ b/src/serves/cdn/ceobe/operation/tool_link/error.rs @@ -4,7 +4,6 @@ use ceobe_operation_logic::error::LogicError; use checker::prefabs::num_check::NonZeroUnsignedError; use persistence::ceobe_operate::tool_link_mongodb::OperateError; - use crate::error_generate; error_generate! { From dda6d19b37de17ca0a40964806d985c09cb412ec Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 09:50:35 +0800 Subject: [PATCH 47/68] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=89=88=E6=9C=AC=E7=9A=84Logic=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/view.rs | 5 - libs/page_size/src/response/mod.rs | 6 ++ logic/ceobe_operation_logic/Cargo.toml | 4 +- logic/ceobe_operation_logic/src/lib.rs | 36 +++++++ .../src/release_version/error.rs | 19 ++++ .../src/release_version/implement.rs | 102 ++++++++++++++++++ .../src/release_version/mod.rs | 47 ++++++++ .../src/release_version/view.rs | 8 ++ 8 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 logic/ceobe_operation_logic/src/release_version/error.rs create mode 100644 logic/ceobe_operation_logic/src/release_version/implement.rs create mode 100644 logic/ceobe_operation_logic/src/release_version/mod.rs create mode 100644 logic/ceobe_operation_logic/src/release_version/view.rs diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 233afda3..10836b57 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -53,12 +53,7 @@ impl Display for QueryVersionFilter { } } -pub struct TencentCDNPath; -impl TencentCDNPath { - pub const LATEST_VERSION: PurgeCachePath = - PurgeCachePath::new("/cdn/operate/version/fetch"); -} #[cfg(test)] mod test { diff --git a/libs/page_size/src/response/mod.rs b/libs/page_size/src/response/mod.rs index 695fc0bf..5d025c6f 100644 --- a/libs/page_size/src/response/mod.rs +++ b/libs/page_size/src/response/mod.rs @@ -29,6 +29,8 @@ where fn with_page_info( self, page_size: Paginator, count: u64, ) -> ListWithPageInfo; + + fn with_plain(self)->ListWithPageInfo; } impl GenerateListWithPageInfo for T @@ -50,4 +52,8 @@ where }, } } + + fn with_plain(self)->ListWithPageInfo{ + todo!() + } } diff --git a/logic/ceobe_operation_logic/Cargo.toml b/logic/ceobe_operation_logic/Cargo.toml index a5db4d58..41ff9d32 100644 --- a/logic/ceobe_operation_logic/Cargo.toml +++ b/logic/ceobe_operation_logic/Cargo.toml @@ -19,6 +19,8 @@ request-clients.workspace = true reqwest.workspace = true tencent-cloud-server.workspace = true serde_qs.workspace = true +semver = "1.0.23" +db-ops-prelude.workspace = true [dependencies.checker] -path = "../../libs/checker" \ No newline at end of file +path = "../../libs/checker" diff --git a/logic/ceobe_operation_logic/src/lib.rs b/logic/ceobe_operation_logic/src/lib.rs index 10a3001a..85d465da 100644 --- a/logic/ceobe_operation_logic/src/lib.rs +++ b/logic/ceobe_operation_logic/src/lib.rs @@ -1,3 +1,39 @@ +use std::ops::{Deref, DerefMut}; + +use db_ops_prelude::sea_orm::prelude::async_trait::async_trait; +use persistence::operate::{FromRequestParts, Parts}; + pub mod error; pub mod impletements; pub mod view; +pub mod release_version; + + +pub struct CeobeOperationLogic(T); + +#[async_trait] +impl FromRequestParts for CeobeOperationLogic +where T:FromRequestParts, +S:Send+Sync+'static+Clone +{ + type Rejection = >::Rejection; + +async fn from_request_parts(parts: & mut Parts,state: & S) -> Result { + Ok(Self(>::from_request_parts(parts, state).await?)) + + } +} + +impl DerefMut for CeobeOperationLogic { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl Deref for CeobeOperationLogic { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} \ No newline at end of file diff --git a/logic/ceobe_operation_logic/src/release_version/error.rs b/logic/ceobe_operation_logic/src/release_version/error.rs new file mode 100644 index 00000000..e82167e3 --- /dev/null +++ b/logic/ceobe_operation_logic/src/release_version/error.rs @@ -0,0 +1,19 @@ +use std::convert::Infallible; + +use persistence::ceobe_operate::release_version; +use tencent_cloud_server::error::TcCloudError; + + + +pub(super)type Rejection = Infallible; + + +#[derive(Debug,thiserror::Error,status_err::StatusErr)] +pub enum Error { + #[error(transparent)] + Dao(#[from]release_version::Error), + #[error(transparent)] + Tencent(#[from]TcCloudError) +} + +pub(super) type LogicResult = core::result::Result; \ No newline at end of file diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs new file mode 100644 index 00000000..d7c389c2 --- /dev/null +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -0,0 +1,102 @@ +use db_ops_prelude::database_operates::operate_trait::OperateTrait; +use page_size::{request::Paginator, response::{GenerateListWithPageInfo, ListWithPageInfo}}; +use persistence::{ + ceobe_operate::{ + models::version::models::{ReleasePlatform, ReleaseVersion}, + ToCeobeOperation, + }, + ceobe_user::ToCeobe, +}; +use semver::Version; + +use super::{LogicResult, ReleaseVersionLogic, TencentCDNPath}; + +impl ReleaseVersionLogic { + pub async fn yank( + &self, version: &Version, platform: &ReleasePlatform, + ) -> LogicResult<()> { + self.mongodb + .ceobe() + .operation() + .release_version() + .delete() + .yank(platform, version) + .await?; + + self.tencent_cloud + .purge_urls_cache(&Some(TencentCDNPath::LATEST_VERSION)) + .await?; + + Ok(()) + } + + pub async fn all( + &self, paginator: Option, + platform: Option, yanked: bool, + ) -> LogicResult> { + let msg = self + .mongodb + .ceobe() + .operation() + .release_version() + .retrieve() + .all(platform, paginator, yanked) + .await?; + + match paginator { + Some(paginator) => { + let total = self.count(platform, yanked).await?; + Ok(msg.with_page_info(paginator, total as _)) + }, + None => Ok(msg.with_plain()), + } + + } + + pub async fn count(&self,platform: Option,yanked: bool)->LogicResult{ + let count = self.mongodb + .ceobe() + .operation() + .release_version() + .retrieve() + .total_num(platform, yanked) + .await?; + Ok(count) + } + + pub async fn new(&self, release: ReleaseVersion) -> LogicResult<()> { + self.mongodb + .ceobe() + .operation() + .release_version() + .create() + .one(release) + .await?; + self.tencent_cloud + .purge_urls_cache(&Some(TencentCDNPath::LATEST_VERSION)) + .await?; + Ok(()) + } + + pub async fn fetch(&self, version: Option,platform: ReleasePlatform)->LogicResult{ + let release_info = match version { + None => { + self.mongodb.ceobe() + .operation() + .release_version() + .retrieve() + .latest_by_platform(platform) + .await? + } + Some(ver) => { + self.mongodb.ceobe() + .operation() + .release_version() + .retrieve() + .by_version_platform(&ver, platform) + .await? + } + }; + Ok(release_info) + } +} diff --git a/logic/ceobe_operation_logic/src/release_version/mod.rs b/logic/ceobe_operation_logic/src/release_version/mod.rs new file mode 100644 index 00000000..a6a62ba4 --- /dev/null +++ b/logic/ceobe_operation_logic/src/release_version/mod.rs @@ -0,0 +1,47 @@ +use persistence::{ + mongodb::MongoDatabaseOperate, + mysql::sea_orm::prelude::async_trait::async_trait, + operate::{FromRef, FromRequestParts, Parts}, +}; +use tencent_cloud_server::{ + axum_starter::{PartTencentCloudManagerState, RequestClient}, + cloud_manager::TencentCloudManager, +}; + +pub struct ReleaseVersionLogic { + pub mongodb: MongoDatabaseOperate, + pub tencent_cloud: TencentCloudManager, +} + +#[async_trait] +impl FromRequestParts for ReleaseVersionLogic +where + S: Send + Sync + 'static, + RequestClient: FromRef, + PartTencentCloudManagerState: FromRef, +{ + type Rejection = Rejection; + + async fn from_request_parts( + parts: &mut Parts, state: &S, + ) -> Result { + let mongodb = >::from_request_parts(parts, state).await?; + let tencent_cloud = + >::from_request_parts( + parts, state, + ) + .await?; + Ok(Self { + mongodb, + tencent_cloud, + }) + } +} + +mod error; +mod implement; +pub mod view; + +use self::error::{Rejection,LogicResult}; +use self::view::*; +pub use self::error::Error; diff --git a/logic/ceobe_operation_logic/src/release_version/view.rs b/logic/ceobe_operation_logic/src/release_version/view.rs new file mode 100644 index 00000000..f857c68f --- /dev/null +++ b/logic/ceobe_operation_logic/src/release_version/view.rs @@ -0,0 +1,8 @@ +use tencent_cloud_server::cdn::purge_urls_cache::PurgeCachePath; + +pub struct TencentCDNPath; + +impl TencentCDNPath { + pub const LATEST_VERSION: PurgeCachePath = + PurgeCachePath::new("/cdn/operate/version/fetch"); +} \ No newline at end of file From 7b1620dd1c267d6dae3cbcaddc6ba84274e7a6ea Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 10:07:07 +0800 Subject: [PATCH 48/68] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E5=B0=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B1=82=E6=B7=BB=E5=8A=A0=E5=88=B0http-serve?= =?UTF-8?q?=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/Cargo.toml | 1 + .../release_version_service/src/error.rs | 6 +- .../release_version_service/src/handlers.rs | 8 ++- .../src/handlers/admin_end.rs | 62 ++++++------------- .../src/handlers/cdn.rs | 25 ++------ 5 files changed, 34 insertions(+), 68 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/Cargo.toml b/http_service/ceobe_operation/release_version_service/Cargo.toml index a3291c33..b35827cd 100644 --- a/http_service/ceobe_operation/release_version_service/Cargo.toml +++ b/http_service/ceobe_operation/release_version_service/Cargo.toml @@ -17,3 +17,4 @@ serde_json.workspace = true tencent-cloud-server.workspace = true checker = { version = "0.1.0", path = "../../../libs/checker" } page_size.workspace = true +ceobe_operation_logic = { version = "0.1.0", path = "../../../logic/ceobe_operation_logic" } diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index 1b9efe01..d275c766 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -10,16 +10,14 @@ use tencent_cloud_server::error::TcCloudError; #[derive(Debug, ThisError, StatusErr)] #[status_err(resp_err)] pub enum Error { - #[error(transparent)] - Mongo(#[from] MongoError), #[error(transparent)] Query(#[from] QueryRejection), #[error(transparent)] Json(#[from] JsonRejection), #[error(transparent)] - TencentCDN(#[from] TcCloudError), - #[error(transparent)] InvalidPaginator(#[from] NonZeroUnsignedError), + #[error(transparent)] + Logic(#[from]ceobe_operation_logic::release_version::Error) } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index a3a93425..ef06edf0 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -18,8 +18,12 @@ pub(crate) type Result = HandlerResult; pub(crate) type MapRejecter = HandlerMapReject; -impl ControllerRouter - for crate::ReleaseVersionController +impl ControllerRouterfor crate::ReleaseVersionController +where + S: Send + Clone + Sync + 'static, + PartTencentCloudManagerState: FromRef, + RequestClient: FromRef, + { const BASE_URI: &'static str = "/version"; diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index 03985670..adfe9a2e 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -1,7 +1,10 @@ +use ceobe_operation_logic::{ + release_version::ReleaseVersionLogic, CeobeOperationLogic, +}; use checker::{ prefabs::option_checker::OptionChecker, CheckExtract, QueryCheckExtract, }; -use page_size::request::PageSizeChecker; +use page_size::{request::PageSizeChecker, response::ListWithPageInfo}; use persistence::{ ceobe_operate::{ models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, @@ -20,14 +23,14 @@ use tencent_cloud_server::cloud_manager::TencentCloudManager; use crate::{ error::Error, handlers::{MapRejecter, Result}, - view::{QueryReleaseVersion, QueryVersionFilter, TencentCDNPath}, + view::{QueryReleaseVersion, QueryVersionFilter}, }; impl crate::ReleaseVersionController { #[resp_result] - #[instrument(skip_all,fields(version = %arg_2.0))] + #[instrument(skip_all,fields(version = %arg_1.0))] pub async fn yank_version( - db: MongoDatabaseOperate, tencent_cloud: TencentCloudManager, + logic: CeobeOperationLogic, MapReject(QueryReleaseVersion { version: ValueField(version), platform, @@ -35,36 +38,23 @@ impl crate::ReleaseVersionController { Query>>, >, ) -> Result<()> { - db.ceobe() - .operation() - .release_version() - .delete() - .yank(&platform, &version) - .await?; - tencent_cloud - .purge_urls_cache(&Some(TencentCDNPath::LATEST_VERSION)) - .await?; + logic.yank(&version, &platform).await?; Ok(()) } #[resp_result] #[instrument(skip_all)] pub async fn all_version( - db: MongoDatabaseOperate, + logic: CeobeOperationLogic, CheckExtract(paginator): QueryCheckExtract< OptionChecker, Error, >, MapReject(filter): MapRejecter>>, - ) -> Result> { - let filter = filter.unwrap_or_default(); - let ret = db - .ceobe() - .operation() - .release_version() - .retrieve() - .all(filter.platform, paginator, filter.yanked) - .await?; + ) -> Result> { + let QueryVersionFilter { platform, yanked } = + filter.unwrap_or_default(); + let ret = logic.all(paginator, platform, yanked).await?; Ok(ret) } @@ -72,35 +62,21 @@ impl crate::ReleaseVersionController { #[resp_result] #[instrument(skip_all)] pub async fn released_version_num( - db: MongoDatabaseOperate, + logic: CeobeOperationLogic, MapReject(filter): MapRejecter>>, ) -> Result { - let filter = filter.unwrap_or_default(); - let ret = db - .ceobe() - .operation() - .release_version() - .retrieve() - .total_num(filter.platform, filter.yanked) - .await?; + let QueryVersionFilter { platform, yanked } = filter.unwrap_or_default(); + let ret =logic.count(platform, yanked).await?; Ok(ret) } #[resp_result] - #[instrument(skip_all,fields(version = %(arg_2.0.version)))] + #[instrument(skip_all,fields(version = %(arg_1.0.version)))] pub async fn new_version( - db: MongoDatabaseOperate, tencent_cloud: TencentCloudManager, + logic: CeobeOperationLogic, MapReject(release): MapRejecter>, ) -> Result<()> { - db.ceobe() - .operation() - .release_version() - .create() - .one(release) - .await?; - tencent_cloud - .purge_urls_cache(&Some(TencentCDNPath::LATEST_VERSION)) - .await?; + logic.new(release).await?; Ok(()) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index e57b6105..6178b7d9 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -1,3 +1,6 @@ +use ceobe_operation_logic::{ + release_version::ReleaseVersionLogic, CeobeOperationLogic, +}; use persistence::{ ceobe_operate::{ models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, @@ -18,30 +21,14 @@ impl crate::ReleaseVersionController { #[resp_result] #[instrument(skip_all,fields(version = %arg_1.0))] pub async fn release_version( - db: MongoDatabaseOperate, + logic: CeobeOperationLogic, MapReject(QueryReleaseVersion { version: OptionValueField(version), platform, }): MapRejecter>, ) -> Result { - let release_info = match version { - None => { - db.ceobe() - .operation() - .release_version() - .retrieve() - .latest_by_platform(platform) - .await? - } - Some(ver) => { - db.ceobe() - .operation() - .release_version() - .retrieve() - .by_version_platform(&ver, platform) - .await? - } - }; + let release_info = logic.fetch(version, platform).await?; + Ok(release_info) } } From 45a1d5bee2c6ade04b5f8319059b230de733eeb4 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 10:23:54 +0800 Subject: [PATCH 49/68] =?UTF-8?q?=E2=9C=A8=20page=5Finfo=20=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E5=8F=AF=E4=BB=A5=E4=B8=8D=E6=90=BA=E5=B8=A6=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/page_size/src/response/mod.rs | 90 +++++++++++++++++++++++++++--- macros/check-obj-macro/Cargo.toml | 2 +- 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/libs/page_size/src/response/mod.rs b/libs/page_size/src/response/mod.rs index 5d025c6f..91ebeb68 100644 --- a/libs/page_size/src/response/mod.rs +++ b/libs/page_size/src/response/mod.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use serde::Serialize; +use serde::{ser::SerializeStruct, Serialize}; use crate::request::Paginator; @@ -13,13 +13,34 @@ pub struct PageInfo { } /// 列表与分页信息 -#[derive(Serialize, Debug)] +#[derive(Debug)] pub struct ListWithPageInfo where T: Serialize, { list: Vec, - page_size: PageInfo, + page_size: Option, +} + +impl Serialize for ListWithPageInfo +where + T: Serialize, +{ + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + match &self.page_size { + Some(page) => { + let mut struc = + serializer.serialize_struct("ListWithPageInfo", 2)?; + struc.serialize_field("list", &self.list)?; + struc.serialize_field("page_size", page)?; + struc.end() + } + None => as Serialize>::serialize(&self.list, serializer), + } + } } pub trait GenerateListWithPageInfo: IntoIterator @@ -30,7 +51,7 @@ where self, page_size: Paginator, count: u64, ) -> ListWithPageInfo; - fn with_plain(self)->ListWithPageInfo; + fn with_plain(self) -> ListWithPageInfo; } impl GenerateListWithPageInfo for T @@ -44,16 +65,69 @@ where ) -> ListWithPageInfo { ListWithPageInfo { list: self.into_iter().collect(), - page_size: PageInfo { + page_size: Some(PageInfo { page_size, total_count: count, total_page: (count as f64 / *page_size.size.deref() as f64) .ceil() as u64, - }, + }), + } + } + + fn with_plain(self) -> ListWithPageInfo { + ListWithPageInfo { + list: self.into_iter().collect(), + page_size: None, } } +} + +#[cfg(test)] +mod test { + use checker::{ + prefabs::num_check::NonZeroUnsignedChecker, + Checker, + }; + use serde_json::json; + + use crate::request::Paginator; + + use super::GenerateListWithPageInfo; + #[test] + fn test_serde_paginator() { + let a = Some("AAA"); + let page = a.with_page_info( + Paginator::builder() + .page( + NonZeroUnsignedChecker::check(Default::default(), 11) + .into_inner() + .unwrap(), + ) + .size( + NonZeroUnsignedChecker::check(Default::default(), 2) + .into_inner() + .unwrap(), + ) + .build(), + 25, + ); + + let value = serde_json::to_value(&page).unwrap(); + + assert_eq!(value,json!({ + "list":["AAA"], + "page_size":{ + + "page":11, + "size":2, + "total_count":25, + "total_page":13 + + } + })); - fn with_plain(self)->ListWithPageInfo{ - todo!() + let no_page = Some("AAA").with_plain(); + let value = serde_json::to_value(&no_page).unwrap(); + assert_eq!(value,json!(["AAA"])) } } diff --git a/macros/check-obj-macro/Cargo.toml b/macros/check-obj-macro/Cargo.toml index 9f0517de..fcf55326 100644 --- a/macros/check-obj-macro/Cargo.toml +++ b/macros/check-obj-macro/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1" +syn = {version="1",features=["full"]} quote = "1" typed-builder = { workspace = true } From b8a5a14650457d05e312509f8f72c1895c8fed10 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 10:34:16 +0800 Subject: [PATCH 50/68] =?UTF-8?q?=F0=9F=8E=A8=20cargo=20clippy=20&=20cargo?= =?UTF-8?q?=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/error.rs | 4 +- .../release_version_service/src/handlers.rs | 3 +- .../src/handlers/admin_end.rs | 16 +++---- .../src/handlers/cdn.rs | 8 +--- .../release_version_service/src/view.rs | 3 -- libs/page_size/src/response/mod.rs | 33 +++++++------- logic/ceobe_operation_logic/src/lib.rs | 30 ++++++------- .../src/release_version/error.rs | 13 +++--- .../src/release_version/implement.rs | 43 ++++++++++++------- .../src/release_version/mod.rs | 6 ++- .../src/release_version/view.rs | 2 +- macros/check-obj-macro/src/lib.rs | 13 +++--- macros/status-err-derive/src/lib.rs | 2 + middle-server/mob-push-server/src/lib.rs | 2 + .../src/push_notify/android/image.rs | 2 +- middle-server/qiniu-cdn-upload/src/lib.rs | 3 +- .../sql/datasource_combination/retrieve.rs | 2 +- .../mongo_connection/src/database/manager.rs | 8 ++-- .../src/ceobe/user_property/models/mod.rs | 2 +- .../models/model_datasource_config.rs | 1 + src/error/mod.rs | 4 +- 21 files changed, 97 insertions(+), 103 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/error.rs b/http_service/ceobe_operation/release_version_service/src/error.rs index d275c766..639bd0c1 100644 --- a/http_service/ceobe_operation/release_version_service/src/error.rs +++ b/http_service/ceobe_operation/release_version_service/src/error.rs @@ -1,11 +1,9 @@ use checker::prefabs::num_check::NonZeroUnsignedError; -use persistence::ceobe_operate::release_version::Error as MongoError; use serve_utils::{ axum::extract::rejection::{JsonRejection, QueryRejection}, status_err::StatusErr, ControllerError, ThisError, }; -use tencent_cloud_server::error::TcCloudError; #[derive(Debug, ThisError, StatusErr)] #[status_err(resp_err)] @@ -17,7 +15,7 @@ pub enum Error { #[error(transparent)] InvalidPaginator(#[from] NonZeroUnsignedError), #[error(transparent)] - Logic(#[from]ceobe_operation_logic::release_version::Error) + Logic(#[from] ceobe_operation_logic::release_version::Error), } impl ControllerError for crate::ReleaseVersionController { diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index ef06edf0..dbf736aa 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -18,12 +18,11 @@ pub(crate) type Result = HandlerResult; pub(crate) type MapRejecter = HandlerMapReject; -impl ControllerRouterfor crate::ReleaseVersionController +impl ControllerRouter for crate::ReleaseVersionController where S: Send + Clone + Sync + 'static, PartTencentCloudManagerState: FromRef, RequestClient: FromRef, - { const BASE_URI: &'static str = "/version"; diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index adfe9a2e..d3651f8e 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -5,20 +5,13 @@ use checker::{ prefabs::option_checker::OptionChecker, CheckExtract, QueryCheckExtract, }; use page_size::{request::PageSizeChecker, response::ListWithPageInfo}; -use persistence::{ - ceobe_operate::{ - models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, - }, - mongodb::MongoDatabaseOperate, - operate::operate_trait::OperateTrait, -}; +use persistence::ceobe_operate::models::version::models::ReleaseVersion; use serve_utils::{ axum::{extract::Query, Json}, axum_resp_result::{resp_result, MapReject}, tracing::instrument, ValueField, }; -use tencent_cloud_server::cloud_manager::TencentCloudManager; use crate::{ error::Error, @@ -65,8 +58,9 @@ impl crate::ReleaseVersionController { logic: CeobeOperationLogic, MapReject(filter): MapRejecter>>, ) -> Result { - let QueryVersionFilter { platform, yanked } = filter.unwrap_or_default(); - let ret =logic.count(platform, yanked).await?; + let QueryVersionFilter { platform, yanked } = + filter.unwrap_or_default(); + let ret = logic.count(platform, yanked).await?; Ok(ret) } @@ -76,7 +70,7 @@ impl crate::ReleaseVersionController { logic: CeobeOperationLogic, MapReject(release): MapRejecter>, ) -> Result<()> { - logic.new(release).await?; + logic.create_new(release).await?; Ok(()) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index 6178b7d9..92baa310 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -1,13 +1,7 @@ use ceobe_operation_logic::{ release_version::ReleaseVersionLogic, CeobeOperationLogic, }; -use persistence::{ - ceobe_operate::{ - models::version::models::ReleaseVersion, ToCeobe, ToCeobeOperation, - }, - mongodb::MongoDatabaseOperate, - operate::operate_trait::OperateTrait, -}; +use persistence::ceobe_operate::models::version::models::ReleaseVersion; use serve_utils::{ axum::extract::Query, axum_resp_result::{resp_result, MapReject}, diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 10836b57..06c417f9 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -4,7 +4,6 @@ use persistence::ceobe_operate::models::version::models::ReleasePlatform; use semver::Version; use serde::Deserialize; use serve_utils::{OptionValueField, OptionViewField, ValueField}; -use tencent_cloud_server::cdn::purge_urls_cache::PurgeCachePath; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< @@ -53,8 +52,6 @@ impl Display for QueryVersionFilter { } } - - #[cfg(test)] mod test { use serve_utils::SkipField; diff --git a/libs/page_size/src/response/mod.rs b/libs/page_size/src/response/mod.rs index 91ebeb68..de203e5d 100644 --- a/libs/page_size/src/response/mod.rs +++ b/libs/page_size/src/response/mod.rs @@ -84,15 +84,11 @@ where #[cfg(test)] mod test { - use checker::{ - prefabs::num_check::NonZeroUnsignedChecker, - Checker, - }; + use checker::{prefabs::num_check::NonZeroUnsignedChecker, Checker}; use serde_json::json; - use crate::request::Paginator; - use super::GenerateListWithPageInfo; + use crate::request::Paginator; #[test] fn test_serde_paginator() { let a = Some("AAA"); @@ -114,20 +110,23 @@ mod test { let value = serde_json::to_value(&page).unwrap(); - assert_eq!(value,json!({ - "list":["AAA"], - "page_size":{ - - "page":11, - "size":2, - "total_count":25, - "total_page":13 + assert_eq!( + value, + json!({ + "list":["AAA"], + "page_size":{ - } - })); + "page":11, + "size":2, + "total_count":25, + "total_page":13 + + } + }) + ); let no_page = Some("AAA").with_plain(); let value = serde_json::to_value(&no_page).unwrap(); - assert_eq!(value,json!(["AAA"])) + assert_eq!(value, json!(["AAA"])) } } diff --git a/logic/ceobe_operation_logic/src/lib.rs b/logic/ceobe_operation_logic/src/lib.rs index 85d465da..d2abe1de 100644 --- a/logic/ceobe_operation_logic/src/lib.rs +++ b/logic/ceobe_operation_logic/src/lib.rs @@ -5,35 +5,35 @@ use persistence::operate::{FromRequestParts, Parts}; pub mod error; pub mod impletements; -pub mod view; pub mod release_version; - +pub mod view; pub struct CeobeOperationLogic(T); #[async_trait] -impl FromRequestParts for CeobeOperationLogic -where T:FromRequestParts, -S:Send+Sync+'static+Clone +impl FromRequestParts for CeobeOperationLogic +where + T: FromRequestParts, + S: Send + Sync + 'static + Clone, { type Rejection = >::Rejection; -async fn from_request_parts(parts: & mut Parts,state: & S) -> Result { - Ok(Self(>::from_request_parts(parts, state).await?)) - + async fn from_request_parts( + parts: &mut Parts, state: &S, + ) -> Result { + Ok(Self( + >::from_request_parts(parts, state) + .await?, + )) } } impl DerefMut for CeobeOperationLogic { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl Deref for CeobeOperationLogic { type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} \ No newline at end of file + fn deref(&self) -> &Self::Target { &self.0 } +} diff --git a/logic/ceobe_operation_logic/src/release_version/error.rs b/logic/ceobe_operation_logic/src/release_version/error.rs index e82167e3..2e2dba63 100644 --- a/logic/ceobe_operation_logic/src/release_version/error.rs +++ b/logic/ceobe_operation_logic/src/release_version/error.rs @@ -3,17 +3,14 @@ use std::convert::Infallible; use persistence::ceobe_operate::release_version; use tencent_cloud_server::error::TcCloudError; +pub(super) type Rejection = Infallible; - -pub(super)type Rejection = Infallible; - - -#[derive(Debug,thiserror::Error,status_err::StatusErr)] +#[derive(Debug, thiserror::Error, status_err::StatusErr)] pub enum Error { #[error(transparent)] - Dao(#[from]release_version::Error), + Dao(#[from] release_version::Error), #[error(transparent)] - Tencent(#[from]TcCloudError) + Tencent(#[from] TcCloudError), } -pub(super) type LogicResult = core::result::Result; \ No newline at end of file +pub(super) type LogicResult = core::result::Result; diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index d7c389c2..efe99073 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -1,5 +1,8 @@ use db_ops_prelude::database_operates::operate_trait::OperateTrait; -use page_size::{request::Paginator, response::{GenerateListWithPageInfo, ListWithPageInfo}}; +use page_size::{ + request::Paginator, + response::{GenerateListWithPageInfo, ListWithPageInfo}, +}; use persistence::{ ceobe_operate::{ models::version::models::{ReleasePlatform, ReleaseVersion}, @@ -47,24 +50,28 @@ impl ReleaseVersionLogic { Some(paginator) => { let total = self.count(platform, yanked).await?; Ok(msg.with_page_info(paginator, total as _)) - }, + } None => Ok(msg.with_plain()), } - } - pub async fn count(&self,platform: Option,yanked: bool)->LogicResult{ - let count = self.mongodb - .ceobe() - .operation() - .release_version() - .retrieve() - .total_num(platform, yanked) - .await?; - Ok(count) + pub async fn count( + &self, platform: Option, yanked: bool, + ) -> LogicResult { + let count = self + .mongodb + .ceobe() + .operation() + .release_version() + .retrieve() + .total_num(platform, yanked) + .await?; + Ok(count) } - pub async fn new(&self, release: ReleaseVersion) -> LogicResult<()> { + pub async fn create_new( + &self, release: ReleaseVersion, + ) -> LogicResult<()> { self.mongodb .ceobe() .operation() @@ -78,10 +85,13 @@ impl ReleaseVersionLogic { Ok(()) } - pub async fn fetch(&self, version: Option,platform: ReleasePlatform)->LogicResult{ + pub async fn fetch( + &self, version: Option, platform: ReleasePlatform, + ) -> LogicResult { let release_info = match version { None => { - self.mongodb.ceobe() + self.mongodb + .ceobe() .operation() .release_version() .retrieve() @@ -89,7 +99,8 @@ impl ReleaseVersionLogic { .await? } Some(ver) => { - self.mongodb.ceobe() + self.mongodb + .ceobe() .operation() .release_version() .retrieve() diff --git a/logic/ceobe_operation_logic/src/release_version/mod.rs b/logic/ceobe_operation_logic/src/release_version/mod.rs index a6a62ba4..e69d9e01 100644 --- a/logic/ceobe_operation_logic/src/release_version/mod.rs +++ b/logic/ceobe_operation_logic/src/release_version/mod.rs @@ -42,6 +42,8 @@ mod error; mod implement; pub mod view; -use self::error::{Rejection,LogicResult}; -use self::view::*; pub use self::error::Error; +use self::{ + error::{LogicResult, Rejection}, + view::*, +}; diff --git a/logic/ceobe_operation_logic/src/release_version/view.rs b/logic/ceobe_operation_logic/src/release_version/view.rs index f857c68f..7bf1cdab 100644 --- a/logic/ceobe_operation_logic/src/release_version/view.rs +++ b/logic/ceobe_operation_logic/src/release_version/view.rs @@ -5,4 +5,4 @@ pub struct TencentCDNPath; impl TencentCDNPath { pub const LATEST_VERSION: PurgeCachePath = PurgeCachePath::new("/cdn/operate/version/fetch"); -} \ No newline at end of file +} diff --git a/macros/check-obj-macro/src/lib.rs b/macros/check-obj-macro/src/lib.rs index 1f1490ea..1bc1bf3b 100644 --- a/macros/check-obj-macro/src/lib.rs +++ b/macros/check-obj-macro/src/lib.rs @@ -64,7 +64,7 @@ mod inner_checker_info; /// 1. `uncheck` 传递一个标识符,用于作为生成的 `UnCheck` 的名称 /// 2. `checked` 传递一个类型,为`Checked` 结构体的类型 /// 3. `error` 传递一个类型, 为生成的 `Checker` 的异常统一映射目标类型, -/// 要求所有的内部`Checker` 的 `Err` 都实现了 [Into](Into) +/// 要求所有的内部`Checker` 的 `Err` 都实现了 [Into](Into) /// /// 传递顺序不可打乱,使用`,` 分割,最后的`,` 可选 /// @@ -100,7 +100,8 @@ mod inner_checker_info; /// /// - 如果需要挂载额外的过程宏或者 `derive` 宏到 `Uncheck` 结构体上,可以在 /// [check_obj](macro@check_obj) -/// 之下挂载宏,[check_obj](macro@check_obj)将会将其搬运到 `Uncheck` 结构体上 +/// 之下挂载宏,[check_obj](macro@check_obj)将会将其搬运到 `Uncheck` +/// 结构体上 /// - 生成的 `Uncheck` 与 `Checker` 的可见性 与 被挂载结构体的可见性 (`pub`) /// 一致 /// - 生成的 `Uncheck` 中每一个域(field)的可见性 与 @@ -112,11 +113,9 @@ mod inner_checker_info; /// ## 生成什么? /// /// 1. `Uncheck` 结构体,名称通过过程宏参数提供 -/// 2. `Checker` 空白结构体,并为其实现 -/// `Checker` -/// 3. `CheckerFut` -/// [!Unpin](std::marker::Unpin) 的结构体,并为其实现 -/// [Future](std::future::Future) ,在其内部实现具体`check`过程 +/// 2. `Checker` 空白结构体,并为其实现 `Checker` +/// 3. `CheckerFut` [!Unpin](std::marker::Unpin) 的结构体,并为其实现 +/// [Future](std::future::Future) ,在其内部实现具体`check`过程 #[proc_macro_attribute] pub fn check_obj(params: TokenStream, item: TokenStream) -> TokenStream { let params = parse_macro_input!(params as checker_info::CheckerInfo); diff --git a/macros/status-err-derive/src/lib.rs b/macros/status-err-derive/src/lib.rs index 3a8d95e1..5c7a50e1 100644 --- a/macros/status-err-derive/src/lib.rs +++ b/macros/status-err-derive/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::manual_unwrap_or_default)] + use darling::FromDeriveInput; use input_loading::derive_info::StatusErrorDeriveInfo; use proc_macro::TokenStream; diff --git a/middle-server/mob-push-server/src/lib.rs b/middle-server/mob-push-server/src/lib.rs index 6187a1c2..4db8e2eb 100644 --- a/middle-server/mob-push-server/src/lib.rs +++ b/middle-server/mob-push-server/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_borrows_for_generic_args)] + pub use config::app_info::MobPushConfigTrait; use device_info::DeviceInfo; pub use error::MobPushError; diff --git a/middle-server/mob-push-server/src/push_notify/android/image.rs b/middle-server/mob-push-server/src/push_notify/android/image.rs index dbc99676..e055c2a7 100644 --- a/middle-server/mob-push-server/src/push_notify/android/image.rs +++ b/middle-server/mob-push-server/src/push_notify/android/image.rs @@ -25,7 +25,7 @@ impl Image { /// /// - 透传消息不支持 /// - 小米厂商对图片尺寸有严格要求,不符合要求则不会按照大图样式进行推送, - /// 具体要求为:宽高固定为876*324px,格式需为PNG/JPG/JPEG,大小小于1M + /// 具体要求为:宽高固定为876*324px,格式需为PNG/JPG/JPEG,大小小于1M /// - OPPO厂商大图需要申请权限,否则会报错导致客户端收不到推送消息 pub fn new_image(image_url: impl Into) -> Self { Self::Image(image_url.into()) diff --git a/middle-server/qiniu-cdn-upload/src/lib.rs b/middle-server/qiniu-cdn-upload/src/lib.rs index 5f177c78..2e961b87 100644 --- a/middle-server/qiniu-cdn-upload/src/lib.rs +++ b/middle-server/qiniu-cdn-upload/src/lib.rs @@ -15,8 +15,7 @@ pub mod update_source; /// 通用七牛云上传接口 /// /// - `uploader`: [`&Uploader`](Uploader) 七牛云上传器,可以通过 -/// [`QiniuManager`](ceobe_qiniu_upload::QiniuManager) -/// 解引用获得 +/// [`QiniuManager`](ceobe_qiniu_upload::QiniuManager) 解引用获得 /// - `source`: 原始待上传信息,可以从中获得待上传的内容和待上传的 /// `Content-Type` /// - `payload`: 指定荷载的信息,包括 上传七牛云的路径,如何从source diff --git a/persistence/dao/fetcher/src/sql/datasource_combination/retrieve.rs b/persistence/dao/fetcher/src/sql/datasource_combination/retrieve.rs index 2857a245..36a21b39 100644 --- a/persistence/dao/fetcher/src/sql/datasource_combination/retrieve.rs +++ b/persistence/dao/fetcher/src/sql/datasource_combination/retrieve.rs @@ -31,7 +31,7 @@ impl DatasourceCombinationOperate<'_, NoConnect> { Ok(Entity::find() .from_raw_sql(Statement::from_sql_and_values( db.get_database_backend(), - &query.to_string(MysqlQueryBuilder).to_lowercase(), + query.to_string(MysqlQueryBuilder).to_lowercase(), [], )) .into_model::() diff --git a/persistence/database/mongo_connection/src/database/manager.rs b/persistence/database/mongo_connection/src/database/manager.rs index 36ca1eef..aee885d1 100644 --- a/persistence/database/mongo_connection/src/database/manager.rs +++ b/persistence/database/mongo_connection/src/database/manager.rs @@ -47,13 +47,13 @@ impl DatabaseManage { } /// 对完成获取的数据库进行数据操作 - /// - handle 为一个异步操作闭包 - /// 形如 `async fn function(&Collection)->Result` + /// - handle 为一个异步操作闭包 形如 `async fn + /// function(&Collection)->Result` /// /// - 这里要求 E 允许 `MongodbError` 可以转换为E /// - /// - 函数通过泛型参数自动识别并寻找对应的Collection - /// 如果Collection 未被创建,就会允许失败 + /// - 函数通过泛型参数自动识别并寻找对应的Collection 如果Collection + /// 未被创建,就会允许失败 pub async fn doing( &self, handle: F, ) -> Result diff --git a/persistence/models/mongo-models/src/ceobe/user_property/models/mod.rs b/persistence/models/mongo-models/src/ceobe/user_property/models/mod.rs index 1c556ca9..8cd8f21e 100644 --- a/persistence/models/mongo-models/src/ceobe/user_property/models/mod.rs +++ b/persistence/models/mongo-models/src/ceobe/user_property/models/mod.rs @@ -8,7 +8,7 @@ use sub_model::SubModel; use typed_builder::TypedBuilder; use crate::{RecordUnit, RecordUnitUpdater, SetRecordUnit}; - +#[allow(clippy::duplicated_attributes)] #[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder, SubModel)] #[sub_model( all( diff --git a/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs b/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs index 3c207eac..d243d7b5 100644 --- a/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs +++ b/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs @@ -9,6 +9,7 @@ use crate::{ NaiveDateTime, SoftDelete, }; +#[allow(clippy::duplicated_attributes)] #[derive(Debug, Clone, PartialEq, Eq, DeriveEntityModel, SubModel)] #[sea_orm(table_name = "fetcher_datasource_config")] #[sub_model( diff --git a/src/error/mod.rs b/src/error/mod.rs index 6c3b3ca3..1dbee996 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -10,8 +10,8 @@ use tracing::{error, instrument, warn}; #[macro_export] /// 1. 辅助构造枚举形式的Error, -/// 并提供 [Form](std::convert::Form)转换实现, -/// 和 [StatusErr](status_err::StatusErr)实现 +/// 并提供 [Form](std::convert::Form)转换实现, +/// 和 [StatusErr](status_err::StatusErr)实现 /// ```rust /// error_generate!( /// // |------- 构造的枚举型异常的类型名称 From f98de90647cc5bc762614ed870a645d6c8e59866 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 10:38:35 +0800 Subject: [PATCH 51/68] =?UTF-8?q?=F0=9F=8E=A8=20cargo=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/error/mod.rs b/src/error/mod.rs index 1dbee996..928b99e6 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -9,19 +9,19 @@ use status_err::ErrPrefix; use tracing::{error, instrument, warn}; #[macro_export] -/// 1. 辅助构造枚举形式的Error, -/// 并提供 [Form](std::convert::Form)转换实现, -/// 和 [StatusErr](status_err::StatusErr)实现 -/// ```rust +/// 1. 辅助构造枚举形式的Error, 并提供 [Form](std::convert::Form)转换实现, 和 +/// [StatusErr](status_err::StatusErr)实现 +/// +/// ```rust /// error_generate!( -/// // |------- 构造的枚举型异常的类型名称 -/// pub GolbalError -/// // |--------------枚举类型的名称 -/// // | |-------每一枚举类型内部的类型 -/// Io=std::io::Error // 多个内部类型用空格区分 -/// Db=sea_orm::DbErr +/// // |------- 构造的枚举型异常的类型名称 +/// pub GolbalError +/// // |--------------枚举类型的名称 +/// // | |-------每一枚举类型内部的类型 +/// Io=std::io::Error // 多个内部类型用空格区分 +/// Db=sea_orm::DbErr /// ); -/// ``` +/// ``` /// 2. 为现有类型生成包装类型 /// ```rust /// error_generate!( From 32c891d0513b89348b0fd4478cf6a168aa5c7e55 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 10:44:28 +0800 Subject: [PATCH 52/68] =?UTF-8?q?=F0=9F=91=B7=20=E8=B0=83=E6=95=B4rustc=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/checker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checker.yaml b/.github/workflows/checker.yaml index 064a5666..3ae96c69 100644 --- a/.github/workflows/checker.yaml +++ b/.github/workflows/checker.yaml @@ -21,7 +21,7 @@ jobs: - name: Rust toolchain Stable uses: actions-rs/toolchain@v1 with: - toolchain: 1.78.0 + toolchain: 1.80.1 components: clippy default: true - name: Rust toolchain Nightly From 45d6e93650bc710bde44c13750e7a19971c3cb2c Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Sun, 8 Sep 2024 21:46:06 +0800 Subject: [PATCH 53/68] =?UTF-8?q?=F0=9F=94=A5=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=80=BB=E9=87=8F=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/handlers.rs | 1 - .../src/handlers/admin_end.rs | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index dbf736aa..8aad3584 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -44,6 +44,5 @@ where .route("/yank", post(Self::yank_version)) .route("/create", post(Self::new_version)) .route("/all", get(Self::all_version)) - .route("/total_num", get(Self::released_version_num)) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index d3651f8e..42329323 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -52,18 +52,6 @@ impl crate::ReleaseVersionController { Ok(ret) } - #[resp_result] - #[instrument(skip_all)] - pub async fn released_version_num( - logic: CeobeOperationLogic, - MapReject(filter): MapRejecter>>, - ) -> Result { - let QueryVersionFilter { platform, yanked } = - filter.unwrap_or_default(); - let ret = logic.count(platform, yanked).await?; - Ok(ret) - } - #[resp_result] #[instrument(skip_all,fields(version = %(arg_1.0.version)))] pub async fn new_version( From 14ff23802a32dbedaeca53d0ea963ea989975f13 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 9 Sep 2024 09:37:42 +0800 Subject: [PATCH 54/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/mongo/release_version/common.rs | 25 ++++++++++ .../src/mongo/release_version/mod.rs | 2 + .../src/mongo/release_version/retrieve.rs | 8 ++- .../src/mongo/release_version/update.rs | 49 +++++++++++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/common.rs create mode 100644 persistence/dao/ceobe-operate/src/mongo/release_version/update.rs diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs new file mode 100644 index 00000000..d62f3ceb --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs @@ -0,0 +1,25 @@ +use serde::Serialize; +use db_ops_prelude::mongo_models::ceobe::operation::version::models::{ReleasePlatform, Version}; +use db_ops_prelude::mongodb::bson::{doc, Document, to_bson}; + +pub(super) fn generate_set_document( + key: &str, value: T, +) -> super::Result { + let doc = doc! { + key:{ + "$set" : to_bson(value)? + } + }; + + Ok(doc) +} + +pub(super) fn generate_release_version_filter( + version: &Version, release_platform: &ReleasePlatform, +) -> super::Result { + let doc = doc! { + "version" : to_bson(version)?, + "platform": to_bson(release_platform)? + }; + Ok(doc) +} diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs index 012f4bd8..29cc53a7 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -2,6 +2,8 @@ mod create; mod delete; mod retrieve; mod verify; +mod update; +mod common; use db_ops_prelude::{ mongo_connection::{database_traits::dao_operator, MongoDbError}, diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index 2dfc910a..226d4e7c 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -9,7 +9,7 @@ use db_ops_prelude::{ }; use page_size::request::Paginator; use tracing::info; - +use crate::release_version::common::generate_release_version_filter; use super::{ models::{ReleaseVersion, Version}, Error, ReleaseVersionRetrieve, Result, @@ -26,10 +26,7 @@ where info!(release.version = %version, release.platform = ?platform); let collection = self.get_collection()?; - let filter = doc! { - "version":to_bson(version)?, - "platform":to_bson(&platform)? - }; + let filter = generate_release_version_filter(version,&platform)?; let ret = collection .doing(|collection| collection.find_one(filter, None)) @@ -38,6 +35,7 @@ where Error::VersionNotFind(version.to_owned(), platform) })?; Ok(ret) + } /// 根据平台返回最新的版本信息 diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs new file mode 100644 index 00000000..9a442f0e --- /dev/null +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs @@ -0,0 +1,49 @@ +use db_ops_prelude::{ + mongo_connection::MongoDbCollectionTrait, + mongo_models::ceobe::operation::version::models::{ + DownloadSourceItem, ReleasePlatform, ReleaseVersion, Version, + }, + mongodb::bson::{doc, to_bson, Document}, +}; +use serde::Serialize; +use crate::release_version::common::{generate_release_version_filter, generate_set_document}; + +impl<'db, C> super::ReleaseVersionUpdate<'db, C> +where + C: MongoDbCollectionTrait<'db, ReleaseVersion>, +{ + pub async fn description( + &'db self, version: Version, platform: ReleasePlatform, + new_description: impl Into>, + ) -> super::Result<()> { + let collection = self.get_collection()?; + + let filter = generate_release_version_filter(&version, &platform)?; + let update = + generate_set_document("description", new_description.into())?; + + collection + .doing(|collection| collection.update_one(filter, update, None)) + .await?; + + Ok(()) + } + + pub async fn download_resource( + &'db self, version: Version, release_platform: ReleasePlatform, + resource: Vec, + ) -> super::Result<()> { + let collect = self.get_collection()?; + + let filter = + generate_release_version_filter(&version, &release_platform)?; + let update = generate_set_document("download_source", resource)?; + + collect + .doing(|collect| collect.update_one(filter, update, None)) + .await?; + + Ok(()) + } +} + From 5d47b84949e14ba2c5193abc00122f59f7ef2b72 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 9 Sep 2024 10:13:45 +0800 Subject: [PATCH 55/68] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=E6=9B=B4?= =?UTF-8?q?=E6=96=B0handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/handlers.rs | 6 +++ .../src/handlers/admin_end.rs | 50 ++++++++++++++++++- .../release_version_service/src/view.rs | 29 ++++++++++- .../src/release_version/implement.rs | 37 +++++++++++++- .../src/mongo/release_version/common.rs | 2 +- 5 files changed, 118 insertions(+), 6 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 8aad3584..7504dbce 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -44,5 +44,11 @@ where .route("/yank", post(Self::yank_version)) .route("/create", post(Self::new_version)) .route("/all", get(Self::all_version)) + .nest( + "/modify", + Router::new() + .route("/description", post(Self::modify_description)) + .route("/download_resource", post(Self::modify_resource)), + ) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index 42329323..7022ef47 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -12,11 +12,15 @@ use serve_utils::{ tracing::instrument, ValueField, }; +use tracing::log::__private_api::log; use crate::{ error::Error, handlers::{MapRejecter, Result}, - view::{QueryReleaseVersion, QueryVersionFilter}, + view::{ + QueryReleaseVersion, QueryVersionFilter, QueryVersionUpdate, + UpdateDescription, UpdateDownloadResource, + }, }; impl crate::ReleaseVersionController { @@ -61,4 +65,48 @@ impl crate::ReleaseVersionController { logic.create_new(release).await?; Ok(()) } + + #[resp_result] + #[instrument(skip_all,fields( + version = %(arg_1.0.version), + ))] + pub async fn modify_description( + logic: CeobeOperationLogic, + MapReject(QueryVersionUpdate { + version: + QueryReleaseVersion { + version: ValueField(version), + platform, + }, + set: UpdateDescription { description }, + }): MapRejecter>>, + ) -> Result<()> { + logic + .update_description(version, platform, description) + .await?; + Ok(()) + } + + #[resp_result] + #[instrument(skip_all,fields( + version = %(arg_1.0.version), + ))] + pub async fn modify_resource( + logic: CeobeOperationLogic, + MapReject(QueryVersionUpdate { + version: + QueryReleaseVersion { + version: ValueField(version), + platform, + }, + set: UpdateDownloadResource { download_source }, + }): MapRejecter< + Json>, + >, + ) -> Result<()> { + logic + .update_resource(version, platform, download_source) + .await?; + Ok(()) + } } diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 06c417f9..53033f3c 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -1,8 +1,10 @@ use std::fmt::{Display, Formatter}; -use persistence::ceobe_operate::models::version::models::ReleasePlatform; -use semver::Version; +use persistence::ceobe_operate::models::version::models::{DownloadSourceItem, ReleasePlatform}; +use semver::{Op, Version}; +use serde::de::DeserializeOwned; use serde::Deserialize; +use tracing::Value; use serve_utils::{OptionValueField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] @@ -52,6 +54,29 @@ impl Display for QueryVersionFilter { } } +#[derive(Debug,Deserialize)] +pub struct QueryVersionUpdate{ + pub version:QueryReleaseVersion>, + #[serde(rename="$set")] + pub set:T +} + +//TODO: 更新结构讨论 +#[derive(Debug,Deserialize,Default)] +pub struct UpdateDescription{ + #[serde(default)] + pub description:Option +} + +#[derive(Debug,Deserialize,Default)] +pub struct UpdateDownloadResource{ + #[serde(default)] + pub download_source:Vec +} + + + + #[cfg(test)] mod test { use serve_utils::SkipField; diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index efe99073..0e78c370 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -1,11 +1,15 @@ -use db_ops_prelude::database_operates::operate_trait::OperateTrait; +use db_ops_prelude::{ + database_operates::operate_trait::OperateTrait, tracing::log::Log, +}; use page_size::{ request::Paginator, response::{GenerateListWithPageInfo, ListWithPageInfo}, }; use persistence::{ ceobe_operate::{ - models::version::models::{ReleasePlatform, ReleaseVersion}, + models::version::models::{ + DownloadSourceItem, ReleasePlatform, ReleaseVersion, + }, ToCeobeOperation, }, ceobe_user::ToCeobe, @@ -110,4 +114,33 @@ impl ReleaseVersionLogic { }; Ok(release_info) } + + pub async fn update_description( + &self, version: Version, platform: ReleasePlatform, + description: Option, + ) -> LogicResult<()> { + self.mongodb + .ceobe() + .operation() + .release_version() + .update() + .description(version, platform, description) + .await?; + Ok(()) + } + + pub async fn update_resource( + &self, version: Version, release_platform: ReleasePlatform, + resources: Vec, + ) -> LogicResult<()> { + self.mongodb + .ceobe() + .operation() + .release_version() + .update() + .download_resource(version, release_platform, resources) + .await?; + + Ok(()) + } } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs index d62f3ceb..62325ce8 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs @@ -7,7 +7,7 @@ pub(super) fn generate_set_document( ) -> super::Result { let doc = doc! { key:{ - "$set" : to_bson(value)? + "$set" : to_bson(&value)? } }; From 1026080c3fbb711d3963e83636a1e2123ac7f2ae Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Mon, 9 Sep 2024 10:52:53 +0800 Subject: [PATCH 56/68] :art: cargo clippy + cargo fmt --- global/redis_global/src/type_bind/hash.rs | 8 ++--- global/redis_global/src/type_bind/normal.rs | 15 +++----- .../src/handlers/admin_end.rs | 1 - .../release_version_service/src/view.rs | 35 +++++++++---------- .../src/release_version/implement.rs | 17 ++++----- .../src/mongo/release_version/common.rs | 8 +++-- .../src/mongo/release_version/mod.rs | 4 +-- .../src/mongo/release_version/retrieve.rs | 6 ++-- .../src/mongo/release_version/update.rs | 8 ++--- .../src/impletements/datasource_comb.rs | 2 +- src/bootstrap/middleware/panic_report.rs | 13 +++---- src/router/mod.rs | 19 +++++----- 12 files changed, 62 insertions(+), 74 deletions(-) diff --git a/global/redis_global/src/type_bind/hash.rs b/global/redis_global/src/type_bind/hash.rs index d4e9c7b8..7c07eac8 100644 --- a/global/redis_global/src/type_bind/hash.rs +++ b/global/redis_global/src/type_bind/hash.rs @@ -40,12 +40,11 @@ where self.redis.hexists(&*self.key, field).await } - pub async fn set<'arg, RV, F>( + pub async fn set<'arg, F>( &mut self, field: F, value: T::Input, - ) -> RedisResult + ) -> RedisResult<()> where F: ToRedisArgs + Send + Sync + 'arg, - RV: FromRedisValue, { self.redis.hset(&*self.key, field, value).await } @@ -97,10 +96,9 @@ where /// /// ## 参考 /// - [`AsyncCommands::hdel`] - pub async fn remove<'arg, RV, F>(&mut self, field: F) -> RedisResult + pub async fn remove<'arg, F>(&mut self, field: F) -> RedisResult<()> where F: ToRedisArgs + Send + Sync + 'arg, - RV: FromRedisValue, { self.redis.hdel(&*self.key, field).await } diff --git a/global/redis_global/src/type_bind/normal.rs b/global/redis_global/src/type_bind/normal.rs index 15b8dd02..56103e62 100644 --- a/global/redis_global/src/type_bind/normal.rs +++ b/global/redis_global/src/type_bind/normal.rs @@ -53,12 +53,10 @@ where /// /// ## 参考 /// - [`AsyncCommands::set_nx`] - pub async fn set_if_not_exist( + pub async fn set_if_not_exist( &mut self, value: T::Input, - ) -> RedisResult - where - RV: FromRedisValue, - { + ) -> RedisResult<()> +where { self.redis.set_nx(&*self.key, value).await } @@ -66,12 +64,9 @@ where /// /// ## 参考 /// - [`AsyncCommands::set_ex`] - pub async fn set_with_expire( + pub async fn set_with_expire( &mut self, value: T::Input, duration: Duration, - ) -> RedisResult - where - RV: FromRedisValue, - { + ) -> RedisResult<()> { self.redis .set_ex(&*self.key, value, duration.as_secs() as _) .await diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index 7022ef47..dff0df57 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -12,7 +12,6 @@ use serve_utils::{ tracing::instrument, ValueField, }; -use tracing::log::__private_api::log; use crate::{ error::Error, diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 53033f3c..f9411a40 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -1,10 +1,10 @@ use std::fmt::{Display, Formatter}; -use persistence::ceobe_operate::models::version::models::{DownloadSourceItem, ReleasePlatform}; -use semver::{Op, Version}; -use serde::de::DeserializeOwned; +use persistence::ceobe_operate::models::version::models::{ + DownloadSourceItem, ReleasePlatform, +}; +use semver::Version; use serde::Deserialize; -use tracing::Value; use serve_utils::{OptionValueField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] @@ -54,29 +54,26 @@ impl Display for QueryVersionFilter { } } -#[derive(Debug,Deserialize)] -pub struct QueryVersionUpdate{ - pub version:QueryReleaseVersion>, - #[serde(rename="$set")] - pub set:T +#[derive(Debug, Deserialize)] +pub struct QueryVersionUpdate { + pub version: QueryReleaseVersion>, + #[serde(rename = "$set")] + pub set: T, } -//TODO: 更新结构讨论 -#[derive(Debug,Deserialize,Default)] -pub struct UpdateDescription{ +// TODO: 更新结构讨论 +#[derive(Debug, Deserialize, Default)] +pub struct UpdateDescription { #[serde(default)] - pub description:Option + pub description: Option, } -#[derive(Debug,Deserialize,Default)] -pub struct UpdateDownloadResource{ +#[derive(Debug, Deserialize, Default)] +pub struct UpdateDownloadResource { #[serde(default)] - pub download_source:Vec + pub download_source: Vec, } - - - #[cfg(test)] mod test { use serve_utils::SkipField; diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index 0e78c370..8bef3e14 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -1,18 +1,13 @@ -use db_ops_prelude::{ - database_operates::operate_trait::OperateTrait, tracing::log::Log, -}; +use db_ops_prelude::database_operates::operate_trait::OperateTrait; use page_size::{ request::Paginator, response::{GenerateListWithPageInfo, ListWithPageInfo}, }; -use persistence::{ - ceobe_operate::{ - models::version::models::{ - DownloadSourceItem, ReleasePlatform, ReleaseVersion, - }, - ToCeobeOperation, +use persistence::ceobe_operate::{ + models::version::models::{ + DownloadSourceItem, ReleasePlatform, ReleaseVersion, }, - ceobe_user::ToCeobe, + ToCeobe, ToCeobeOperation, }; use semver::Version; @@ -140,7 +135,7 @@ impl ReleaseVersionLogic { .update() .download_resource(version, release_platform, resources) .await?; - + Ok(()) } } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs index 62325ce8..2449afb0 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs @@ -1,6 +1,10 @@ +use db_ops_prelude::{ + mongo_models::ceobe::operation::version::models::{ + ReleasePlatform, Version, + }, + mongodb::bson::{doc, to_bson, Document}, +}; use serde::Serialize; -use db_ops_prelude::mongo_models::ceobe::operation::version::models::{ReleasePlatform, Version}; -use db_ops_prelude::mongodb::bson::{doc, Document, to_bson}; pub(super) fn generate_set_document( key: &str, value: T, diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs index 29cc53a7..fca67752 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/mod.rs @@ -1,9 +1,9 @@ +mod common; mod create; mod delete; mod retrieve; -mod verify; mod update; -mod common; +mod verify; use db_ops_prelude::{ mongo_connection::{database_traits::dao_operator, MongoDbError}, diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index 226d4e7c..57690b07 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -9,11 +9,12 @@ use db_ops_prelude::{ }; use page_size::request::Paginator; use tracing::info; -use crate::release_version::common::generate_release_version_filter; + use super::{ models::{ReleaseVersion, Version}, Error, ReleaseVersionRetrieve, Result, }; +use crate::release_version::common::generate_release_version_filter; impl<'db, Conn> ReleaseVersionRetrieve<'db, Conn> where @@ -26,7 +27,7 @@ where info!(release.version = %version, release.platform = ?platform); let collection = self.get_collection()?; - let filter = generate_release_version_filter(version,&platform)?; + let filter = generate_release_version_filter(version, &platform)?; let ret = collection .doing(|collection| collection.find_one(filter, None)) @@ -35,7 +36,6 @@ where Error::VersionNotFind(version.to_owned(), platform) })?; Ok(ret) - } /// 根据平台返回最新的版本信息 diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs index 9a442f0e..d9e61dd8 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs @@ -3,10 +3,11 @@ use db_ops_prelude::{ mongo_models::ceobe::operation::version::models::{ DownloadSourceItem, ReleasePlatform, ReleaseVersion, Version, }, - mongodb::bson::{doc, to_bson, Document}, }; -use serde::Serialize; -use crate::release_version::common::{generate_release_version_filter, generate_set_document}; + +use crate::release_version::common::{ + generate_release_version_filter, generate_set_document, +}; impl<'db, C> super::ReleaseVersionUpdate<'db, C> where @@ -46,4 +47,3 @@ where Ok(()) } } - diff --git a/service/qiniu_service/src/impletements/datasource_comb.rs b/service/qiniu_service/src/impletements/datasource_comb.rs index dbd1badb..71752774 100644 --- a/service/qiniu_service/src/impletements/datasource_comb.rs +++ b/service/qiniu_service/src/impletements/datasource_comb.rs @@ -43,7 +43,7 @@ impl QiniuService { .remove(&comb_id) .await?; } - } + }; Ok(()) } diff --git a/src/bootstrap/middleware/panic_report.rs b/src/bootstrap/middleware/panic_report.rs index 53551b95..5d3352ee 100644 --- a/src/bootstrap/middleware/panic_report.rs +++ b/src/bootstrap/middleware/panic_report.rs @@ -49,17 +49,14 @@ impl ResponseForPanic for PanicReportHandle { &mut self, err: Box, ) -> http::Response { // TODO: 推送panic到频道好像有问题 - let err = if let Some(msg) = err + + let err = err .downcast_ref::() .map(String::as_str) .or_else(|| err.downcast_ref::<&str>().copied()) - { - msg - } - else { - "Unknown Panic Message" - } - .to_owned(); + .unwrap_or("Unknown Panic Message") + .to_owned(); + error!(unexpectedPanic.detail = err); let service = self.0.clone(); tokio::spawn(async move { diff --git a/src/router/mod.rs b/src/router/mod.rs index fd9a42a1..00e0bdb3 100644 --- a/src/router/mod.rs +++ b/src/router/mod.rs @@ -43,15 +43,18 @@ pub fn root_route() -> ServerRoute { .nest("/qiniuCdn", qiniu_cdn_router()) .route( "/panic", - get(|| async { - #[cfg(debug_assertions)] - { - panic!("测试 Panic"); + get(|| { + async { + #[cfg(debug_assertions)] + { + let f =||->&str{panic!("测试 Panic")}; + f() + } + #[cfg(not(debug_assertions))] + axum_resp_result::RespResult::<_, crate::error::NotAnError>::ok( + "不可以Panic", + ) } - #[cfg(not(debug_assertions))] - axum_resp_result::RespResult::<_, crate::error::NotAnError>::ok( - "不可以Panic", - ) }), ) } From af2421d934a3d29e10ebaaec34ffbcc6cb3e82de Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 12 Sep 2024 16:42:31 +0800 Subject: [PATCH 57/68] =?UTF-8?q?:recycle:=20=E5=90=88=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/handlers.rs | 7 +---- .../src/handlers/admin_end.rs | 31 +++---------------- .../release_version_service/src/view.rs | 19 +++++------- .../src/impletements/announcement.rs | 2 +- .../src/impletements/resource.rs | 2 +- .../src/impletements/tool_link.rs | 2 +- .../src/impletements/video.rs | 2 +- .../src/release_version/implement.rs | 14 +++------ 8 files changed, 22 insertions(+), 57 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 7504dbce..2dba71b8 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -44,11 +44,6 @@ where .route("/yank", post(Self::yank_version)) .route("/create", post(Self::new_version)) .route("/all", get(Self::all_version)) - .nest( - "/modify", - Router::new() - .route("/description", post(Self::modify_description)) - .route("/download_resource", post(Self::modify_resource)), - ) + .route("/modify", post(Self::modify_description)) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index dff0df57..b0ab24ff 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -18,9 +18,9 @@ use crate::{ handlers::{MapRejecter, Result}, view::{ QueryReleaseVersion, QueryVersionFilter, QueryVersionUpdate, - UpdateDescription, UpdateDownloadResource, }, }; +use crate::view::UpdatePayload; impl crate::ReleaseVersionController { #[resp_result] @@ -77,35 +77,14 @@ impl crate::ReleaseVersionController { version: ValueField(version), platform, }, - set: UpdateDescription { description }, - }): MapRejecter>>, + set:UpdatePayload{ description, download_source }, + }): MapRejecter>, ) -> Result<()> { logic - .update_description(version, platform, description) + .update(version, platform, description,download_source) .await?; Ok(()) } - #[resp_result] - #[instrument(skip_all,fields( - version = %(arg_1.0.version), - ))] - pub async fn modify_resource( - logic: CeobeOperationLogic, - MapReject(QueryVersionUpdate { - version: - QueryReleaseVersion { - version: ValueField(version), - platform, - }, - set: UpdateDownloadResource { download_source }, - }): MapRejecter< - Json>, - >, - ) -> Result<()> { - logic - .update_resource(version, platform, download_source) - .await?; - Ok(()) - } + } diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index f9411a40..ecc8f317 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -55,27 +55,24 @@ impl Display for QueryVersionFilter { } #[derive(Debug, Deserialize)] -pub struct QueryVersionUpdate { +pub struct QueryVersionUpdate { pub version: QueryReleaseVersion>, #[serde(rename = "$set")] - pub set: T, + pub set: UpdatePayload, } - -// TODO: 更新结构讨论 #[derive(Debug, Deserialize, Default)] -pub struct UpdateDescription { - #[serde(default)] +pub struct UpdatePayload{ pub description: Option, -} - -#[derive(Debug, Deserialize, Default)] -pub struct UpdateDownloadResource { - #[serde(default)] pub download_source: Vec, } + + + #[cfg(test)] mod test { + use serde::Deserialize; + use serde_json::json; use serve_utils::SkipField; use crate::view::QueryReleaseVersion; diff --git a/logic/ceobe_operation_logic/src/impletements/announcement.rs b/logic/ceobe_operation_logic/src/impletements/announcement.rs index 2d78d2f4..66ae7cf6 100644 --- a/logic/ceobe_operation_logic/src/impletements/announcement.rs +++ b/logic/ceobe_operation_logic/src/impletements/announcement.rs @@ -1,8 +1,8 @@ use persistence::{ ceobe_operate::{announcement, ToCeobeOperation}, - ceobe_user::ToCeobe, mysql::SqlDatabaseOperate, }; +use persistence::ceobe_operate::ToCeobe; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, }; diff --git a/logic/ceobe_operation_logic/src/impletements/resource.rs b/logic/ceobe_operation_logic/src/impletements/resource.rs index 93713270..afd19bfa 100644 --- a/logic/ceobe_operation_logic/src/impletements/resource.rs +++ b/logic/ceobe_operation_logic/src/impletements/resource.rs @@ -1,8 +1,8 @@ use persistence::{ ceobe_operate::{resource, ToCeobeOperation}, - ceobe_user::ToCeobe, mysql::SqlDatabaseOperate, }; +use persistence::ceobe_operate::ToCeobe; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, }; diff --git a/logic/ceobe_operation_logic/src/impletements/tool_link.rs b/logic/ceobe_operation_logic/src/impletements/tool_link.rs index 19933911..5440204e 100644 --- a/logic/ceobe_operation_logic/src/impletements/tool_link.rs +++ b/logic/ceobe_operation_logic/src/impletements/tool_link.rs @@ -8,10 +8,10 @@ use persistence::{ models::tool_link::checkers::tool_link_data::CeobeOperationToolLink, tool_link_mongodb::models::ToolLink, ToCeobeOperation, }, - ceobe_user::ToCeobe, mongodb::{mongodb::bson, MongoDatabaseOperate}, mysql::SqlDatabaseOperate, }; +use persistence::ceobe_operate::ToCeobe; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, }; diff --git a/logic/ceobe_operation_logic/src/impletements/video.rs b/logic/ceobe_operation_logic/src/impletements/video.rs index a833aa3a..bfcd9495 100644 --- a/logic/ceobe_operation_logic/src/impletements/video.rs +++ b/logic/ceobe_operation_logic/src/impletements/video.rs @@ -3,10 +3,10 @@ use persistence::{ video::{self, bv::Bv}, ToCeobeOperation, }, - ceobe_user::ToCeobe, help_crates::tracing::{event, Level}, mysql::SqlDatabaseOperate, }; +use persistence::ceobe_operate::ToCeobe; use request_clients::bili_client::QueryBiliVideo; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index 8bef3e14..ff7d9ae6 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -110,30 +110,24 @@ impl ReleaseVersionLogic { Ok(release_info) } - pub async fn update_description( + pub async fn update( &self, version: Version, platform: ReleasePlatform, - description: Option, + description: Option,resources: Vec, ) -> LogicResult<()> { self.mongodb .ceobe() .operation() .release_version() .update() - .description(version, platform, description) + .description(version.clone(), platform, description) .await?; - Ok(()) - } - pub async fn update_resource( - &self, version: Version, release_platform: ReleasePlatform, - resources: Vec, - ) -> LogicResult<()> { self.mongodb .ceobe() .operation() .release_version() .update() - .download_resource(version, release_platform, resources) + .download_resource(version, platform, resources) .await?; Ok(()) From 200ad4504e8c0771964194bc87f0b32817851882 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Thu, 12 Sep 2024 16:43:05 +0800 Subject: [PATCH 58/68] :art: cargo fmt + cargo clippy --- .../src/handlers/admin_end.rs | 12 +++++++----- .../release_version_service/src/view.rs | 5 +---- .../src/impletements/announcement.rs | 3 +-- .../src/impletements/resource.rs | 3 +-- .../src/impletements/tool_link.rs | 3 +-- .../ceobe_operation_logic/src/impletements/video.rs | 3 +-- .../src/release_version/implement.rs | 2 +- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index b0ab24ff..e43d52f7 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -18,9 +18,9 @@ use crate::{ handlers::{MapRejecter, Result}, view::{ QueryReleaseVersion, QueryVersionFilter, QueryVersionUpdate, + UpdatePayload, }, }; -use crate::view::UpdatePayload; impl crate::ReleaseVersionController { #[resp_result] @@ -77,14 +77,16 @@ impl crate::ReleaseVersionController { version: ValueField(version), platform, }, - set:UpdatePayload{ description, download_source }, + set: + UpdatePayload { + description, + download_source, + }, }): MapRejecter>, ) -> Result<()> { logic - .update(version, platform, description,download_source) + .update(version, platform, description, download_source) .await?; Ok(()) } - - } diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index ecc8f317..f8866e6a 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -61,14 +61,11 @@ pub struct QueryVersionUpdate { pub set: UpdatePayload, } #[derive(Debug, Deserialize, Default)] -pub struct UpdatePayload{ +pub struct UpdatePayload { pub description: Option, pub download_source: Vec, } - - - #[cfg(test)] mod test { use serde::Deserialize; diff --git a/logic/ceobe_operation_logic/src/impletements/announcement.rs b/logic/ceobe_operation_logic/src/impletements/announcement.rs index 66ae7cf6..8451419a 100644 --- a/logic/ceobe_operation_logic/src/impletements/announcement.rs +++ b/logic/ceobe_operation_logic/src/impletements/announcement.rs @@ -1,8 +1,7 @@ use persistence::{ - ceobe_operate::{announcement, ToCeobeOperation}, + ceobe_operate::{announcement, ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use persistence::ceobe_operate::ToCeobe; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, }; diff --git a/logic/ceobe_operation_logic/src/impletements/resource.rs b/logic/ceobe_operation_logic/src/impletements/resource.rs index afd19bfa..7f76f87b 100644 --- a/logic/ceobe_operation_logic/src/impletements/resource.rs +++ b/logic/ceobe_operation_logic/src/impletements/resource.rs @@ -1,8 +1,7 @@ use persistence::{ - ceobe_operate::{resource, ToCeobeOperation}, + ceobe_operate::{resource, ToCeobe, ToCeobeOperation}, mysql::SqlDatabaseOperate, }; -use persistence::ceobe_operate::ToCeobe; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, }; diff --git a/logic/ceobe_operation_logic/src/impletements/tool_link.rs b/logic/ceobe_operation_logic/src/impletements/tool_link.rs index 5440204e..d86bea14 100644 --- a/logic/ceobe_operation_logic/src/impletements/tool_link.rs +++ b/logic/ceobe_operation_logic/src/impletements/tool_link.rs @@ -6,12 +6,11 @@ use page_size::{ use persistence::{ ceobe_operate::{ models::tool_link::checkers::tool_link_data::CeobeOperationToolLink, - tool_link_mongodb::models::ToolLink, ToCeobeOperation, + tool_link_mongodb::models::ToolLink, ToCeobe, ToCeobeOperation, }, mongodb::{mongodb::bson, MongoDatabaseOperate}, mysql::SqlDatabaseOperate, }; -use persistence::ceobe_operate::ToCeobe; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, }; diff --git a/logic/ceobe_operation_logic/src/impletements/video.rs b/logic/ceobe_operation_logic/src/impletements/video.rs index bfcd9495..52becf28 100644 --- a/logic/ceobe_operation_logic/src/impletements/video.rs +++ b/logic/ceobe_operation_logic/src/impletements/video.rs @@ -1,12 +1,11 @@ use persistence::{ ceobe_operate::{ video::{self, bv::Bv}, - ToCeobeOperation, + ToCeobe, ToCeobeOperation, }, help_crates::tracing::{event, Level}, mysql::SqlDatabaseOperate, }; -use persistence::ceobe_operate::ToCeobe; use request_clients::bili_client::QueryBiliVideo; use tencent_cloud_server::{ cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager, diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index ff7d9ae6..f9e0da1e 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -112,7 +112,7 @@ impl ReleaseVersionLogic { pub async fn update( &self, version: Version, platform: ReleasePlatform, - description: Option,resources: Vec, + description: Option, resources: Vec, ) -> LogicResult<()> { self.mongodb .ceobe() From 2d8a59e6853b088d94d6152f2f1372775630755b Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Tue, 15 Oct 2024 08:18:17 +0800 Subject: [PATCH 59/68] =?UTF-8?q?=F0=9F=93=9D=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3view=E6=96=87=E6=A1=A3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/view.rs | 2 +- libs/serve_utils/src/view_traits.rs | 46 +++++++++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 06c417f9..a9a1017d 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -7,7 +7,7 @@ use serve_utils::{OptionValueField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< - Version: OptionViewField = OptionValueField, + Version: OptionViewField = OptionValueField, > { #[serde(skip_serializing_if = "OptionViewField::skip_serde")] pub version: Version, diff --git a/libs/serve_utils/src/view_traits.rs b/libs/serve_utils/src/view_traits.rs index 835bf32b..b55deedc 100644 --- a/libs/serve_utils/src/view_traits.rs +++ b/libs/serve_utils/src/view_traits.rs @@ -2,7 +2,44 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::view_traits::_private::SealTrait; -pub trait OptionViewField: _private::SealTrait { +/// 用于view中的可选field +/// +/// 由于view可能存面向不同端有细微差别,如果由于少量的字段区分重复整个view定义会带来大量代码冗余。 +/// 因此,提出了该trait +/// +/// ## Example +/// 如果有某个view结构体, +/// - 其在后台接口的view需要提供其ID +/// - 在前台接口的view中不需要提供ID +/// - 在请求接口中会基于是否提供ID进行不同操作 +/// +/// 那么使用[OptionViewField]就可以如下实现 +/// +/// ```rust +/// use serde::{Serialize, Deserialize}; +/// +/// #[derive(Serialize, Deserialize)] +/// struct FooView>{ +/// id:ID, +/// foo:String +/// } +/// ``` +/// +/// - 当在后台接口中使用时,其为 `FooView>`, 即需要提供id的view。可能的序列化结果为 +/// ```json +/// { +/// "id": 114514, +/// "foo": "hello" +/// } +/// ``` +/// - 当在前台接口中使用时,其为 `FooView`, 即不携带id的view。可能的序列化结果为 +/// ```json +/// { +/// "foo": "hello" +/// } +/// ``` +/// - 当需要根据是否提供ID执行不同操作实现,其为 `FooView>`, 即携带Option的ID的view +pub trait OptionViewField: _private::SealTrait { fn skip_serde(&self) -> bool; } @@ -10,6 +47,7 @@ mod _private { pub trait SealTrait {} } +/// View 中可选field的可以跳过情况 #[derive(Default, Debug, Clone, Copy)] pub struct SkipField; @@ -32,7 +70,7 @@ impl<'de> Deserialize<'de> for SkipField { } } -impl OptionViewField for SkipField { +impl OptionViewField for SkipField { fn skip_serde(&self) -> bool { true } } @@ -63,7 +101,7 @@ impl Serialize for ValueField { impl SealTrait for ValueField {} -impl OptionViewField for ValueField { +impl OptionViewField for ValueField { fn skip_serde(&self) -> bool { false } } @@ -90,7 +128,7 @@ impl Serialize for OptionValueField { } } -impl OptionViewField for OptionValueField { +impl OptionViewField for OptionValueField { fn skip_serde(&self) -> bool { self.0.is_none() } } From 887233c8f59a2fd95934603c395721479902ef22 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Tue, 15 Oct 2024 08:20:05 +0800 Subject: [PATCH 60/68] =?UTF-8?q?=F0=9F=8E=A8=20cargo=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/view.rs | 4 +++- libs/serve_utils/src/view_traits.rs | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index efdffd86..31584aa3 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -9,7 +9,9 @@ use serve_utils::{OptionValueField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< - Version: OptionViewField = OptionValueField, + Version: OptionViewField = OptionValueField< + semver::Version, + >, > { #[serde(skip_serializing_if = "OptionViewField::skip_serde")] pub version: Version, diff --git a/libs/serve_utils/src/view_traits.rs b/libs/serve_utils/src/view_traits.rs index b55deedc..ac5b1dc4 100644 --- a/libs/serve_utils/src/view_traits.rs +++ b/libs/serve_utils/src/view_traits.rs @@ -3,42 +3,46 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::view_traits::_private::SealTrait; /// 用于view中的可选field -/// -/// 由于view可能存面向不同端有细微差别,如果由于少量的字段区分重复整个view定义会带来大量代码冗余。 +/// +/// 由于view可能存面向不同端有细微差别, +/// 如果由于少量的字段区分重复整个view定义会带来大量代码冗余。 /// 因此,提出了该trait -/// +/// /// ## Example /// 如果有某个view结构体, /// - 其在后台接口的view需要提供其ID /// - 在前台接口的view中不需要提供ID /// - 在请求接口中会基于是否提供ID进行不同操作 -/// +/// /// 那么使用[OptionViewField]就可以如下实现 -/// +/// /// ```rust /// use serde::{Serialize, Deserialize}; -/// +/// /// #[derive(Serialize, Deserialize)] /// struct FooView>{ /// id:ID, /// foo:String /// } /// ``` -/// -/// - 当在后台接口中使用时,其为 `FooView>`, 即需要提供id的view。可能的序列化结果为 +/// +/// - 当在后台接口中使用时,其为 `FooView>`, +/// 即需要提供id的view。可能的序列化结果为 /// ```json /// { /// "id": 114514, /// "foo": "hello" /// } /// ``` -/// - 当在前台接口中使用时,其为 `FooView`, 即不携带id的view。可能的序列化结果为 +/// - 当在前台接口中使用时,其为 `FooView`, +/// 即不携带id的view。可能的序列化结果为 /// ```json /// { /// "foo": "hello" /// } /// ``` -/// - 当需要根据是否提供ID执行不同操作实现,其为 `FooView>`, 即携带Option的ID的view +/// - 当需要根据是否提供ID执行不同操作实现,其为 +/// `FooView>`, 即携带Option的ID的view pub trait OptionViewField: _private::SealTrait { fn skip_serde(&self) -> bool; } From c29d51c58d8029a37d26747c8c687d11056be9cd Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Tue, 29 Oct 2024 10:34:18 +0800 Subject: [PATCH 61/68] =?UTF-8?q?=F0=9F=93=9D=20=E6=B7=BB=E5=8A=A0OptionVi?= =?UTF-8?q?ewField=20=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/handlers/cdn.rs | 4 ++-- .../release_version_service/src/view.rs | 6 +++--- libs/serve_utils/src/lib.rs | 2 +- libs/serve_utils/src/view_traits.rs | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index 92baa310..543dd266 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -6,7 +6,7 @@ use serve_utils::{ axum::extract::Query, axum_resp_result::{resp_result, MapReject}, tracing::instrument, - OptionValueField, + OptionField, }; use super::{MapRejecter, Result}; @@ -17,7 +17,7 @@ impl crate::ReleaseVersionController { pub async fn release_version( logic: CeobeOperationLogic, MapReject(QueryReleaseVersion { - version: OptionValueField(version), + version: OptionField(version), platform, }): MapRejecter>, ) -> Result { diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 31584aa3..9866c047 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -5,11 +5,11 @@ use persistence::ceobe_operate::models::version::models::{ }; use semver::Version; use serde::Deserialize; -use serve_utils::{OptionValueField, OptionViewField, ValueField}; +use serve_utils::{OptionField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< - Version: OptionViewField = OptionValueField< + Version: OptionViewField = OptionField< semver::Version, >, > { @@ -24,7 +24,7 @@ impl Display for QueryReleaseVersion> { } } -impl Display for QueryReleaseVersion> { +impl Display for QueryReleaseVersion> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match &self.version.0 { None => { diff --git a/libs/serve_utils/src/lib.rs b/libs/serve_utils/src/lib.rs index 1a04bef0..81660ee9 100644 --- a/libs/serve_utils/src/lib.rs +++ b/libs/serve_utils/src/lib.rs @@ -15,7 +15,7 @@ pub use status_err; pub use thiserror::Error as ThisError; pub use tracing; pub use view_traits::{ - OptionValueField, OptionViewField, SkipField, ValueField, + OptionField, OptionViewField, SkipField, ValueField, }; pub mod endpoint { diff --git a/libs/serve_utils/src/view_traits.rs b/libs/serve_utils/src/view_traits.rs index ac5b1dc4..1a32c1d9 100644 --- a/libs/serve_utils/src/view_traits.rs +++ b/libs/serve_utils/src/view_traits.rs @@ -5,7 +5,7 @@ use crate::view_traits::_private::SealTrait; /// 用于view中的可选field /// /// 由于view可能存面向不同端有细微差别, -/// 如果由于少量的字段区分重复整个view定义会带来大量代码冗余。 +/// 但是如果由于少量的字段区分重复整个view定义会带来大量代码冗余。 /// 因此,提出了该trait /// /// ## Example @@ -110,9 +110,9 @@ impl OptionViewField for ValueField { } #[derive(Debug, Clone)] -pub struct OptionValueField(pub Option); +pub struct OptionField(pub Option); -impl<'de, T: Deserialize<'de>> Deserialize<'de> for OptionValueField { +impl<'de, T: Deserialize<'de>> Deserialize<'de> for OptionField { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, @@ -123,7 +123,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for OptionValueField { } } -impl Serialize for OptionValueField { +impl Serialize for OptionField { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -132,8 +132,8 @@ impl Serialize for OptionValueField { } } -impl OptionViewField for OptionValueField { +impl OptionViewField for OptionField { fn skip_serde(&self) -> bool { self.0.is_none() } } -impl SealTrait for OptionValueField {} +impl SealTrait for OptionField {} From 989379c14a97d5bd13fbf2f31006bb6470c9a81b Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Tue, 29 Oct 2024 11:08:22 +0800 Subject: [PATCH 62/68] =?UTF-8?q?=E2=9C=A8=20=E6=B7=BB=E5=8A=A0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=B8=80=E6=AC=A1=E5=AE=9A=E4=B9=89=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=89=80=E5=B1=9ERouter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/handlers.rs | 8 +- .../release_version_service/src/view.rs | 4 +- libs/serve_utils/src/controller_trait.rs | 10 +- libs/serve_utils/src/endpoint_type.rs | 9 +- libs/serve_utils/src/lib.rs | 6 +- libs/serve_utils/src/router_extra.rs | 98 +++++++++++++++++-- src/router/back_end/ceobe_operation/mod.rs | 8 +- src/router/cdn/operation/mod.rs | 8 +- 8 files changed, 117 insertions(+), 34 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 2dba71b8..9ae7a0e8 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -5,7 +5,7 @@ use serve_utils::{ Router, }, endpoint::{AdminEnd, CDN}, - ControllerRouter, HandlerMapReject, HandlerResult, + ControllerRoute, HandlerMapReject, HandlerResult, }; use tencent_cloud_server::axum_starter::{ PartTencentCloudManagerState, RequestClient, @@ -18,7 +18,7 @@ pub(crate) type Result = HandlerResult; pub(crate) type MapRejecter = HandlerMapReject; -impl ControllerRouter for crate::ReleaseVersionController +impl ControllerRoute for crate::ReleaseVersionController where S: Send + Clone + Sync + 'static, PartTencentCloudManagerState: FromRef, @@ -31,13 +31,13 @@ where } } -impl ControllerRouter for crate::ReleaseVersionController +impl ControllerRoute for crate::ReleaseVersionController where S: Send + Clone + Sync + 'static, PartTencentCloudManagerState: FromRef, RequestClient: FromRef, { - const BASE_URI: &'static str = "/release_version"; + const BASE_URI: &'static str = "/releaseVersion"; fn route(self) -> Router { Router::new() diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 9866c047..15a84de4 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -70,8 +70,8 @@ pub struct UpdatePayload { #[cfg(test)] mod test { - use serde::Deserialize; - use serde_json::json; + + use serve_utils::SkipField; use crate::view::QueryReleaseVersion; diff --git a/libs/serve_utils/src/controller_trait.rs b/libs/serve_utils/src/controller_trait.rs index 756c2afa..4fc43208 100644 --- a/libs/serve_utils/src/controller_trait.rs +++ b/libs/serve_utils/src/controller_trait.rs @@ -7,7 +7,7 @@ use tower::{Layer, Service}; use crate::EndpointType; -pub trait ControllerRouter +pub trait ControllerRoute where S: Clone + Send + Sync + 'static, E: EndpointType, @@ -25,7 +25,7 @@ where >::Error: Into + 'static, >::Future: Send + 'static, { - LayeredController::new(ControllerRouter::route(self).layer(layer)) + LayeredController::new(ControllerRoute::route(self).layer(layer)) } } @@ -43,13 +43,13 @@ impl LayeredController { } } -impl ControllerRouter for LayeredController +impl ControllerRoute for LayeredController where S: Clone + Send + Sync + 'static, - C: ControllerRouter, + C: ControllerRoute, E: EndpointType, { - const BASE_URI: &'static str = >::BASE_URI; + const BASE_URI: &'static str = >::BASE_URI; fn route(self) -> Router { self.inner } } diff --git a/libs/serve_utils/src/endpoint_type.rs b/libs/serve_utils/src/endpoint_type.rs index 77ff66e3..74bc07e6 100644 --- a/libs/serve_utils/src/endpoint_type.rs +++ b/libs/serve_utils/src/endpoint_type.rs @@ -1,17 +1,18 @@ -pub trait EndpointType {} +pub trait EndpointType:Default {} +#[derive(Default)] pub struct UserEnd; impl EndpointType for UserEnd {} - +#[derive(Default)] pub struct AdminEnd; impl EndpointType for AdminEnd {} - +#[derive(Default)] pub struct CDN; impl EndpointType for CDN {} - +#[derive(Default)] pub struct Internal; impl EndpointType for Internal {} diff --git a/libs/serve_utils/src/lib.rs b/libs/serve_utils/src/lib.rs index 81660ee9..c98b095a 100644 --- a/libs/serve_utils/src/lib.rs +++ b/libs/serve_utils/src/lib.rs @@ -6,11 +6,11 @@ mod view_traits; pub use axum; pub use axum_resp_result; pub use controller_trait::{ - ControllerError, ControllerRouter, HandlerMapReject, HandlerResult, - LayeredController, + ControllerError, ControllerRoute, HandlerMapReject, HandlerResult, + LayeredController }; pub use endpoint_type::EndpointType; -pub use router_extra::ControllerRouterExt; +pub use router_extra::{ControllerRouterExt,ControllerRouter}; pub use status_err; pub use thiserror::Error as ThisError; pub use tracing; diff --git a/libs/serve_utils/src/router_extra.rs b/libs/serve_utils/src/router_extra.rs index 11a7329a..5f6095e9 100644 --- a/libs/serve_utils/src/router_extra.rs +++ b/libs/serve_utils/src/router_extra.rs @@ -1,6 +1,11 @@ -use axum::Router; +use std::{convert::Infallible, marker::PhantomData}; -use crate::{ControllerRouter, EndpointType}; +use axum::{ + extract::Request, response::IntoResponse, routing::Route, Router, +}; +use tower::{Layer, Service}; + +use crate::{ControllerRoute, EndpointType}; pub trait ControllerRouterExt { fn nest_controller(self, controller: C, _endpoint: E) -> Self; @@ -10,19 +15,96 @@ pub trait ControllerRouterExt { impl ControllerRouterExt for Router where - C: ControllerRouter, + C: ControllerRoute, E: EndpointType, S: Send + Sync + 'static + Clone, { fn nest_controller(self, controller: C, _endpoint: E) -> Self { self.nest( C::BASE_URI, - >::route(controller), + >::route(controller), ) } fn merge_controller(self, controller: C, _endpoint: E) -> Self { - self.merge(>::route(controller)) + self.merge(>::route(controller)) + } +} + +pub struct ControllerRouter { + router: Router, + __phantom: PhantomData, +} + +impl Into> for ControllerRouter { + fn into(self) -> Router { + self.router + } +} + +impl ControllerRouter +where + E: EndpointType, + S: Send + Sync + 'static + Clone, +{ + pub fn nest_controller>( + self, controller: C, + ) -> Self { + self.nest( + C::BASE_URI, + >::route(controller), + ) + } + + pub fn merge_controller>( + self, controller: C, + ) -> Self { + let router = self + .router + .merge(>::route(controller)); + Self { router, ..self } + } + + pub fn nest(self, path: &str, handler: Router) -> Self { + let router = self.router.nest(path, handler); + Self { router, ..self } + } + + pub fn merge>>(self, handler: R) -> Self { + let router = self.router.merge(handler); + Self { router, ..self } + } + + pub fn route_layer(self, layer: L) -> Self + where + L: Layer + Clone + Send + 'static, + L::Service: Service + Clone + Send + 'static, + >::Response: IntoResponse + 'static, + >::Error: Into + 'static, + >::Future: Send + 'static, + { + let router = self.router.route_layer(layer); + Self { router, ..self } + } +} + +impl ControllerRouter { + pub fn new(_endpoint: E) -> Self + where + S: Clone + Send + Sync + 'static, + E: EndpointType, + { + Self { + router: Router::new(), + __phantom: PhantomData, + } + } + + pub fn set_router) -> Router>( + self, handle: F, + ) -> Self { + let router = handle(self.router); + Self { router, ..self } } } @@ -31,19 +113,19 @@ mod test { use axum::Router; use crate::{ - endpoint::AdminEnd, endpoint_type::UserEnd, ControllerRouter, + endpoint::AdminEnd, endpoint_type::UserEnd, ControllerRoute, ControllerRouterExt, }; pub struct TestController; - impl ControllerRouter + impl ControllerRoute for TestController { const BASE_URI: &'static str = "/admin/test"; } - impl ControllerRouter + impl ControllerRoute for TestController { const BASE_URI: &'static str = "/test"; diff --git a/src/router/back_end/ceobe_operation/mod.rs b/src/router/back_end/ceobe_operation/mod.rs index 9ab7325b..465cec3c 100644 --- a/src/router/back_end/ceobe_operation/mod.rs +++ b/src/router/back_end/ceobe_operation/mod.rs @@ -1,8 +1,7 @@ pub use announcement::CeobeOperationAnnouncement; -use axum::Router; use release_version_service::ReleaseVersionController; pub use resource::CeobeOpResource; -use serve_utils::{endpoint::AdminEnd, ControllerRouterExt}; +use serve_utils::{endpoint::AdminEnd, ControllerRouter}; pub use tool_link::CeobeOpToolLink; pub use version::CeobeOpVersion; pub use video::CeobeOperationVideo; @@ -25,14 +24,15 @@ mod version; mod video; pub(super) fn ceobe_operation_router() -> crate::router::ServerRoute { - Router::new() + ControllerRouter::new(AdminEnd) .nest("/announcement", announcement_router()) .nest("/video", video_router()) .nest("/version", version_router()) .nest("/resource", resource_router()) .nest("/toolLink", tool_link_router()) - .nest_controller(ReleaseVersionController, AdminEnd) + .nest_controller(ReleaseVersionController) .route_layer(AuthorizeLayer::::new()) + .into() } new_auth_level! { diff --git a/src/router/cdn/operation/mod.rs b/src/router/cdn/operation/mod.rs index 6aaf3cf5..24ddefef 100644 --- a/src/router/cdn/operation/mod.rs +++ b/src/router/cdn/operation/mod.rs @@ -1,8 +1,7 @@ pub use announcement::CdnOperationAnnouncementFrontend; -use axum::Router; use release_version_service::ReleaseVersionController; pub use resource::CdnOperationResourceFrontend; -use serve_utils::{endpoint::CDN, ControllerRouterExt}; +use serve_utils::{endpoint::CDN, ControllerRouter}; pub use tool_link::CdnOperateToolLinkFrontend; pub use video::CdnOperationVideoFrontend; @@ -18,10 +17,11 @@ mod tool_link; mod video; pub(super) fn operation_router() -> ServerRoute { - Router::new() + ControllerRouter::new(CDN) .nest("/video", video_router()) .nest("/announcement", announcement_router()) .nest("/resource", resource_router()) - .nest_controller(ReleaseVersionController, CDN) + .nest_controller(ReleaseVersionController) .nest("/toolLink", tool_list_router()) + .into() } From f1704e5c2772334d78d9300bfc3f77b2b8a89546 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Tue, 29 Oct 2024 11:28:24 +0800 Subject: [PATCH 63/68] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/release_version/implement.rs | 17 +++--- .../src/mongo/release_version/common.rs | 13 ----- .../src/mongo/release_version/delete.rs | 33 +----------- .../src/mongo/release_version/update.rs | 54 ++++++++++++------- .../src/mongo/release_version/verify.rs | 2 +- 5 files changed, 45 insertions(+), 74 deletions(-) diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index f9e0da1e..ad838ded 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -21,7 +21,7 @@ impl ReleaseVersionLogic { .ceobe() .operation() .release_version() - .delete() + .update() .yank(platform, version) .await?; @@ -119,15 +119,12 @@ impl ReleaseVersionLogic { .operation() .release_version() .update() - .description(version.clone(), platform, description) - .await?; - - self.mongodb - .ceobe() - .operation() - .release_version() - .update() - .download_resource(version, platform, resources) + .description_and_resource( + version.clone(), + platform, + description, + resources, + ) .await?; Ok(()) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs index 2449afb0..f0f9a91f 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/common.rs @@ -4,19 +4,6 @@ use db_ops_prelude::{ }, mongodb::bson::{doc, to_bson, Document}, }; -use serde::Serialize; - -pub(super) fn generate_set_document( - key: &str, value: T, -) -> super::Result { - let doc = doc! { - key:{ - "$set" : to_bson(&value)? - } - }; - - Ok(doc) -} pub(super) fn generate_release_version_filter( version: &Version, release_platform: &ReleasePlatform, diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs index 24af5e50..2d77b267 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs @@ -1,40 +1,11 @@ use db_ops_prelude::{ mongo_connection::MongoDbCollectionTrait, - mongo_models::ceobe::operation::version::models::{ - ReleasePlatform, ReleaseVersion, Version, - }, - mongodb::bson::{doc, to_bson}, + mongo_models::ceobe::operation::version::models::ReleaseVersion, }; -use super::Result; impl<'db, Conn> super::ReleaseVersionDelete<'db, Conn> where Conn: MongoDbCollectionTrait<'db, ReleaseVersion>, { - /// 撤回一个已经发布的版本 - pub async fn yank( - &'db self, platform: &ReleasePlatform, version: &Version, - ) -> Result<()> { - let collection = self.get_collection()?; - let filter = doc! { - "platform": to_bson(platform)?, - "version": to_bson(version)?, - "yanked":false - }; - collection - .doing(|collection| { - collection.find_one_and_update( - filter, - doc! { - "$set":{ - "yanked": true - } - }, - None, - ) - }) - .await?; - - Ok(()) - } + } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs index d9e61dd8..23029004 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs @@ -3,25 +3,31 @@ use db_ops_prelude::{ mongo_models::ceobe::operation::version::models::{ DownloadSourceItem, ReleasePlatform, ReleaseVersion, Version, }, + mongodb::bson::{doc, to_bson}, }; -use crate::release_version::common::{ - generate_release_version_filter, generate_set_document, -}; +use crate::release_version::common::generate_release_version_filter; + +use super::Result; impl<'db, C> super::ReleaseVersionUpdate<'db, C> where C: MongoDbCollectionTrait<'db, ReleaseVersion>, { - pub async fn description( + pub async fn description_and_resource( &'db self, version: Version, platform: ReleasePlatform, new_description: impl Into>, - ) -> super::Result<()> { + resource: Vec, + ) -> Result<()> { let collection = self.get_collection()?; let filter = generate_release_version_filter(&version, &platform)?; - let update = - generate_set_document("description", new_description.into())?; + let update = doc! { + "$set":{ + "description": to_bson(&new_description.into())?, + "download_source":to_bson(&resource)? + } + }; collection .doing(|collection| collection.update_one(filter, update, None)) @@ -30,18 +36,28 @@ where Ok(()) } - pub async fn download_resource( - &'db self, version: Version, release_platform: ReleasePlatform, - resource: Vec, - ) -> super::Result<()> { - let collect = self.get_collection()?; - - let filter = - generate_release_version_filter(&version, &release_platform)?; - let update = generate_set_document("download_source", resource)?; - - collect - .doing(|collect| collect.update_one(filter, update, None)) + /// 撤回一个已经发布的版本 + pub async fn yank( + &'db self, platform: &ReleasePlatform, version: &Version, + ) -> Result<()> { + let collection = self.get_collection()?; + let filter = doc! { + "platform": to_bson(platform)?, + "version": to_bson(version)?, + "yanked":false + }; + collection + .doing(|collection| { + collection.find_one_and_update( + filter, + doc! { + "$set":{ + "yanked": true + } + }, + None, + ) + }) .await?; Ok(()) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs index 15271705..82cc40a8 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/verify.rs @@ -31,7 +31,7 @@ pub(super) async fn suitable_version( filter, FindOneOptions::builder() .sort(doc! {"$natural": -1i32}) - .projection(doc! {"version":1i32}) + .projection(doc! {"version": 1i32}) .build(), ) }) From c0d1574fa0b625728eeef132fd272d1effa4a8d7 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Tue, 29 Oct 2024 11:29:41 +0800 Subject: [PATCH 64/68] =?UTF-8?q?=F0=9F=8E=A8=20cargo=20clippy=20+=20cargo?= =?UTF-8?q?=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ceobe_operation/release_version_service/src/view.rs | 7 ++----- libs/serve_utils/src/endpoint_type.rs | 2 +- libs/serve_utils/src/lib.rs | 8 +++----- libs/serve_utils/src/router_extra.rs | 6 ++---- .../dao/ceobe-operate/src/mongo/release_version/delete.rs | 6 ++---- .../dao/ceobe-operate/src/mongo/release_version/update.rs | 3 +-- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 15a84de4..3b7b54b7 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -9,9 +9,7 @@ use serve_utils::{OptionField, OptionViewField, ValueField}; #[derive(Deserialize, Clone, Debug)] pub struct QueryReleaseVersion< - Version: OptionViewField = OptionField< - semver::Version, - >, + Version: OptionViewField = OptionField, > { #[serde(skip_serializing_if = "OptionViewField::skip_serde")] pub version: Version, @@ -70,8 +68,7 @@ pub struct UpdatePayload { #[cfg(test)] mod test { - - + use serve_utils::SkipField; use crate::view::QueryReleaseVersion; diff --git a/libs/serve_utils/src/endpoint_type.rs b/libs/serve_utils/src/endpoint_type.rs index 74bc07e6..e5352b34 100644 --- a/libs/serve_utils/src/endpoint_type.rs +++ b/libs/serve_utils/src/endpoint_type.rs @@ -1,4 +1,4 @@ -pub trait EndpointType:Default {} +pub trait EndpointType: Default {} #[derive(Default)] pub struct UserEnd; diff --git a/libs/serve_utils/src/lib.rs b/libs/serve_utils/src/lib.rs index c98b095a..9bd104ff 100644 --- a/libs/serve_utils/src/lib.rs +++ b/libs/serve_utils/src/lib.rs @@ -7,16 +7,14 @@ pub use axum; pub use axum_resp_result; pub use controller_trait::{ ControllerError, ControllerRoute, HandlerMapReject, HandlerResult, - LayeredController + LayeredController, }; pub use endpoint_type::EndpointType; -pub use router_extra::{ControllerRouterExt,ControllerRouter}; +pub use router_extra::{ControllerRouter, ControllerRouterExt}; pub use status_err; pub use thiserror::Error as ThisError; pub use tracing; -pub use view_traits::{ - OptionField, OptionViewField, SkipField, ValueField, -}; +pub use view_traits::{OptionField, OptionViewField, SkipField, ValueField}; pub mod endpoint { pub use crate::endpoint_type::{AdminEnd, Internal, UserEnd, CDN}; diff --git a/libs/serve_utils/src/router_extra.rs b/libs/serve_utils/src/router_extra.rs index 5f6095e9..ebf4c969 100644 --- a/libs/serve_utils/src/router_extra.rs +++ b/libs/serve_utils/src/router_extra.rs @@ -36,10 +36,8 @@ pub struct ControllerRouter { __phantom: PhantomData, } -impl Into> for ControllerRouter { - fn into(self) -> Router { - self.router - } +impl From> for Router { + fn from(val: ControllerRouter) -> Self { val.router } } impl ControllerRouter diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs index 2d77b267..7767b066 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/delete.rs @@ -3,9 +3,7 @@ use db_ops_prelude::{ mongo_models::ceobe::operation::version::models::ReleaseVersion, }; -impl<'db, Conn> super::ReleaseVersionDelete<'db, Conn> -where - Conn: MongoDbCollectionTrait<'db, ReleaseVersion>, +impl<'db, Conn> super::ReleaseVersionDelete<'db, Conn> where + Conn: MongoDbCollectionTrait<'db, ReleaseVersion> { - } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs index 23029004..810b5e62 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs @@ -6,9 +6,8 @@ use db_ops_prelude::{ mongodb::bson::{doc, to_bson}, }; -use crate::release_version::common::generate_release_version_filter; - use super::Result; +use crate::release_version::common::generate_release_version_filter; impl<'db, C> super::ReleaseVersionUpdate<'db, C> where From 502d6965cf8d77cef75233c14cc0aa62a03fd9d5 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Wed, 30 Oct 2024 14:23:51 +0800 Subject: [PATCH 65/68] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=B9=E8=BF=9B=E4=B8=BAflatten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ceobe_operation/release_version_service/src/view.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 3b7b54b7..428018b1 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -56,8 +56,9 @@ impl Display for QueryVersionFilter { #[derive(Debug, Deserialize)] pub struct QueryVersionUpdate { + #[serde(flatten)] pub version: QueryReleaseVersion>, - #[serde(rename = "$set")] + #[serde(flatten)] pub set: UpdatePayload, } #[derive(Debug, Deserialize, Default)] From 825ad58af203080d133f2c2071b79d937884b34b Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Wed, 30 Oct 2024 14:38:22 +0800 Subject: [PATCH 66/68] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ceobe_operation/release_version_service/src/handlers.rs | 2 +- .../ceobe_operation/release_version_service/src/handlers/cdn.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 9ae7a0e8..33791012 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -27,7 +27,7 @@ where const BASE_URI: &'static str = "/version"; fn route(self) -> Router { - Router::new().route("/fetch", get(Self::release_version)) + Router::new().route("/fetch", get(Self::fetch_version)) } } diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs index 543dd266..8e57544e 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/cdn.rs @@ -14,7 +14,7 @@ use crate::view::QueryReleaseVersion; impl crate::ReleaseVersionController { #[resp_result] #[instrument(skip_all,fields(version = %arg_1.0))] - pub async fn release_version( + pub async fn fetch_version( logic: CeobeOperationLogic, MapReject(QueryReleaseVersion { version: OptionField(version), From 9d2e4a5e5bd3772495c2b11cd5825f3cac10a367 Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Wed, 30 Oct 2024 14:40:07 +0800 Subject: [PATCH 67/68] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E5=B0=86logic=20cou?= =?UTF-8?q?nt=20=E6=96=B9=E6=B3=95=E8=B0=83=E6=95=B4=E4=B8=BAprivate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/ceobe_operation_logic/src/release_version/implement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index ad838ded..4def91d2 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -54,7 +54,7 @@ impl ReleaseVersionLogic { } } - pub async fn count( + async fn count( &self, platform: Option, yanked: bool, ) -> LogicResult { let count = self From d141914eddcca41ec121f083eb189cb58941122a Mon Sep 17 00:00:00 2001 From: FrozenString <964413011@qq.com> Date: Thu, 31 Oct 2024 12:34:49 +0800 Subject: [PATCH 68/68] =?UTF-8?q?=F0=9F=9A=9A=20yank=E6=9B=B4=E5=90=8D?= =?UTF-8?q?=E4=B8=BAdelete=E5=92=8Cmark-deleted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release_version_service/src/handlers.rs | 2 +- .../src/handlers/admin_end.rs | 8 ++++---- .../release_version_service/src/view.rs | 6 +++--- .../src/release_version/implement.rs | 14 +++++++------- .../src/mongo/release_version/retrieve.rs | 16 ++++++++-------- .../src/mongo/release_version/update.rs | 6 +++--- .../database/mongo_connection/src/config.rs | 1 + .../ceobe/operation/version/models/version.rs | 2 +- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers.rs b/http_service/ceobe_operation/release_version_service/src/handlers.rs index 33791012..cc386a7d 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers.rs @@ -41,7 +41,7 @@ where fn route(self) -> Router { Router::new() - .route("/yank", post(Self::yank_version)) + .route("/markDelete", post(Self::make_delete_version)) .route("/create", post(Self::new_version)) .route("/all", get(Self::all_version)) .route("/modify", post(Self::modify_description)) diff --git a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs index e43d52f7..936e7124 100644 --- a/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs +++ b/http_service/ceobe_operation/release_version_service/src/handlers/admin_end.rs @@ -25,7 +25,7 @@ use crate::{ impl crate::ReleaseVersionController { #[resp_result] #[instrument(skip_all,fields(version = %arg_1.0))] - pub async fn yank_version( + pub async fn make_delete_version( logic: CeobeOperationLogic, MapReject(QueryReleaseVersion { version: ValueField(version), @@ -34,7 +34,7 @@ impl crate::ReleaseVersionController { Query>>, >, ) -> Result<()> { - logic.yank(&version, &platform).await?; + logic.mark_deleted(&version, &platform).await?; Ok(()) } @@ -48,9 +48,9 @@ impl crate::ReleaseVersionController { >, MapReject(filter): MapRejecter>>, ) -> Result> { - let QueryVersionFilter { platform, yanked } = + let QueryVersionFilter { platform, deleted } = filter.unwrap_or_default(); - let ret = logic.all(paginator, platform, yanked).await?; + let ret = logic.all(paginator, platform, deleted).await?; Ok(ret) } diff --git a/http_service/ceobe_operation/release_version_service/src/view.rs b/http_service/ceobe_operation/release_version_service/src/view.rs index 428018b1..42fe11c3 100644 --- a/http_service/ceobe_operation/release_version_service/src/view.rs +++ b/http_service/ceobe_operation/release_version_service/src/view.rs @@ -38,17 +38,17 @@ impl Display for QueryReleaseVersion> { #[derive(Debug, Deserialize, Default)] pub struct QueryVersionFilter { pub platform: Option, - pub yanked: bool, + pub deleted: bool, } impl Display for QueryVersionFilter { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match &self.platform { None => { - write!(f, "{{yanked: {} }}", self.yanked) + write!(f, "{{deleted: {} }}", self.deleted) } Some(plat) => { - write!(f, "{{yanked: {}, platform: {}}}", self.yanked, plat) + write!(f, "{{deleted: {}, platform: {}}}", self.deleted, plat) } } } diff --git a/logic/ceobe_operation_logic/src/release_version/implement.rs b/logic/ceobe_operation_logic/src/release_version/implement.rs index 4def91d2..97c51cb0 100644 --- a/logic/ceobe_operation_logic/src/release_version/implement.rs +++ b/logic/ceobe_operation_logic/src/release_version/implement.rs @@ -14,7 +14,7 @@ use semver::Version; use super::{LogicResult, ReleaseVersionLogic, TencentCDNPath}; impl ReleaseVersionLogic { - pub async fn yank( + pub async fn mark_deleted( &self, version: &Version, platform: &ReleasePlatform, ) -> LogicResult<()> { self.mongodb @@ -22,7 +22,7 @@ impl ReleaseVersionLogic { .operation() .release_version() .update() - .yank(platform, version) + .mark_deleted(platform, version) .await?; self.tencent_cloud @@ -34,7 +34,7 @@ impl ReleaseVersionLogic { pub async fn all( &self, paginator: Option, - platform: Option, yanked: bool, + platform: Option, deleted: bool, ) -> LogicResult> { let msg = self .mongodb @@ -42,12 +42,12 @@ impl ReleaseVersionLogic { .operation() .release_version() .retrieve() - .all(platform, paginator, yanked) + .all(platform, paginator, deleted) .await?; match paginator { Some(paginator) => { - let total = self.count(platform, yanked).await?; + let total = self.count(platform, deleted).await?; Ok(msg.with_page_info(paginator, total as _)) } None => Ok(msg.with_plain()), @@ -55,7 +55,7 @@ impl ReleaseVersionLogic { } async fn count( - &self, platform: Option, yanked: bool, + &self, platform: Option, deleted: bool, ) -> LogicResult { let count = self .mongodb @@ -63,7 +63,7 @@ impl ReleaseVersionLogic { .operation() .release_version() .retrieve() - .total_num(platform, yanked) + .total_num(platform, deleted) .await?; Ok(count) } diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs index 57690b07..085235d3 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/retrieve.rs @@ -47,7 +47,7 @@ where let collection = self.get_collection()?; let filter = doc! { "platform":to_bson(&platform)?, - "yanked": false + "deleted": false }; let sort = doc! { "$natural": -1i32 @@ -68,10 +68,10 @@ where pub async fn all( &'db self, platform: Option, - paginate: impl Into>, yanked: bool, + paginate: impl Into>, deleted: bool, ) -> Result> { let collection = self.get_collection()?; - let filter = generate_platform_filter_document(platform, yanked)?; + let filter = generate_platform_filter_document(platform, deleted)?; let sort = doc! { "$natural": -1i32 }; @@ -99,10 +99,10 @@ where } pub async fn total_num( - &'db self, platform: Option, yanked: bool, + &'db self, platform: Option, deleted: bool, ) -> Result { let collection = self.get_collection()?; - let filter = generate_platform_filter_document(platform, yanked)?; + let filter = generate_platform_filter_document(platform, deleted)?; let ret = collection .doing(|collection| collection.count_documents(filter, None)) @@ -113,16 +113,16 @@ where } fn generate_platform_filter_document( - platform: Option, yanked: bool, + platform: Option, deleted: bool, ) -> Result { Ok(match platform { None => { - doc! {"yanked": yanked} + doc! {"deleted": deleted} } Some(plat) => { doc! { "platform":to_bson(&plat)?, - "yanked": yanked + "deleted": deleted } } }) diff --git a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs index 810b5e62..57146748 100644 --- a/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs +++ b/persistence/dao/ceobe-operate/src/mongo/release_version/update.rs @@ -36,14 +36,14 @@ where } /// 撤回一个已经发布的版本 - pub async fn yank( + pub async fn mark_deleted( &'db self, platform: &ReleasePlatform, version: &Version, ) -> Result<()> { let collection = self.get_collection()?; let filter = doc! { "platform": to_bson(platform)?, "version": to_bson(version)?, - "yanked":false + "deleted":false }; collection .doing(|collection| { @@ -51,7 +51,7 @@ where filter, doc! { "$set":{ - "yanked": true + "deleted": true } }, None, diff --git a/persistence/database/mongo_connection/src/config.rs b/persistence/database/mongo_connection/src/config.rs index 3d33c584..4fba4f9c 100644 --- a/persistence/database/mongo_connection/src/config.rs +++ b/persistence/database/mongo_connection/src/config.rs @@ -31,6 +31,7 @@ impl Default for MongoDbConfig { host: host_default(), port: port_default(), db_name: "ceobe_canteen".into(), + query: Default::default(), } } } diff --git a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs index 7b297b14..81ea0ee5 100644 --- a/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs +++ b/persistence/models/mongo-models/src/ceobe/operation/version/models/version.rs @@ -34,7 +34,7 @@ pub struct ReleaseVersion { #[builder(via_mutators)] download_source: Vec, #[builder(default = false)] - yanked: bool, + deleted: bool, } #[cfg(test)]