Files
social-mcp/web/src/api/endpoints.ts
T
kurihada 5a1f88de95 集成互动功能到帖子详情,删除独立互动页面
- 点赞/收藏改为纯 toggle,移除 unlike/unfavorite 参数
- 帖子详情 API 返回 isLiked/isFavorited 状态(SVG xlink:href 检测)
- 前端两个切换按钮替代原四个独立按钮
- 修复 __INITIAL_STATE__ Vue 响应式代理序列化(structuredClone + fallback)
- 修复 overlay 场景下点赞按钮误点 feed 列表元素(.last() 定位)
- 删除 InteractionsPage 及相关路由/导航
2026-03-02 14:39:15 +08:00

114 lines
3.3 KiB
TypeScript

import { apiFetch } from './client';
import type {
LoginStatus,
QRCodeResult,
Feed,
FeedDetail,
UserProfile,
SearchFilters,
HealthResponse,
ApiResponse,
PublishResult,
CommentResult,
} from './types';
// Health (no auth required)
export const getHealth = () =>
apiFetch<HealthResponse>('/health');
// Login
export const getLoginStatus = () =>
apiFetch<ApiResponse<LoginStatus>>('/api/xhs/login/status');
export const getLoginQRCode = () =>
apiFetch<ApiResponse<QRCodeResult>>('/api/xhs/login/qrcode');
export const deleteCookies = () =>
apiFetch<ApiResponse<{ message: string }>>('/api/xhs/login/cookies', { method: 'DELETE' });
// Lightweight cookie check (no browser opened)
export const checkLoginCookie = () =>
apiFetch<ApiResponse<{ hasCookies: boolean }>>('/api/xhs/login/cookie-check');
// Feeds
export const listFeeds = () =>
apiFetch<ApiResponse<Feed[]>>('/api/xhs/feeds');
export const searchFeeds = (keyword: string, filters?: SearchFilters) =>
apiFetch<ApiResponse<Feed[]>>('/api/xhs/search', {
method: 'POST',
body: JSON.stringify({ keyword, filters }),
});
export const getFeedDetail = (feedId: string, xsecToken: string, loadAllComments = false) =>
apiFetch<ApiResponse<FeedDetail>>('/api/xhs/feeds/detail', {
method: 'POST',
body: JSON.stringify({ feed_id: feedId, xsec_token: xsecToken, load_all_comments: loadAllComments }),
});
// User
export const getUserProfile = (userId: string, xsecToken: string) =>
apiFetch<ApiResponse<UserProfile>>('/api/xhs/user/profile', {
method: 'POST',
body: JSON.stringify({ user_id: userId, xsec_token: xsecToken }),
});
// Publish
export const publishImage = (data: {
title: string;
content: string;
images: string[];
tags?: string[];
schedule_at?: string;
is_original?: boolean;
visibility?: 'public' | 'private' | 'friends';
}) =>
apiFetch<ApiResponse<PublishResult>>('/api/xhs/publish/image', {
method: 'POST',
body: JSON.stringify(data),
});
export const publishVideo = (data: {
title: string;
content: string;
video: string;
tags?: string[];
schedule_at?: string;
visibility?: 'public' | 'private' | 'friends';
}) =>
apiFetch<ApiResponse<PublishResult>>('/api/xhs/publish/video', {
method: 'POST',
body: JSON.stringify(data),
});
// Interactions
export const postComment = (feedId: string, xsecToken: string, content: string) =>
apiFetch<ApiResponse<CommentResult>>('/api/xhs/comment', {
method: 'POST',
body: JSON.stringify({ feed_id: feedId, xsec_token: xsecToken, content }),
});
export const replyComment = (data: {
feed_id: string;
xsec_token: string;
content: string;
comment_id?: string;
user_id?: string;
}) =>
apiFetch<ApiResponse<CommentResult>>('/api/xhs/comment/reply', {
method: 'POST',
body: JSON.stringify(data),
});
export const toggleLike = (feedId: string, xsecToken: string) =>
apiFetch<ApiResponse<{ success: boolean; liked: boolean }>>('/api/xhs/like', {
method: 'POST',
body: JSON.stringify({ feed_id: feedId, xsec_token: xsecToken }),
});
export const toggleFavorite = (feedId: string, xsecToken: string) =>
apiFetch<ApiResponse<{ success: boolean; favorited: boolean }>>('/api/xhs/favorite', {
method: 'POST',
body: JSON.stringify({ feed_id: feedId, xsec_token: xsecToken }),
});