119 lines
3.3 KiB
TypeScript
119 lines
3.3 KiB
TypeScript
import { get, post, del } from './request';
|
||
import {
|
||
LikeTask,
|
||
CreateLikeTaskData,
|
||
UpdateLikeTaskData,
|
||
LikeRecord,
|
||
ApiResponse,
|
||
PaginatedResponse
|
||
} from '@/types/auto-like';
|
||
|
||
// 获取自动点赞任务列表
|
||
export async function fetchAutoLikeTasks(): Promise<LikeTask[]> {
|
||
try {
|
||
const res = await get<ApiResponse<PaginatedResponse<LikeTask>>>('/v1/workbench/list?type=1&page=1&limit=100');
|
||
|
||
if (res.code === 200 && res.data) {
|
||
return res.data.list || [];
|
||
}
|
||
return [];
|
||
} catch (error) {
|
||
console.error('获取自动点赞任务失败:', error);
|
||
return [];
|
||
}
|
||
}
|
||
|
||
// 获取单个任务详情
|
||
export async function fetchAutoLikeTaskDetail(id: string): Promise<LikeTask | null> {
|
||
try {
|
||
console.log(`Fetching task detail for id: ${id}`);
|
||
// 使用any类型来处理可能的不同响应结构
|
||
const res = await get<any>(`/v1/workbench/detail?id=${id}`);
|
||
console.log('Task detail API response:', res);
|
||
|
||
if (res.code === 200) {
|
||
// 检查响应中的data字段
|
||
if (res.data) {
|
||
// 如果data是对象,直接返回
|
||
if (typeof res.data === 'object') {
|
||
return res.data;
|
||
} else {
|
||
console.error('Task detail API response data is not an object:', res.data);
|
||
return null;
|
||
}
|
||
} else {
|
||
console.error('Task detail API response missing data field:', res);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
console.error('Task detail API error:', res.msg || 'Unknown error');
|
||
return null;
|
||
} catch (error) {
|
||
console.error('获取任务详情失败:', error);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
// 创建自动点赞任务
|
||
export async function createAutoLikeTask(data: CreateLikeTaskData): Promise<ApiResponse> {
|
||
return post('/v1/workbench/create', {
|
||
...data,
|
||
type: 1 // 自动点赞类型
|
||
});
|
||
}
|
||
|
||
// 更新自动点赞任务
|
||
export async function updateAutoLikeTask(data: UpdateLikeTaskData): Promise<ApiResponse> {
|
||
return post('/v1/workbench/update', {
|
||
...data,
|
||
type: 1 // 自动点赞类型
|
||
});
|
||
}
|
||
|
||
// 删除自动点赞任务
|
||
export async function deleteAutoLikeTask(id: string): Promise<ApiResponse> {
|
||
return del('/v1/workbench/delete', { params: { id } });
|
||
}
|
||
|
||
// 切换任务状态
|
||
export async function toggleAutoLikeTask(id: string, status: string): Promise<ApiResponse> {
|
||
return post('/v1/workbench/update-status', { id, status });
|
||
}
|
||
|
||
// 复制自动点赞任务
|
||
export async function copyAutoLikeTask(id: string): Promise<ApiResponse> {
|
||
return post('/v1/workbench/copy', { id });
|
||
}
|
||
|
||
// 获取点赞记录
|
||
export async function fetchLikeRecords(
|
||
workbenchId: string,
|
||
page: number = 1,
|
||
limit: number = 20,
|
||
keyword?: string
|
||
): Promise<PaginatedResponse<LikeRecord>> {
|
||
try {
|
||
const params = new URLSearchParams({
|
||
workbenchId,
|
||
page: page.toString(),
|
||
limit: limit.toString()
|
||
});
|
||
|
||
if (keyword) {
|
||
params.append('keyword', keyword);
|
||
}
|
||
|
||
const res = await get<ApiResponse<PaginatedResponse<LikeRecord>>>(`/v1/workbench/like-records?${params.toString()}`);
|
||
|
||
if (res.code === 200 && res.data) {
|
||
return res.data;
|
||
}
|
||
return { list: [], total: 0, page, limit };
|
||
} catch (error) {
|
||
console.error('获取点赞记录失败:', error);
|
||
return { list: [], total: 0, page, limit };
|
||
}
|
||
}
|
||
|
||
export type { LikeTask, LikeRecord, CreateLikeTaskData };
|