Skip to content

Commit

Permalink
fix critical time parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub committed Oct 12, 2024
1 parent cc7c339 commit c70ecb7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/controller/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use axum_extra::{
};
use cached::proc_macro::cached;
use garde::Validate;
use jiff::Timestamp;
use jiff::{fmt::rfc2822, Timestamp};
use reqwest::Client;
use rinja_axum::{into_response, Template};
use serde::Deserialize;
Expand All @@ -35,7 +35,7 @@ use std::{
collections::{BTreeMap, HashMap},
sync::LazyLock,
};
use tracing::error;
use tracing::{error, warn};

struct SourceItem {
link: String,
Expand All @@ -48,9 +48,10 @@ impl TryFrom<rss::Item> for SourceItem {
type Error = AppError;
fn try_from(rss: rss::Item) -> Result<Self, Self::Error> {
let updated = if let Some(ref pub_date) = rss.pub_date {
if let Ok(ts) = pub_date.parse::<Timestamp>() {
ts.as_second()
if let Ok(ts) = rfc2822::parse(pub_date) {
ts.timestamp().as_second()
} else {
warn!("invalid pub_date: {}, rss: {:?}", pub_date, rss.link);
Timestamp::now().as_second()
}
} else {
Expand Down Expand Up @@ -273,7 +274,8 @@ pub(crate) async fn feed(
}
}

item_ids.sort_unstable_by(|a, b| a.1.cmp(&b.1));
item_ids.sort_unstable_by(|a, b| a.1.cmp(&b.1).then(a.0.cmp(&b.0)));

let n = site_config.per_page;
let anchor = params.anchor.unwrap_or(0);
let is_desc = params.is_desc.unwrap_or(true);
Expand Down

0 comments on commit c70ecb7

Please sign in to comment.