| 1 | /** |
| 2 | * 浏览器插件相关类型定义 |
| 3 | */ |
| 4 | |
| 5 | import type { |
| 6 | PublishParams as BasePublishParams, |
| 7 | ProgressEvent, |
| 8 | PublishTask, |
| 9 | PublishTaskListConfig, |
| 10 | } from './index' |
| 11 | import type { PlatAccountInfo, WxSphLoginStatus, XhsLoginStatus } from './plat.type' |
| 12 | import { PlatType } from '@/app/config/platConfig' |
| 13 | |
| 14 | // 导出任务相关类型 |
| 15 | export type { |
| 16 | PlatformPublishMode, |
| 17 | PlatformPublishTask, |
| 18 | PlatformPublishUserAction, |
| 19 | PublishTask, |
| 20 | PublishTaskListConfig, |
| 21 | UnifiedPublishParams, |
| 22 | } from './publishTask.types' |
| 23 | export { PlatformTaskStatus } from './publishTask.types' |
| 24 | |
| 25 | /** |
| 26 | * 发布结果 |
| 27 | */ |
| 28 | interface PublishResult { |
| 29 | success: boolean |
| 30 | workId?: string |
| 31 | shareLink?: string |
| 32 | publishTime?: number |
| 33 | failReason?: string |
| 34 | errorCode?: string |
| 35 | platformData?: unknown |
| 36 | } |
| 37 | |
| 38 | export interface WxSphLinkAnchor { |
| 39 | mediaMd5sum?: string |
| 40 | videoClipTaskId?: string |
| 41 | scheduledTime?: number |
| 42 | } |
| 43 | |
| 44 | export interface WxSphStartLinkPollingParams { |
| 45 | recordId: string |
| 46 | mediaMd5sum: string |
| 47 | apiBaseUrl?: string |
| 48 | authToken?: string |
| 49 | accountId?: string |
| 50 | videoClipTaskId?: string |
| 51 | scheduledTime?: number |
| 52 | } |
| 53 | |
| 54 | export interface WxSphStartLinkPollingResult { |
| 55 | success: boolean |
| 56 | status?: 'pending' | 'ready' | 'failed' |
| 57 | error?: string |
| 58 | code?: string |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * 导出基础类型 |
| 63 | */ |
| 64 | export type { PlatAccountInfo, ProgressEvent, PublishResult, WxSphLoginStatus, XhsLoginStatus } |
| 65 | |
| 66 | /** |
| 67 | * 插件连接状态 |
| 68 | */ |
| 69 | export enum PluginStatus { |
| 70 | /** 未检测 */ |
| 71 | UNKNOWN = 'UNKNOWN', |
| 72 | /** 检测中 */ |
| 73 | CHECKING = 'CHECKING', |
| 74 | /** 已就绪(已安装且已授权) */ |
| 75 | READY = 'READY', |
| 76 | /** 已安装但未授权 */ |
| 77 | INSTALLED_NO_PERMISSION = 'INSTALLED_NO_PERMISSION', |
| 78 | /** 未安装 */ |
| 79 | NOT_INSTALLED = 'NOT_INSTALLED', |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * 插件支持的平台列表 |
| 84 | */ |
| 85 | export const PLUGIN_SUPPORTED_PLATFORMS = [PlatType.Xhs, PlatType.WxSph] as const |
| 86 | |
| 87 | /** |
| 88 | * 插件支持的平台类型(直接复用 PlatType) |
| 89 | */ |
| 90 | export type PluginPlatformType = (typeof PLUGIN_SUPPORTED_PLATFORMS)[number] |
| 91 | |
| 92 | /** 视频号登录过期错误码 */ |
| 93 | export const WX_SPH_LOGIN_EXPIRED_CODE = 'WX_SPH_LOGIN_EXPIRED' as const |
| 94 | |
| 95 | /** |
| 96 | * 发布参数(扩展基础类型,添加 platform 字段) |
| 97 | */ |
| 98 | export interface PublishParams extends BasePublishParams { |
| 99 | platform: PluginPlatformType |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * 进度回调函数类型 |
| 104 | */ |
| 105 | export type ProgressCallback = (event: ProgressEvent) => void |
| 106 | |
| 107 | /** |
| 108 | * 权限检查结果 |
| 109 | */ |
| 110 | export interface PermissionCheckResult { |
| 111 | /** 是否已授予所有必需权限 */ |
| 112 | granted: boolean |
| 113 | /** 是否已授予站点访问权限 */ |
| 114 | hostAccess?: boolean |
| 115 | /** 已授予的权限列表 */ |
| 116 | permissions?: string[] |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * HTTP 请求方法类型 |
| 121 | */ |
| 122 | export type HttpMethod = 'GET' | 'POST' | 'DELETE' |
| 123 | |
| 124 | /** |
| 125 | * 平台通用请求参数 |
| 126 | */ |
| 127 | export interface PlatformRequestParams { |
| 128 | /** API 路径 */ |
| 129 | path: string |
| 130 | /** HTTP 方法,默认 POST */ |
| 131 | method?: HttpMethod |
| 132 | /** 请求数据 */ |
| 133 | data?: any |
| 134 | /** 额外请求头 */ |
| 135 | headers?: Record<string, string> |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * 插件通用代理请求参数 |
| 140 | */ |
| 141 | export interface PluginProxyRequestParams { |
| 142 | /** 完整请求 URL */ |
| 143 | url: string |
| 144 | /** 额外请求头 */ |
| 145 | headers?: Record<string, string> |
| 146 | /** 请求体;为空时插件按 GET,有值时按 POST */ |
| 147 | body?: unknown |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * 插件通用代理响应 |
| 152 | */ |
| 153 | export interface PluginProxyResponse { |
| 154 | /** 实际响应 URL(重定向后) */ |
| 155 | url: string |
| 156 | /** HTTP 状态码 */ |
| 157 | status: number |
| 158 | /** HTTP 状态描述 */ |
| 159 | statusText: string |
| 160 | /** 是否为 2xx */ |
| 161 | ok: boolean |
| 162 | /** 响应头 */ |
| 163 | headers: Record<string, string> |
| 164 | /** 原始响应体文本 */ |
| 165 | body: string |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * 抖音交互操作参数 |
| 170 | */ |
| 171 | export interface DouyinInteractionParams { |
| 172 | /** 操作类型:点赞、收藏、评论 */ |
| 173 | action: 'like' | 'favorite' | 'comment' |
| 174 | /** 作品ID */ |
| 175 | workId: string |
| 176 | /** 目标状态:true=执行操作,false=取消操作 */ |
| 177 | targetState: boolean |
| 178 | /** 评论内容(action 为 comment 时必填) */ |
| 179 | content?: string |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * 抖音私信参数 |
| 184 | */ |
| 185 | export interface DouyinDirectMessageParams { |
| 186 | /** 作品ID(二选一) */ |
| 187 | workId?: string |
| 188 | /** 作者链接(二选一) */ |
| 189 | authorUrl?: string |
| 190 | /** 私信内容 */ |
| 191 | content: string |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * 抖音交互操作结果 |
| 196 | */ |
| 197 | export interface DouyinInteractionResult { |
| 198 | /** 是否成功 */ |
| 199 | success: boolean |
| 200 | /** 提示信息 */ |
| 201 | message?: string |
| 202 | /** 错误信息 */ |
| 203 | error?: string |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * 插件版本信息 |
| 208 | */ |
| 209 | export interface WxSphLocationSearchParams { |
| 210 | query: string |
| 211 | longitude?: number |
| 212 | latitude?: number |
| 213 | } |
| 214 | |
| 215 | export interface WxSphLocationItem { |
| 216 | uid: string |
| 217 | name: string |
| 218 | longitude: number |
| 219 | latitude: number |
| 220 | address?: string |
| 221 | province?: string |
| 222 | city?: string |
| 223 | region?: string |
| 224 | fullAddress?: string |
| 225 | poiCheckSum?: string |
| 226 | } |
| 227 | |
| 228 | export interface WxSphEventInfo { |
| 229 | eventTopicId: string |
| 230 | eventName: string |
| 231 | eventCreatorNickname?: string |
| 232 | eventAttendCount?: number |
| 233 | } |
| 234 | |
| 235 | export interface PluginVersionInfo { |
| 236 | /** 插件版本号 */ |
| 237 | version: string |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * 插件 API 接口定义 |
| 242 | */ |
| 243 | export interface AIToEarnPluginAPI { |
| 244 | /** |
| 245 | * 检查插件权限 |
| 246 | * @returns Promise<权限检查结果> |
| 247 | */ |
| 248 | checkPermission: () => Promise<PermissionCheckResult> |
| 249 | |
| 250 | /** |
| 251 | * 登录到指定平台 |
| 252 | * @param platform 平台类型 |
| 253 | * @returns Promise<账号信息> |
| 254 | */ |
| 255 | login: (platform: PluginPlatformType) => Promise<PlatAccountInfo> |
| 256 | |
| 257 | /** |
| 258 | * 发布内容到指定平台 |
| 259 | * @param params 发布参数 |
| 260 | * @param onProgress 进度回调函数 |
| 261 | * @returns Promise<发布结果> |
| 262 | */ |
| 263 | publish: (params: PublishParams, onProgress?: ProgressCallback) => Promise<PublishResult> |
| 264 | |
| 265 | /** |
| 266 | * 通用代理请求 |
| 267 | * 直接请求任意 URL,并返回原始响应文本和状态信息 |
| 268 | * 旧版本插件可能不存在该方法,调用前需要兼容判断 |
| 269 | */ |
| 270 | proxyRequest?: (params: PluginProxyRequestParams) => Promise<PluginProxyResponse> |
| 271 | |
| 272 | /** |
| 273 | * 小红书通用请求 |
| 274 | * 自动处理签名,返回原始响应 |
| 275 | * @param params 请求参数 |
| 276 | * @returns Promise<响应数据> |
| 277 | */ |
| 278 | xhsRequest: <T = any>(params: PlatformRequestParams) => Promise<T> |
| 279 | |
| 280 | /** |
| 281 | * 抖音通用请求 |
| 282 | * 返回原始响应 |
| 283 | * @param params 请求参数 |
| 284 | * @returns Promise<响应数据> |
| 285 | */ |
| 286 | douyinRequest: <T = any>(params: PlatformRequestParams) => Promise<T> |
| 287 | |
| 288 | wxSphSearchLocation?: (params: WxSphLocationSearchParams) => Promise<WxSphLocationItem[]> |
| 289 | |
| 290 | wxSphSearchActivity?: (params: { query: string }) => Promise<WxSphEventInfo[]> |
| 291 | |
| 292 | wxSphStartLinkPolling?: ( |
| 293 | params: WxSphStartLinkPollingParams, |
| 294 | ) => Promise<WxSphStartLinkPollingResult> |
| 295 | |
| 296 | /** |
| 297 | * 抖音交互操作(自动化方案) |
| 298 | * 支持点赞、收藏、评论 |
| 299 | * @param params 交互参数 |
| 300 | * @returns Promise<交互结果> |
| 301 | */ |
| 302 | douyinInteraction: (params: DouyinInteractionParams) => Promise<DouyinInteractionResult> |
| 303 | |
| 304 | /** |
| 305 | * 抖音私信(自动化方案) |
| 306 | * 根据作品ID或作者链接发送私信 |
| 307 | * @param params 私信参数 |
| 308 | * @returns Promise<私信结果> |
| 309 | */ |
| 310 | douyinDirectMessage: (params: DouyinDirectMessageParams) => Promise<DouyinInteractionResult> |
| 311 | |
| 312 | /** |
| 313 | * 获取插件版本号 |
| 314 | * 旧版本插件可能不存在该方法,调用前需要兼容判断 |
| 315 | */ |
| 316 | getVersion?: () => Promise<PluginVersionInfo> |
| 317 | |
| 318 | /** |
| 319 | * 统一互动操作(跨平台点赞、收藏、评论) |
| 320 | * 支持抖音和小红书,使用自动化方案 |
| 321 | * 旧版本插件可能不存在该方法,调用前需要兼容判断 |
| 322 | */ |
| 323 | unifiedInteraction?: (params: { |
| 324 | platform: string |
| 325 | action: 'like' | 'favorite' | 'comment' |
| 326 | /** 作品链接(完整 URL) */ |
| 327 | workLink: string |
| 328 | targetState: boolean |
| 329 | content?: string |
| 330 | needScreenshot?: boolean |
| 331 | }) => Promise<{ |
| 332 | success: boolean |
| 333 | currentState?: boolean |
| 334 | message?: string |
| 335 | screenshot?: string |
| 336 | needHumanAssist?: boolean |
| 337 | verificationReason?: string |
| 338 | error?: string |
| 339 | }> |
| 340 | |
| 341 | /** |
| 342 | * 远程自动化执行 |
| 343 | * 固定流程:打开页面 -> 执行代码 -> 截图 -> 返回结果 |
| 344 | * 旧版本插件可能不存在该方法,调用前需要兼容判断 |
| 345 | */ |
| 346 | remoteAutomationRun?: (params: { |
| 347 | url: string |
| 348 | code: string |
| 349 | timeout?: number |
| 350 | needScreenshot?: boolean |
| 351 | }) => Promise<{ |
| 352 | success: boolean |
| 353 | message?: string |
| 354 | error?: string |
| 355 | result?: unknown |
| 356 | executionTime?: number |
| 357 | screenshot?: string |
| 358 | }> |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * 扩展 Window 接口 |
| 363 | */ |
| 364 | declare global { |
| 365 | interface Window { |
| 366 | // @ts-ignore |
| 367 | AIToEarnPlugin?: AIToEarnPluginAPI |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * 插件 Store 状态接口(只定义属性,方法在 store 中实现) |
| 373 | */ |
| 374 | export interface PluginStore { |
| 375 | /** 插件连接状态 */ |
| 376 | status: PluginStatus |
| 377 | /** 轮询定时器 ID */ |
| 378 | pollingTimer: NodeJS.Timeout | null |
| 379 | /** 是否正在发布 */ |
| 380 | isPublishing: boolean |
| 381 | /** 当前发布进度 */ |
| 382 | publishProgress: ProgressEvent | null |
| 383 | /** 发布任务列表 */ |
| 384 | publishTasks?: PublishTask[] |
| 385 | /** 任务列表配置 */ |
| 386 | taskListConfig?: PublishTaskListConfig |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * 操作结果类型 |
| 391 | */ |
| 392 | export interface OperationResult<T = any> { |
| 393 | success: boolean |
| 394 | data?: T |
| 395 | error?: string |
| 396 | } |
| 397 |