MCPcopy Create free account
hub / github.com/acking-you/static_flow / fetch_article_view_trend

Function fetch_article_view_trend

crates/frontend/src/api.rs:651–722  ·  view source on GitHub ↗

Fetch article view trend points.

(
    id: &str,
    granularity: &str,
    days: Option<usize>,
    day: Option<&str>,
)

Source from the content-addressed store, hash-verified

649
650/// Fetch article view trend points.
651pub async fn fetch_article_view_trend(
652 id: &str,
653 granularity: &str,
654 days: Option<usize>,
655 day: Option<&str>,
656) -> Result<ArticleViewTrendResponse, String> {
657 #[cfg(feature = "mock")]
658 {
659 if granularity.eq_ignore_ascii_case("hour") {
660 return Ok(ArticleViewTrendResponse {
661 article_id: id.to_string(),
662 timezone: "Asia/Shanghai".to_string(),
663 granularity: "hour".to_string(),
664 day: Some(day.unwrap_or("2026-02-15").to_string()),
665 total_views: 128,
666 points: (0..24)
667 .map(|hour| ArticleViewPoint {
668 key: format!("{hour:02}"),
669 views: ((hour * 3 + 5) % 18) as u32,
670 })
671 .collect(),
672 });
673 }
674
675 let window = days.unwrap_or(30).max(1);
676 Ok(ArticleViewTrendResponse {
677 article_id: id.to_string(),
678 timezone: "Asia/Shanghai".to_string(),
679 granularity: "day".to_string(),
680 day: None,
681 total_views: 128,
682 points: (0..window)
683 .map(|offset| ArticleViewPoint {
684 key: format!("2026-02-{:02}", offset + 1),
685 views: ((offset * 5 + 9) % 40) as u32,
686 })
687 .collect(),
688 })
689 }
690
691 #[cfg(not(feature = "mock"))]
692 {
693 let mut url = format!(
694 "{}/articles/{}/view-trend?granularity={}",
695 API_BASE,
696 urlencoding::encode(id),
697 urlencoding::encode(granularity),
698 );
699 if let Some(days) = days {
700 url.push_str(&format!("&days={days}"));
701 }
702 if let Some(day) = day {
703 url.push_str(&format!("&day={}", urlencoding::encode(day)));
704 }
705
706 let response = api_get(&url)
707 .header("Cache-Control", "no-cache, no-store, max-age=0")
708 .header("Pragma", "no-cache")

Callers 1

article_detail_pageFunction · 0.85

Calls 2

api_getFunction · 0.85
okMethod · 0.80

Tested by

no test coverage detected