Replace typed-builder with bon and update builder usage
Replaced the 'typed-builder' crate with 'bon' across the project, updating all builder pattern usages to match the new derive macros and method names. Adjusted struct derives and builder method calls in uploader and upload logic to use 'bon::Builder' and the new 'maybe_' method conventions. Updated dependencies in Cargo.toml files accordingly and removed 'typed-builder' from the workspace.
This commit is contained in:
1 parent
69caca628c
commit
e7e795dd72
8 files changed
+23
-45
No files matched your search
Generated
+1
-22
@@ -361,6 +361,7 @@ version = "0.2.4"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64",
|
||||
"bon",
|
||||
"byteorder",
|
||||
"bytes",
|
||||
"chrono",
|
||||
@@ -386,7 +387,6 @@ dependencies = [
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"typed-builder",
|
||||
"url",
|
||||
]
|
||||
|
||||
@@ -3661,7 +3661,6 @@ dependencies = [
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
"typed-builder",
|
||||
"url",
|
||||
]
|
||||
|
||||
@@ -4224,26 +4223,6 @@ version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "typed-builder"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd9d30e3a08026c78f246b173243cf07b3696d274debd26680773b6773c2afc7"
|
||||
dependencies = [
|
||||
"typed-builder-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typed-builder-macro"
|
||||
version = "0.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c36781cc0e46a83726d9879608e4cf6c2505237e263a8eb8c24502989cfdb28"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
|
||||
@@ -29,7 +29,6 @@ error-stack = "0.6.0"
|
||||
time = { version = "0.3", features = ["serde"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
||||
typed-builder = "0.20.0"
|
||||
bon = "3.7.2"
|
||||
regex = "1.11.1"
|
||||
reqwest = { version = "0.12", default-features = false }
|
||||
|
||||
@@ -215,13 +215,13 @@ async fn build_studio(context: &UploadContext, videos: Vec<Video>) -> AppResult<
|
||||
// 使用 Builder 模式简化构建
|
||||
let mut studio: Studio = Studio::builder()
|
||||
.desc(upload_config.description.clone().unwrap_or_default())
|
||||
.dtime(upload_config.dtime)
|
||||
.copyright(upload_config.copyright.unwrap_or(2))
|
||||
.maybe_dtime(upload_config.dtime)
|
||||
.maybe_copyright(upload_config.copyright)
|
||||
.cover(upload_config.cover_path.clone().unwrap_or_default())
|
||||
.dynamic(upload_config.dynamic.clone().unwrap_or_default())
|
||||
.source(upload_config.copyright_source.clone().unwrap_or_default())
|
||||
.tag(upload_config.tags.join(","))
|
||||
.tid(upload_config.tid.unwrap_or(171))
|
||||
.maybe_tid(upload_config.tid)
|
||||
.title(upload_config.title.clone().unwrap_or_default())
|
||||
.videos(videos)
|
||||
.dolby(upload_config.dolby.unwrap_or_default())
|
||||
@@ -231,7 +231,7 @@ async fn build_studio(context: &UploadContext, videos: Vec<Video>) -> AppResult<
|
||||
.up_close_reply(upload_config.up_close_reply.unwrap_or_default())
|
||||
.up_selection_reply(upload_config.up_selection_reply.unwrap_or_default())
|
||||
.up_close_danmu(upload_config.up_close_danmu.unwrap_or_default())
|
||||
.desc_v2(None)
|
||||
.maybe_desc_v2(None)
|
||||
.extra_fields(
|
||||
serde_json::from_str(&upload_config.extra_fields.clone().unwrap_or_default())
|
||||
.unwrap_or_default(), // 处理额外字段
|
||||
|
||||
@@ -27,7 +27,7 @@ cookie = "0.18.1"
|
||||
|
||||
bytes = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
typed-builder = { workspace = true }
|
||||
bon = { workspace = true }
|
||||
reqwest-middleware = { version = "0.4", features = ["json"] }
|
||||
reqwest-retry = "0.7.0"
|
||||
clap = { version = "4", features = ["derive"], optional = true }
|
||||
|
||||
@@ -10,11 +10,12 @@ use std::fmt::{Display, Formatter};
|
||||
use std::num::ParseIntError;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
use bon::Builder;
|
||||
use tracing::{info, warn};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, TypedBuilder)]
|
||||
#[builder(field_defaults(default))]
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Builder)]
|
||||
#[cfg_attr(feature = "cli", derive(clap::Args))]
|
||||
pub struct Studio {
|
||||
/// 是否转载, 1-自制 2-转载
|
||||
@@ -37,10 +38,10 @@ pub struct Studio {
|
||||
|
||||
/// 视频标题
|
||||
#[cfg_attr(feature = "cli", clap(long, default_value_t))]
|
||||
#[builder(!default, setter(into))]
|
||||
pub title: String,
|
||||
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
#[builder(default)]
|
||||
pub desc_format_id: u32,
|
||||
|
||||
/// 视频简介
|
||||
@@ -49,7 +50,6 @@ pub struct Studio {
|
||||
|
||||
/// 视频简介v2
|
||||
#[serde(default)]
|
||||
#[builder(!default)]
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
pub desc_v2: Option<Vec<Credit>>,
|
||||
|
||||
@@ -59,7 +59,7 @@ pub struct Studio {
|
||||
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
#[serde(default)]
|
||||
#[builder(default, setter(skip))]
|
||||
#[builder(default)]
|
||||
pub subtitle: Subtitle,
|
||||
|
||||
/// 视频标签,逗号分隔多个tag
|
||||
@@ -67,7 +67,6 @@ pub struct Studio {
|
||||
pub tag: String,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(!default)]
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
pub videos: Vec<Video>,
|
||||
|
||||
@@ -77,10 +76,12 @@ pub struct Studio {
|
||||
|
||||
#[cfg_attr(feature = "cli", clap(skip))]
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub open_subtitle: bool,
|
||||
|
||||
#[cfg_attr(feature = "cli", clap(long, default_value = "0"))]
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub interactive: u8,
|
||||
|
||||
#[cfg_attr(feature = "cli", clap(long))]
|
||||
@@ -97,6 +98,7 @@ pub struct Studio {
|
||||
/// 是否开启 Hi-Res, 0-关闭 1-开启
|
||||
#[cfg_attr(feature = "cli", clap(long = "hires", default_value = "0"))]
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub lossless_music: u8,
|
||||
|
||||
/// 0-允许转载,1-禁止转载
|
||||
|
||||
@@ -35,7 +35,6 @@ url = { workspace = true }
|
||||
time = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
fancy-regex = { version = "0.16.1"}
|
||||
typed-builder = { workspace = true }
|
||||
bon = { workspace = true }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
async-trait = { workspace = true }
|
||||
|
||||
@@ -413,7 +413,7 @@ fn upload(
|
||||
let studio_pre = StudioPre::builder()
|
||||
.video_path(video_path)
|
||||
.cookie_file(cookie_file)
|
||||
.line(line)
|
||||
.maybe_line(line)
|
||||
.limit(limit)
|
||||
.title(title)
|
||||
.tid(tid)
|
||||
@@ -423,7 +423,7 @@ fn upload(
|
||||
.desc(desc)
|
||||
.dynamic(dynamic)
|
||||
.cover(cover)
|
||||
.dtime(dtime)
|
||||
.maybe_dtime(dtime)
|
||||
.dolby(dolby)
|
||||
.lossless_music(lossless_music)
|
||||
.no_reprint(no_reprint)
|
||||
@@ -432,7 +432,7 @@ fn upload(
|
||||
.up_selection_reply(up_selection_reply)
|
||||
.up_close_danmu(up_close_danmu)
|
||||
.desc_v2_credit(desc_v2)
|
||||
.extra_fields(Some(parse_extra_fields(extra_fields)))
|
||||
.extra_fields(parse_extra_fields(extra_fields))
|
||||
.build();
|
||||
|
||||
// let submit = match submit {
|
||||
|
||||
@@ -14,10 +14,10 @@ use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::time::Instant;
|
||||
use bon::Builder;
|
||||
use tracing::info;
|
||||
|
||||
use biliup_cli::server::errors::{AppError, AppResult};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
#[pyclass]
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
@@ -49,7 +49,7 @@ pub struct PyCredit {
|
||||
biz_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(TypedBuilder)]
|
||||
#[derive(Builder)]
|
||||
pub struct StudioPre {
|
||||
video_path: Vec<PathBuf>,
|
||||
cookie_file: PathBuf,
|
||||
@@ -75,7 +75,6 @@ pub struct StudioPre {
|
||||
#[builder(default = false)]
|
||||
up_close_danmu: bool,
|
||||
desc_v2_credit: Vec<PyCredit>,
|
||||
#[builder(default)]
|
||||
extra_fields: Option<HashMap<String, serde_json::Value>>,
|
||||
}
|
||||
|
||||
@@ -193,7 +192,7 @@ pub async fn upload(
|
||||
|
||||
let mut studio: Studio = Studio::builder()
|
||||
.desc(desc)
|
||||
.dtime(dtime)
|
||||
.maybe_dtime(dtime)
|
||||
.copyright(copyright)
|
||||
.cover(cover)
|
||||
.dynamic(dynamic)
|
||||
@@ -209,8 +208,8 @@ pub async fn upload(
|
||||
.up_close_reply(up_close_reply)
|
||||
.up_selection_reply(up_selection_reply)
|
||||
.up_close_danmu(up_close_danmu)
|
||||
.desc_v2(Some(desc_v2))
|
||||
.extra_fields(extra_fields)
|
||||
.desc_v2(desc_v2)
|
||||
.maybe_extra_fields(extra_fields)
|
||||
.build();
|
||||
|
||||
if !studio.cover.is_empty() {
|
||||
|
||||
Reference in new issue
Block a user