publish-api.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * 视频发布模块 - API
  3. */
  4. import { get, post, del } from './request';
  5. // ============ 类型定义 ============
  6. export interface PlatformAccount {
  7. platform: 'douyin' | 'kuaishou' | 'bilibili';
  8. nickname: string;
  9. avatar: string;
  10. isValid: boolean;
  11. createdAt: string;
  12. }
  13. export interface PublishTask {
  14. id: number;
  15. userId: number;
  16. videoProjectId: number;
  17. platform: 'douyin' | 'kuaishou' | 'bilibili';
  18. title: string;
  19. description?: string;
  20. tags?: string[];
  21. coverUrl?: string;
  22. videoUrl?: string;
  23. status: 'pending' | 'uploading' | 'success' | 'failed';
  24. errorMsg?: string;
  25. publishedUrl?: string;
  26. createdAt: string;
  27. }
  28. export interface VideoPreview {
  29. title: string;
  30. description: string;
  31. videoUrl: string;
  32. coverUrl?: string;
  33. }
  34. // ============ 平台账号 API ============
  35. /**
  36. * 获取已绑定的平台账号
  37. */
  38. export async function getPlatformAccounts(): Promise<PlatformAccount[]> {
  39. return get<PlatformAccount[]>('/publish/accounts');
  40. }
  41. /**
  42. * 绑定平台账号(保存登录凭证)
  43. */
  44. export async function bindPlatformAccount(data: {
  45. platform: 'douyin' | 'kuaishou' | 'bilibili';
  46. cookies: string;
  47. headers?: Record<string, string>;
  48. nickname?: string;
  49. avatar?: string;
  50. }): Promise<{ platform: string; nickname: string }> {
  51. return post('/publish/accounts', data);
  52. }
  53. /**
  54. * 解绑平台账号
  55. */
  56. export async function unbindPlatformAccount(
  57. platform: 'douyin' | 'kuaishou' | 'bilibili'
  58. ): Promise<void> {
  59. return del(`/publish/accounts/${platform}`);
  60. }
  61. /**
  62. * 验证账号是否有效
  63. */
  64. export async function validatePlatformAccount(
  65. platform: 'douyin' | 'kuaishou' | 'bilibili'
  66. ): Promise<{ valid: boolean; nickname?: string; error?: string }> {
  67. return post(`/publish/accounts/${platform}/validate`);
  68. }
  69. // ============ 发布任务 API ============
  70. /**
  71. * 获取发布任务列表
  72. */
  73. export async function getPublishTasks(options?: {
  74. platform?: string;
  75. status?: string;
  76. page?: number;
  77. pageSize?: number;
  78. }): Promise<{ items: PublishTask[]; total: number }> {
  79. return get('/publish/tasks', options as Record<string, unknown>);
  80. }
  81. /**
  82. * 获取单个发布任务
  83. */
  84. export async function getPublishTask(id: number): Promise<PublishTask> {
  85. return get<PublishTask>(`/publish/tasks/${id}`);
  86. }
  87. /**
  88. * 创建发布任务并立即发布
  89. */
  90. export async function createAndPublishTask(data: {
  91. videoProjectId?: number;
  92. videoUrl?: string;
  93. platform: 'douyin' | 'kuaishou' | 'bilibili';
  94. title: string;
  95. description?: string;
  96. tags?: string[];
  97. coverUrl?: string;
  98. }): Promise<{
  99. taskId: number;
  100. success: boolean;
  101. publishedUrl?: string;
  102. error?: string;
  103. }> {
  104. return post('/publish/tasks', data);
  105. }
  106. /**
  107. * 重新发布任务
  108. */
  109. export async function republishTask(
  110. taskId: number
  111. ): Promise<{ success: boolean; publishedUrl?: string; error?: string }> {
  112. return post(`/publish/tasks/${taskId}/publish`);
  113. }
  114. // ============ 辅助 API ============
  115. /**
  116. * 获取视频发布预览信息
  117. */
  118. export async function getVideoPublishPreview(
  119. projectId: number
  120. ): Promise<VideoPreview> {
  121. return get<VideoPreview>(`/publish/video/${projectId}/preview`);
  122. }