import { request } from "./request"; import { LikeTask, CreateLikeTaskData, UpdateLikeTaskData, LikeRecord, ApiResponse, PaginatedResponse, } from "@/types/auto-like"; // 获取自动点赞任务列表 export async function fetchAutoLikeTasks(): Promise { try { const res = await request>>({ url: "/v1/workbench/list", method: "GET", params: { 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 { try { console.log(`Fetching task detail for id: ${id}`); const res = await request({ url: "/v1/workbench/detail", method: "GET", params: { id }, }); console.log("Task detail API response:", res); if (res.code === 200) { if (res.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 { return request({ url: "/v1/workbench/create", method: "POST", data: { ...data, type: 1, // 自动点赞类型 }, }); } // 更新自动点赞任务 export async function updateAutoLikeTask( data: UpdateLikeTaskData ): Promise { return request({ url: "/v1/workbench/update", method: "POST", data: { ...data, type: 1, // 自动点赞类型 }, }); } // 删除自动点赞任务 export async function deleteAutoLikeTask(id: string): Promise { return request({ url: "/v1/workbench/delete", method: "DELETE", params: { id }, }); } // 切换任务状态 export async function toggleAutoLikeTask( id: string, status: string ): Promise { return request({ url: "/v1/workbench/update-status", method: "POST", data: { id, status }, }); } // 复制自动点赞任务 export async function copyAutoLikeTask(id: string): Promise { return request({ url: "/v1/workbench/copy", method: "POST", data: { id }, }); } // 获取点赞记录 export async function fetchLikeRecords( workbenchId: string, page: number = 1, limit: number = 20, keyword?: string ): Promise> { try { const params: any = { workbenchId, page: page.toString(), limit: limit.toString(), }; if (keyword) { params.keyword = keyword; } const res = await request>>({ url: "/v1/workbench/records", method: "GET", params, }); if (res.code === 200 && res.data) { return res.data; } return { list: [], total: 0, page: 1, limit: 20, }; } catch (error) { console.error("获取点赞记录失败:", error); return { list: [], total: 0, page: 1, limit: 20, }; } }