Skip to content

Let's use AI to Earn!

feat: 数据中心,添加快手获取数据的逻辑

gaoSir5cba2936e92c
diff --git a/electron/main/account/controller.ts b/electron/main/account/controller.ts
index 6e2f51fb..93a79ce1 100644
--- a/electron/main/account/controller.ts
+++ b/electron/main/account/controller.ts
@@ -173,7 +173,6 @@ export class AccountController {
const account = await this.accountService.getAccountById(id);
if (!account) return null;
-
return this.accountService.getAccountDashboard(account, time);
}
diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.ts
index 4050705c..e526c23e 100644
--- a/electron/main/plat/plat.type.ts
+++ b/electron/main/plat/plat.type.ts
@@ -35,6 +35,7 @@ export type DashboardData = {
like: number;
collect: number;
forward: number;
+ time?: string;
};
// 获取某个作品的数据返回值
diff --git a/electron/main/plat/platforms/Kwai/index.ts b/electron/main/plat/platforms/Kwai/index.ts
index 034a70a8..f63802a0 100644
--- a/electron/main/plat/platforms/Kwai/index.ts
+++ b/electron/main/plat/platforms/Kwai/index.ts
@@ -8,6 +8,7 @@
import { PlatformBase } from '../../PlatformBase';
import {
AccountInfoTypeRV,
+ DashboardData,
IAccountInfoParams,
IGetLocationDataParams,
IGetTopicsParams,
@@ -24,6 +25,7 @@ import { AccountType } from '../../../../../commont/AccountEnum';
import { AccountModel } from '../../../../db/models/account';
import { VisibleTypeEnum } from '../../../../../commont/publish/PublishEnum';
import { KwaiVisibleTypeEnum } from '../../../../plat/plat.common.type';
+import dayjs from 'dayjs';
export class Kwai extends PlatformBase {
constructor() {
@@ -100,7 +102,44 @@ export class Kwai extends PlatformBase {
}
async getDashboard(account: AccountModel, time: string[] = []) {
- return [];
+ const res = await kwaiPub.getHomeOverview(JSON.parse(account.loginCookie));
+ const dashboard: DashboardData[] = [];
+ const startTime = new Date(time[0]).getTime();
+ const endTime = new Date(time[1]).getTime();
+
+ res?.data?.data?.basicData?.map((v1, i1) => {
+ v1.trendData.map((v2, i2) => {
+ const currTime = dayjs(v2.date, 'YYYYMMDD').valueOf();
+ if (currTime >= startTime && currTime <= endTime) {
+ if (!dashboard[i2])
+ dashboard[i2] = {
+ comment: 0,
+ fans: 0,
+ forward: 0,
+ like: 0,
+ read: 0,
+ time: '',
+ collect: 0, // TODO: 获取收藏数据
+ };
+ const item = dashboard[i2];
+
+ item.time = v2.date;
+ if (v1.tab === 'LIKE') {
+ item.like = v2.count;
+ } else if (v1.tab === 'PURE_INCREASE_FAN') {
+ item.fans = v2.count;
+ } else if (v1.tab === ' COMMENT') {
+ item.comment = v2.count;
+ } else if (v1.tab === 'SHARE') {
+ item.forward = v2.count;
+ } else if (v1.tab === 'PLAY') {
+ item.read = v2.count;
+ }
+ }
+ });
+ });
+
+ return dashboard.filter(Boolean);
}
/**
diff --git a/electron/plat/Kwai/index.ts b/electron/plat/Kwai/index.ts
index 32abf55d..c8df55ea 100644
--- a/electron/plat/Kwai/index.ts
+++ b/electron/plat/Kwai/index.ts
@@ -1,6 +1,7 @@
import requestNet from '../requestNet';
import {
IGetHomeInfoResponse,
+ IGetHomeOverview,
IKwaiGetLocationsResponse,
IKwaiGetTopicsResponse,
IKwaiGetUsersResponse,
@@ -172,6 +173,20 @@ class KwaiPub {
});
}
+ async getHomeOverview(cookie: Electron.Cookie[]) {
+ return await requestNet<IGetHomeOverview>({
+ url: 'https://cp.kuaishou.com/rest/cp/creator/analysis/pc/home/author/overview?__NS_sig3=1c0c4b7b90498228d5414243bfb44c3f997dd5395d5d5f5f50515248',
+ method: 'POST',
+ headers: {
+ cookie: CookieToString(cookie),
+ },
+ body: {
+ timeType: 3,
+ 'kuaishou.web.cp.api_ph': '19af6d5b24cb170a03331ce9254b1204154c',
+ },
+ });
+ }
+
// 快手登录
login(): Promise<ILoginResponse> {
return new Promise(async (resolve, reject) => {
diff --git a/electron/plat/Kwai/kwai.type.ts b/electron/plat/Kwai/kwai.type.ts
index 9021d0b0..f40c2dc8 100644
--- a/electron/plat/Kwai/kwai.type.ts
+++ b/electron/plat/Kwai/kwai.type.ts
@@ -19,6 +19,30 @@ export interface IKwaiUserCommonResponse<T> {
message: string;
}
+export interface IGetHomeOverviewItem {
+ name: string;
+ tab: string;
+ sumCount: number;
+ endDayCount: number;
+ interpretDesc: string | null;
+ trendData: {
+ date: string;
+ count: number;
+ }[];
+ diagnoseResultType: string;
+}
+
+export interface IGetHomeOverview {
+ result: number;
+ currentTime: number;
+ 'host-name': string;
+ data: {
+ basicData: IGetHomeOverviewItem[];
+ dataUpdateTime: string;
+ };
+ message: string;
+}
+
export interface IGetHomeInfoResponse {
data: {
desc: string;
diff --git a/src/icp/account.ts b/src/icp/account.ts
index 72815650..85a47b30 100644
--- a/src/icp/account.ts
+++ b/src/icp/account.ts
@@ -8,6 +8,7 @@
import { AccountInfo } from '@/views/account/comment';
import { AccountStatus, AccountType } from '../../commont/AccountEnum';
+import { DashboardData } from '../views/statistics/comment';
export async function ipcUpdateAccountStatus(
accountId: number,
@@ -98,8 +99,7 @@ export async function icpGetAccountStatistics() {
// 获取账户统计
export async function icpGetAccountDashboard(id: number, time?: any) {
- console.log('time@@111:', time);
- const res = await window.ipcRenderer.invoke(
+ const res: DashboardData[] = await window.ipcRenderer.invoke(
'ICP_ACCOUNT_DASHBOARD',
id,
time,
diff --git a/src/views/statistics/comment.ts b/src/views/statistics/comment.ts
index cc13ebc5..b24d2abc 100644
--- a/src/views/statistics/comment.ts
+++ b/src/views/statistics/comment.ts
@@ -7,6 +7,7 @@
*/
import { AccountInfo } from '../account/comment';
+import { DashboardData as DashboardDataLast } from '../../../electron/main/plat/plat.type';
export interface StatisticsInfo {
accountTotal: number;
@@ -20,11 +21,4 @@ export interface StatisticsInfo {
}
// 获取平台账户统计信息返回值
-export type DashboardData = {
- fans: number;
- read: number;
- comment: number;
- like: number;
- collect: number;
- forward: number;
-};
+export type DashboardData = DashboardDataLast;