use axum::{
Json,
extract::{Path, Query, State},
http::HeaderMap,
};
use super::super::support::{FetchResult, fetch_error_response, xiaohongshu_fetcher};
use super::types::{XiaohongshuHomeFeedQuery, XiaohongshuNoteCommentsQuery, XiaohongshuNoteQuery};
use crate::platforms::xiaohongshu::{
XiaohongshuCommentsOptions, XiaohongshuEmojiList, XiaohongshuHomeFeed,
XiaohongshuHomeFeedOptions, XiaohongshuNoteComments, XiaohongshuNoteDetail,
XiaohongshuNoteDetailOptions,
};
use crate::server::state::AppState;
pub async fn xiaohongshu_home_feed(
Query(query): Query<XiaohongshuHomeFeedQuery>,
headers: HeaderMap,
State(state): State<AppState>,
) -> FetchResult<XiaohongshuHomeFeed> {
xiaohongshu_fetcher(&state, &headers)
.fetch_home_feed(&XiaohongshuHomeFeedOptions {
cursor_score: query.cursor_score,
num: query.num,
refresh_type: query.refresh_type,
note_index: query.note_index,
category: query.category,
search_key: query.search_key,
})
.await
.map(Json)
.map_err(fetch_error_response)
}
pub async fn xiaohongshu_note_detail(
Path(note_id): Path<String>,
Query(query): Query<XiaohongshuNoteQuery>,
headers: HeaderMap,
State(state): State<AppState>,
) -> FetchResult<XiaohongshuNoteDetail> {
xiaohongshu_fetcher(&state, &headers)
.fetch_note_detail(&XiaohongshuNoteDetailOptions {
note_id,
xsec_token: query.xsec_token,
})
.await
.map(Json)
.map_err(fetch_error_response)
}
pub async fn xiaohongshu_note_comments(
Path(note_id): Path<String>,
Query(query): Query<XiaohongshuNoteCommentsQuery>,
headers: HeaderMap,
State(state): State<AppState>,
) -> FetchResult<XiaohongshuNoteComments> {
xiaohongshu_fetcher(&state, &headers)
.fetch_note_comments(&XiaohongshuCommentsOptions {
note_id,
cursor: query.cursor,
xsec_token: query.xsec_token,
})
.await
.map(Json)
.map_err(fetch_error_response)
}
pub async fn xiaohongshu_emoji_list(
headers: HeaderMap,
State(state): State<AppState>,
) -> FetchResult<XiaohongshuEmojiList> {
xiaohongshu_fetcher(&state, &headers)
.fetch_emoji_list()
.await
.map(Json)
.map_err(fetch_error_response)
}