chore: 程序开始时打印欢迎信息,调整日志和构建流 (#285)
This commit is contained in:
2
.github/workflows/build-binary.yaml
vendored
2
.github/workflows/build-binary.yaml
vendored
@@ -68,6 +68,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-tags: true
|
||||||
- name: Download Web Build Artifact
|
- name: Download Web Build Artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "Bili-Sync", version = version(), about, long_about = None)]
|
#[command(name = "Bili-Sync", version = detail_version(), about, long_about = None)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[arg(short, long, env = "SCAN_ONLY")]
|
#[arg(short, long, env = "SCAN_ONLY")]
|
||||||
pub scan_only: bool,
|
pub scan_only: bool,
|
||||||
@@ -14,19 +16,22 @@ mod built_info {
|
|||||||
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version() -> String {
|
pub fn version() -> Cow<'static, str> {
|
||||||
let version = if let (Some(git_version), Some(git_dirty)) = (built_info::GIT_VERSION, built_info::GIT_DIRTY) {
|
if let (Some(git_version), Some(git_dirty)) = (built_info::GIT_VERSION, built_info::GIT_DIRTY) {
|
||||||
format!("{}{}", git_version, if git_dirty { "-dirty" } else { "" })
|
Cow::Owned(format!("{}{}", git_version, if git_dirty { "-dirty" } else { "" }))
|
||||||
} else {
|
} else {
|
||||||
built_info::PKG_VERSION.to_owned()
|
Cow::Borrowed(built_info::PKG_VERSION)
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detail_version() -> String {
|
||||||
format!(
|
format!(
|
||||||
"{}
|
"{}
|
||||||
Architecture: {}-{}
|
Architecture: {}-{}
|
||||||
Author: {}
|
Author: {}
|
||||||
Built Time: {}
|
Built Time: {}
|
||||||
Rustc Version: {}",
|
Rustc Version: {}",
|
||||||
version,
|
version(),
|
||||||
built_info::CFG_OS,
|
built_info::CFG_OS,
|
||||||
built_info::CFG_TARGET_ARCH,
|
built_info::CFG_TARGET_ARCH,
|
||||||
built_info::PKG_AUTHORS,
|
built_info::PKG_AUTHORS,
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ pub static CONFIG_DIR: Lazy<PathBuf> =
|
|||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
fn load_config() -> Config {
|
fn load_config() -> Config {
|
||||||
|
info!("开始加载配置文件..");
|
||||||
let config = Config::load().unwrap_or_else(|err| {
|
let config = Config::load().unwrap_or_else(|err| {
|
||||||
if err
|
if err
|
||||||
.downcast_ref::<std::io::Error>()
|
.downcast_ref::<std::io::Error>()
|
||||||
@@ -47,7 +48,7 @@ fn load_config() -> Config {
|
|||||||
{
|
{
|
||||||
panic!("加载配置文件失败,错误为: {err}");
|
panic!("加载配置文件失败,错误为: {err}");
|
||||||
}
|
}
|
||||||
warn!("配置文件不存在,使用默认配置...");
|
warn!("配置文件不存在,使用默认配置..");
|
||||||
Config::default()
|
Config::default()
|
||||||
});
|
});
|
||||||
info!("配置文件加载完毕,覆盖刷新原有配置");
|
info!("配置文件加载完毕,覆盖刷新原有配置");
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ mod item;
|
|||||||
|
|
||||||
use crate::adapter::Args;
|
use crate::adapter::Args;
|
||||||
use crate::bilibili::{CollectionItem, Credential, DanmakuOption, FilterOption};
|
use crate::bilibili::{CollectionItem, Credential, DanmakuOption, FilterOption};
|
||||||
|
pub use crate::config::clap::version;
|
||||||
pub use crate::config::global::{ARGS, CONFIG, CONFIG_DIR, TEMPLATE};
|
pub use crate::config::global::{ARGS, CONFIG, CONFIG_DIR, TEMPLATE};
|
||||||
use crate::config::item::{ConcurrentLimit, deserialize_collection_list, serialize_collection_list};
|
use crate::config::item::{ConcurrentLimit, deserialize_collection_list, serialize_collection_list};
|
||||||
pub use crate::config::item::{NFOTimeType, PathSafeTemplate, RateLimit, WatchLaterConfig};
|
pub use crate::config::item::{NFOTimeType, PathSafeTemplate, RateLimit, WatchLaterConfig};
|
||||||
|
|||||||
@@ -59,10 +59,11 @@ fn spawn_task(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 初始化日志系统,加载命令行参数和配置文件
|
/// 初始化日志系统,打印欢迎信息,加载配置文件
|
||||||
fn init() {
|
fn init() {
|
||||||
Lazy::force(&ARGS);
|
|
||||||
init_logger(&ARGS.log_level);
|
init_logger(&ARGS.log_level);
|
||||||
|
info!("欢迎使用 Bili-Sync,当前程序版本:{}", config::version());
|
||||||
|
info!("项目地址:https://github.com/amtoaer/bili-sync");
|
||||||
Lazy::force(&CONFIG);
|
Lazy::force(&CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ pub async fn http_server(database_connection: Arc<DatabaseConnection>) -> Result
|
|||||||
let listener = tokio::net::TcpListener::bind(&CONFIG.bind_address)
|
let listener = tokio::net::TcpListener::bind(&CONFIG.bind_address)
|
||||||
.await
|
.await
|
||||||
.context("bind address failed")?;
|
.context("bind address failed")?;
|
||||||
info!("开始监听 http 服务: http://{}", CONFIG.bind_address);
|
info!("开始运行管理页: http://{}", CONFIG.bind_address);
|
||||||
Ok(axum::serve(listener, ServiceExt::<Request>::into_make_service(app)).await?)
|
Ok(axum::serve(listener, ServiceExt::<Request>::into_make_service(app)).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ pub async fn video_downloader(connection: Arc<DatabaseConnection>) {
|
|||||||
let bili_client = BiliClient::new();
|
let bili_client = BiliClient::new();
|
||||||
let video_sources = CONFIG.as_video_sources();
|
let video_sources = CONFIG.as_video_sources();
|
||||||
loop {
|
loop {
|
||||||
|
info!("开始执行本轮视频下载任务..");
|
||||||
'inner: {
|
'inner: {
|
||||||
match bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) {
|
match bili_client.wbi_img().await.map(|wbi_img| wbi_img.into()) {
|
||||||
Ok(Some(mixin_key)) => bilibili::set_global_mixin_key(mixin_key),
|
Ok(Some(mixin_key)) => bilibili::set_global_mixin_key(mixin_key),
|
||||||
|
|||||||
Reference in New Issue
Block a user