Skip to content

Let's use AI to Earn!

feat: 统一三方平台的列表分页都改为游标方式

牛文政1d171ac51f1e
diff --git a/electron/db/models/autoComment.ts b/electron/db/models/autoComment.ts
new file mode 100644
index 00000000..d872e30e
--- /dev/null
+++ b/electron/db/models/autoComment.ts
@@ -0,0 +1,101 @@
+/*
+ * @Author: nevin
+ * @Date: 2025-01-20 16:24:16
+ * @LastEditTime: 2025-02-17 12:24:49
+ * @LastEditors: nevin
+ * @Description: 自动评论 autoComment
+ */
+import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
+import { TempModel } from './temp';
+
+// 状态 未进行 进行中 失败 已完成
+export enum AutoCommentStatus {
+ UNDO = 0,
+ DOING = 1,
+ FAIL = 2,
+ DONE = 3,
+}
+
+@Entity({ name: 'autoComment' })
+export class AccountModel extends TempModel {
+ @PrimaryGeneratedColumn({ type: 'int', comment: 'id' })
+ id!: number;
+
+ @Column({ type: 'varchar', nullable: false, comment: '用户id' })
+ userId!: string;
+
+ @Column({ type: 'varchar', nullable: false, comment: '名称' })
+ title!: string;
+
+ @Column({ type: 'int', nullable: false, comment: '总点赞数量', default: 0 })
+ likeCount!: number;
+
+ @Column({
+ type: 'tinyint',
+ nullable: false,
+ comment: '登录状态,用于判断是否失效',
+ default: AccountStatus.USABLE,
+ })
+ status?: AccountStatus;
+
+ @Column({
+ type: 'varchar',
+ nullable: true,
+ comment: '其他token 目前抖音用',
+ default: '',
+ })
+ token?: string;
+
+ @Column({
+ type: 'datetime',
+ nullable: true,
+ comment: '登录时间',
+ })
+ loginTime?: Date;
+
+ @Column({ type: 'varchar', nullable: false, comment: '用户id' })
+ uid!: string;
+
+ // 账号
+ @Column({ type: 'varchar', nullable: false, comment: '账号' })
+ account!: string;
+
+ // 头像
+ @Column({ type: 'varchar', nullable: false, comment: '头像' })
+ avatar!: string;
+
+ // 昵称
+ @Column({ type: 'varchar', nullable: false, comment: '昵称' })
+ nickname!: string;
+
+ // 粉丝数量
+ @Column({ type: 'int', nullable: false, comment: '粉丝数量', default: 0 })
+ fansCount!: number;
+
+ // 阅读数量
+ @Column({ type: 'int', nullable: false, comment: '总阅读数量', default: 0 })
+ readCount!: number;
+
+ // 收藏数量
+ @Column({ type: 'int', nullable: false, comment: '总收藏数量', default: 0 })
+ collectCount!: number;
+
+ // 转发数量
+ @Column({ type: 'int', nullable: false, comment: '总转发数量', default: 0 })
+ forwardCount!: number;
+
+ // 评论数量
+ @Column({ type: 'int', nullable: false, comment: '总评论数量', default: 0 })
+ commentCount!: number;
+
+ @Column({ type: 'datetime', nullable: true, comment: '最后统计时间' })
+ lastStatsTime?: Date;
+
+ // 作品数量
+ @Column({ type: 'int', nullable: false, comment: '作品数量', default: 0 })
+ workCount?: number;
+
+ // 收益
+ @Column({ type: 'bigint', nullable: false, comment: '收益', default: 0 })
+ income?: number;
+}
diff --git a/electron/main/plat/PlatformBase.ts b/electron/main/plat/PlatformBase.ts
index dde0fa8d..54602d8f 100644
--- a/electron/main/plat/PlatformBase.ts
+++ b/electron/main/plat/PlatformBase.ts
@@ -17,7 +17,6 @@ import {
IGetUsersParams,
IGetUsersResponse,
IVideoPublishParams,
- PageInfo,
ResponsePageInfo,
StatisticsData,
VideoCallbackType,
@@ -76,11 +75,12 @@ export abstract class PlatformBase {
/**
* 获取作品列表
- * @param pageInfo
+ * @param account 账户
+ * @param pcursor 分页游标
*/
abstract getWorkList(
account: AccountModel,
- pageInfo: PageInfo,
+ pcursor?: string,
): Promise<{
list: WorkData[];
pageInfo: ResponsePageInfo;
@@ -94,11 +94,14 @@ export abstract class PlatformBase {
/**
* 获取评论列表
+ * @param account
+ * @param dataId
+ * @param pcursor
*/
abstract getCommentList(
account: AccountModel,
dataId: string,
- pageInfo: PageInfo,
+ pcursor?: string,
): Promise<{
list: CommentData[];
pageInfo: ResponsePageInfo;
diff --git a/electron/main/plat/index.ts b/electron/main/plat/index.ts
index bf60eed5..339dad05 100644
--- a/electron/main/plat/index.ts
+++ b/electron/main/plat/index.ts
@@ -15,7 +15,6 @@ import {
IAccountInfoParams,
IGetLocationDataParams,
IGetUsersParams,
- PageInfo,
} from './plat.type';
import { PublishVideoResult } from './module';
import { VideoModel } from '../../db/models/video';
@@ -155,9 +154,9 @@ class PlatController {
* @param account
* @param pageInfo
*/
- public async getWorkList(account: AccountModel, pageInfo: PageInfo) {
+ public async getWorkList(account: AccountModel, pcursor?: string) {
const platform = this.platforms.get(account.type)!;
- return await platform.getWorkList(account, pageInfo);
+ return await platform.getWorkList(account, pcursor);
}
/**
@@ -168,10 +167,10 @@ class PlatController {
public async getCommentList(
account: AccountModel,
dataId: string,
- pageInfo: PageInfo,
+ pcursor?: string,
) {
const platform = this.platforms.get(account.type)!;
- return await platform.getCommentList(account, dataId, pageInfo);
+ return await platform.getCommentList(account, dataId, pcursor);
}
/**
diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.ts
index 9c9971b7..e6705e78 100644
--- a/electron/main/plat/plat.type.ts
+++ b/electron/main/plat/plat.type.ts
@@ -11,21 +11,9 @@ import { DiffParmasType, ILableValue } from '../../db/models/video';
export type CookiesType = Electron.Cookie[];
-export enum PageType {
- paging = 'paging',
- cursor = 'cursor',
-}
-
-export interface PageInfo {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string;
-}
-
export interface ResponsePageInfo {
- pageType: PageType;
count?: number;
- hasMore?: boolean;
+ hasMore: boolean;
pcursor?: string;
}
diff --git a/electron/main/plat/platforms/Kwai/index.ts b/electron/main/plat/platforms/Kwai/index.ts
index ae63f79c..b5bff150 100644
--- a/electron/main/plat/platforms/Kwai/index.ts
+++ b/electron/main/plat/platforms/Kwai/index.ts
@@ -17,7 +17,6 @@ import {
IGetTopicsResponse,
IGetUsersParams,
IVideoPublishParams,
- PageType,
VideoCallbackType,
WorkData,
} from '../../plat.type';
@@ -157,14 +156,9 @@ export class Kwai extends PlatformBase {
* @param pageInfo
* @returns
*/
- async getWorkList(
- account: AccountModel,
- pageInfo: {
- pcursor?: string;
- },
- ) {
+ async getWorkList(account: AccountModel, pcursor?: string) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
- const res = await kwaiPub.getPhotoList(cookie, Number(pageInfo.pcursor));
+ const res = await kwaiPub.getPhotoList(cookie, Number(pcursor));
const photoList = res.data.data.photoList;
const list: WorkData[] = photoList.map((v) => {
@@ -180,7 +174,6 @@ export class Kwai extends PlatformBase {
return {
list,
pageInfo: {
- pageType: PageType.cursor,
hasMore: !!res.data.data.pcursor,
count: res.data.data.totalCount,
pcursor: res.data.data.pcursor + '',
@@ -202,15 +195,13 @@ export class Kwai extends PlatformBase {
async getCommentList(
account: AccountModel,
dataId: string,
- pageInfo: {
- pcursor?: string;
- },
+ pcursor?: string,
) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
const res = await kwaiPub.getCommentList(
cookie,
dataId,
- pageInfo?.pcursor ? Number.parseInt(pageInfo.pcursor) : undefined,
+ pcursor ? Number.parseInt(pcursor) : undefined,
);
const list: CommentData[] = res.data.data.list.map((v) => {
@@ -229,7 +220,6 @@ export class Kwai extends PlatformBase {
return {
list: list,
pageInfo: {
- pageType: PageType.cursor,
count: 0,
pcursor: res.data.data.pcursor + '',
hasMore: !!res.data.data.pcursor,
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index 01d726a8..459a590f 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -19,7 +19,6 @@ import {
IVideoPublishParams,
VideoCallbackType,
WorkData,
- PageType,
} from '../../plat.type';
import { PublishVideoResult } from '../../module';
import { douyinService } from '../../../../plat/douyin';
@@ -135,18 +134,12 @@ export class Douyin extends PlatformBase {
* @param pageInfo
* @returns
*/
- async getWorkList(
- account: AccountModel,
- pageInfo: {
- pcursor?: string;
- },
- ) {
+ async getWorkList(account: AccountModel, pcursor?: string) {
const res = await douyinService.getCreatorItems(
JSON.parse(account.loginCookie),
- pageInfo.pcursor,
+ pcursor,
);
- let pcursor = '';
const list: WorkData[] = [];
for (const element of res.data.item_info_list) {
list.push({
@@ -170,7 +163,6 @@ export class Douyin extends PlatformBase {
return {
list: list,
pageInfo: {
- pageType: PageType.cursor,
count: res.data.total_count,
hasMore: res.data.has_more,
pcursor: pcursor,
@@ -192,15 +184,12 @@ export class Douyin extends PlatformBase {
async getCommentList(
account: AccountModel,
dataId: string,
- pageInfo: {
- pageSize?: number;
- pcursor?: string;
- },
+ pcursor?: string,
) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
const res = await douyinService.getCreatorCommentList(cookie, dataId, {
- count: pageInfo?.pageSize || undefined,
- cursor: pageInfo?.pcursor || undefined,
+ count: pcursor ? 20 : undefined,
+ cursor: pcursor || undefined,
});
const list: CommentData[] = res.data.comment_info_list.map((v: any) => {
@@ -218,7 +207,6 @@ export class Douyin extends PlatformBase {
return {
list,
pageInfo: {
- pageType: PageType.cursor,
count: res.data.total_count,
pcursor: res.data.cursor + '',
hasMore: res.data.has_more,
diff --git a/electron/main/plat/platforms/wxSph/index.ts b/electron/main/plat/platforms/wxSph/index.ts
index 3cb389ae..fb0fd0fe 100644
--- a/electron/main/plat/platforms/wxSph/index.ts
+++ b/electron/main/plat/platforms/wxSph/index.ts
@@ -16,7 +16,6 @@ import {
IGetTopicsResponse,
IGetUsersParams,
IVideoPublishParams,
- PageType,
VideoCallbackType,
WorkData,
} from '../../plat.type';
@@ -126,18 +125,12 @@ export class WxSph extends PlatformBase {
* @param pageInfo
* @returns
*/
- async getWorkList(
- account: AccountModel,
- pageInfo: {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string;
- },
- ) {
+ async getWorkList(account: AccountModel, pcursor?: string) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
+ const pageNo = pcursor ? Number.parseInt(pcursor) : 1;
const res = await shipinhaoService.getPostList(cookie, {
- pageNo: pageInfo.pageNo || 1,
- pageSize: pageInfo.pageSize || 20,
+ pageNo: pageNo,
+ pageSize: 20,
});
const listData: WorkData[] = res.list.map((item) => {
@@ -154,8 +147,10 @@ export class WxSph extends PlatformBase {
return {
list: listData,
pageInfo: {
- pageType: PageType.paging,
count: res.totalCount,
+ hasMore: res.totalCount > res.list.length * pageNo,
+ pcursor:
+ res.totalCount > res.list.length * pageNo ? pageNo + 1 + '' : '',
},
};
}
@@ -174,16 +169,10 @@ export class WxSph extends PlatformBase {
async getCommentList(
account: AccountModel,
dataId: string,
- pageInfo: {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string;
- },
+ pcursor?: string,
) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
const res = await shipinhaoService.getCommentList(cookie, dataId);
- console.log('----- res ----', res);
-
const dataList = res.comment.map((item) => {
return {
dataId: item.commentId,
@@ -198,8 +187,12 @@ export class WxSph extends PlatformBase {
return {
list: dataList,
pageInfo: {
- pageType: PageType.paging,
count: res.commentCount,
+ hasMore: res.commentCount > res.comment.length * Number(pcursor),
+ pcursor:
+ res.commentCount > res.comment.length * Number(pcursor)
+ ? Number(pcursor) + 1 + ''
+ : '',
},
};
}
diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.ts
index 3f2f8922..d30bab9b 100644
--- a/electron/main/plat/platforms/xhs/index.ts
+++ b/electron/main/plat/platforms/xhs/index.ts
@@ -17,7 +17,6 @@ import {
IGetTopicsResponse,
IGetUsersParams,
IVideoPublishParams,
- PageType,
VideoCallbackType,
WorkData,
} from '../../plat.type';
@@ -136,16 +135,13 @@ export class Xhs extends PlatformBase {
* @param pageInfo
* @returns
*/
- async getWorkList(
- account: AccountModel,
- pageInfo: {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string;
- },
- ) {
+ async getWorkList(account: AccountModel, pcursor?: string) {
+ const pageNo = pcursor ? Number.parseInt(pcursor) : 0;
+
+ // TODO: 小红书的分页每页数量?
+ const pageSize = 20;
const cookie: CookiesType = JSON.parse(account.loginCookie);
- const res = await xiaohongshuService.getWorks(cookie);
+ const res = await xiaohongshuService.getWorks(cookie, pageNo);
const list: WorkData[] = res.data.data.notes.map((v) => ({
dataId: v.id,
@@ -157,11 +153,14 @@ export class Xhs extends PlatformBase {
coverUrl: v.images_list[0]?.url || '',
}));
+ const count = res.data.data.tags[0].notes_count;
+ const hasMore = count > pageSize * (pageNo + 1);
return {
list,
pageInfo: {
- pageType: PageType.cursor,
- count: res.data.data.tags[0].notes_count,
+ count,
+ hasMore,
+ pcursor: hasMore ? pageNo + 1 + '' : '',
},
};
}
@@ -180,11 +179,7 @@ export class Xhs extends PlatformBase {
async getCommentList(
account: AccountModel,
dataId: string,
- pageInfo: {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string;
- },
+ pcursor?: string,
) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
@@ -203,7 +198,6 @@ export class Xhs extends PlatformBase {
return {
list: list,
pageInfo: {
- pageType: PageType.cursor,
hasMore: res.data.data.has_more,
pcursor: res.data.data.cursor,
},
diff --git a/electron/main/reply/controller.ts b/electron/main/reply/controller.ts
index 8ca9c503..48ee3bc5 100644
--- a/electron/main/reply/controller.ts
+++ b/electron/main/reply/controller.ts
@@ -9,7 +9,7 @@ import { AccountService } from '../account/service';
import { toolsApi } from '../api/tools';
import { Controller, Icp, Inject } from '../core/decorators';
import platController from '../plat';
-import type { CommentData, PageInfo } from '../plat/plat.type';
+import type { CommentData } from '../plat/plat.type';
import { ReplyService } from './service';
@Controller()
@@ -27,7 +27,7 @@ export class ReplyController {
async getCreatorList(
event: Electron.IpcMainInvokeEvent,
accountId: number,
- pageInfo: PageInfo,
+ pcursor?: string,
) {
const account = await this.accountService.getAccountById(accountId);
@@ -37,7 +37,7 @@ export class ReplyController {
count: 0,
};
- const res = await platController.getWorkList(account, pageInfo);
+ const res = await platController.getWorkList(account, pcursor);
return res;
}
@@ -50,12 +50,12 @@ export class ReplyController {
event: Electron.IpcMainInvokeEvent,
accountId: number,
dataId: string,
- pageInfo: PageInfo,
+ pcursor?: string,
): Promise<any> {
const account = await this.accountService.getAccountById(accountId);
if (!account) return null;
- const res = await platController.getCommentList(account, dataId, pageInfo);
+ const res = await platController.getCommentList(account, dataId, pcursor);
return res;
}
@@ -98,9 +98,7 @@ export class ReplyController {
const {
list,
pageInfo: { pcursor, hasMore },
- } = await platController.getCommentList(account, dataId, {
- pcursor: thePcursor,
- });
+ } = await platController.getCommentList(account, dataId, thePcursor);
list.forEach((item) => {
list.push(item);
diff --git a/src/icp/reply.ts b/src/icp/reply.ts
index 2cff2690..1ea339d8 100644
--- a/src/icp/reply.ts
+++ b/src/icp/reply.ts
@@ -38,14 +38,7 @@ export enum PageType {
/**
* 获取作品列表
*/
-export async function icpCreatorList(
- accountId: number,
- pageInfo: {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string; // 分页游标
- },
-) {
+export async function icpCreatorList(accountId: number, pcursor?: string) {
const res: {
list: WorkData[];
pageInfo: {
@@ -54,7 +47,7 @@ export async function icpCreatorList(
hasMore?: boolean;
pcursor?: string;
};
- } = await window.ipcRenderer.invoke('ICP_CREATOR_LIST', accountId, pageInfo);
+ } = await window.ipcRenderer.invoke('ICP_CREATOR_LIST', accountId, pcursor);
return res;
}
@@ -64,21 +57,21 @@ export async function icpCreatorList(
export async function icpGetCommentList(
accountId: number,
dataId: string,
- pageInfo: {
- pageNo?: number;
- pageSize?: number;
- pcursor?: string;
- },
+ pcursor?: string,
) {
const res: {
list: CommentData[];
pageInfo: {
- pageType: PageType;
count?: number;
- hasMore?: boolean;
+ hasMore: boolean;
pcursor?: string;
};
- } = await window.ipcRenderer.invoke('ICP_COMMENT_LIST', accountId, dataId);
+ } = await window.ipcRenderer.invoke(
+ 'ICP_COMMENT_LIST',
+ accountId,
+ dataId,
+ pcursor,
+ );
return res;
}
diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsx
index 4caba8bd..213718ff 100644
--- a/src/views/reply/index.tsx
+++ b/src/views/reply/index.tsx
@@ -34,10 +34,7 @@ export default function Page() {
}
setWordList([]);
- const res = await icpCreatorList(activeAccountId, {
- pageNo: 1,
- pageSize: 10,
- });
+ const res = await icpCreatorList(activeAccountId);
setWordList(res.list);
}
@@ -46,7 +43,7 @@ export default function Page() {
* 获取评论列表
*/
async function getCommentList(dataId: string) {
- const res = await icpGetCommentList(activeAccountId, dataId, {});
+ const res = await icpGetCommentList(activeAccountId, dataId);
setCommentList(res.list);
}