From f37d9af6782cba56223be1fbef6d3829a02f3140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Fri, 5 Dec 2025 01:56:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=20API=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=B1=BB=E5=9E=8B=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E7=9A=84=E6=83=85=E5=86=B5=20(#552)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/bili_sync/src/bilibili/dynamic.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/bili_sync/src/bilibili/dynamic.rs b/crates/bili_sync/src/bilibili/dynamic.rs index 4176b5d..f1be72e 100644 --- a/crates/bili_sync/src/bilibili/dynamic.rs +++ b/crates/bili_sync/src/bilibili/dynamic.rs @@ -1,7 +1,6 @@ use anyhow::{Context, Result, anyhow}; use async_stream::try_stream; -use chrono::serde::ts_seconds; -use chrono::{DateTime, Utc}; +use chrono::DateTime; use futures::Stream; use reqwest::Method; use serde_json::Value; @@ -14,12 +13,6 @@ pub struct Dynamic<'a> { credential: &'a Credential, } -#[derive(Debug, serde::Deserialize)] -pub struct DynamicItemPublished { - #[serde(with = "ts_seconds")] - pub_ts: DateTime, -} - impl<'a> Dynamic<'a> { pub fn new(client: &'a BiliClient, upper_id: String, credential: &'a Credential) -> Self { Self { @@ -64,13 +57,17 @@ impl<'a> Dynamic<'a> { if item["type"].as_str().is_none_or(|t| t != "DYNAMIC_TYPE_AV") { continue; } - let published: DynamicItemPublished = serde_json::from_value(item["modules"]["module_author"].take()) - .with_context(|| "failed to parse published time")?; + let pub_ts = item["modules"]["module_author"]["pub_ts"].take(); + let pub_dt = pub_ts + .as_i64() + .or_else(|| pub_ts.as_str().and_then(|s| s.parse::().ok())) + .and_then(DateTime::from_timestamp_secs) + .with_context(|| format!("invalid pub_ts: {:?}", pub_ts))?; let mut video_info: VideoInfo = serde_json::from_value(item["modules"]["module_dynamic"]["major"]["archive"].take())?; // 这些地方不使用 let else 是因为 try_stream! 宏不支持 if let VideoInfo::Dynamic { ref mut pubtime, .. } = video_info { - *pubtime = published.pub_ts; + *pubtime = pub_dt; yield video_info; } else { Err(anyhow!("video info is not dynamic"))?;