Skip to content

Commit

Permalink
Merge pull request #219 from Enraged-Dun-Cookie-Development-Team/feat…
Browse files Browse the repository at this point in the history
…/union-version

去除冗余嵌套的强制更新内容
  • Loading branch information
phidiaLam authored Dec 1, 2024
2 parents 46f6aed + 87ee1b2 commit fa974e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing_unwrap::ResultExt;
use crate::ceobe::operation::{
plugin_version::{self, DownloadResource, SpareLink},
version::models::{
DownloadSourceItem, ForceCtrl, Primary,
DownloadSourceItem, Primary,
ReleasePlatform::{Desktop, Plugin, Pocket},
ReleaseVersion, ResourceUrl,
SupportPlatform::{Android, MacOS, Windows},
Expand Down Expand Up @@ -40,16 +40,11 @@ impl From<plugin_version::Checked> for ReleaseVersion {
.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(),
)
.previous_mandatory_version(Version::new(
major as _,
minor as _,
security as _,
))
.add_download_source(
DownloadSourceItem::builder()
.name("CRX")
Expand Down Expand Up @@ -117,25 +112,20 @@ impl From<app_version::Checked> 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(),
.previous_mandatory_version(
last_force_version.parse().unwrap_or_log(),
)
.platform(Pocket)
.description(description)
Expand Down Expand Up @@ -176,7 +166,6 @@ impl From<desktop_version::Checked> for ReleaseVersion {
fn from(
desktop_version::Checked {
version,
force,
last_force_version,
description,
exe,
Expand All @@ -185,18 +174,14 @@ impl From<desktop_version::Checked> for ReleaseVersion {
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(),
.previous_mandatory_version(
last_force_version.parse().unwrap_or_log(),
)
.platform(Desktop)
.description(description)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod conv;
mod download_source;
mod force;
mod platform;
mod primary;
mod version;

pub use download_source::{DownloadSourceItem, ResourceUrl};
pub use force::ForceCtrl;
pub use platform::{ReleasePlatform, SupportPlatform};
pub use primary::Primary;
pub use semver::Version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use crate::ceobe::operation::version::models::{
download_source::DownloadSourceItem, force::ForceCtrl,
platform::ReleasePlatform,
download_source::DownloadSourceItem, platform::ReleasePlatform,
};

#[derive(Debug, Serialize, Deserialize, Clone, TypedBuilder, PartialEq)]
Expand All @@ -23,7 +22,7 @@ pub struct ReleaseVersion {
/// 当前要发布的版本号
pub version: Version,
/// 发布的版本更新控制
force: ForceCtrl,
previous_mandatory_version: Version,
/// 发布的版本的说明
#[builder(default, setter(into, strip_option))]
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -45,18 +44,19 @@ mod test {

use crate::ceobe::operation::version::models::{
platform::SupportPlatform, primary::Primary, DownloadSourceItem,
ForceCtrl, ReleasePlatform, ReleaseVersion, ResourceUrl,
ReleasePlatform, ReleaseVersion, ResourceUrl,
};

#[test]
fn test_sem_version_serde() {
let ver = Version::new(1, 1, 1);
let s = serde_json::to_string(&ver).unwrap();
assert_eq!(s, "\"1.1.1\"")
}
#[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(),
)
.previous_mandatory_version(Version::new(1, 0, 0))
.description("Abc")
.platform(ReleasePlatform::Desktop)
.add_download_source(
Expand Down Expand Up @@ -88,6 +88,7 @@ mod test {
)
.build(),
)
.deleted(false)
.build();

let serde =
Expand All @@ -96,10 +97,7 @@ mod test {
serde,
json!({
"version": "1.13.2",
"force": {
"force_update": false,
"previous_force_version": "1.0.0"
},
"previous_mandatory_version": "1.0.0",
"description": "Abc",
"platform": "desktop",
"download_source": [
Expand All @@ -119,7 +117,8 @@ mod test {
}
]
}
]
],
"deleted":false,

})
);
Expand Down

0 comments on commit fa974e4

Please sign in to comment.