Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
fix: 数据中心当用户未登录时报错处理
gaoSir25ea3e1a45af
diff --git a/electron/main/account/service.ts b/electron/main/account/service.tsindex a466b406..c44172ff 100644--- a/electron/main/account/service.ts+++ b/electron/main/account/service.ts@@ -106,8 +106,10 @@ export class AccountService {};for (const element of accountList) {- const ret = await platController.getStatistics(element);- res.fansCount += ret.fansCount || 0;+ const ret = await platController.getStatistics(element).catch(err => {+ console.error(err);+ });+ res.fansCount += ret?.fansCount || 0;}return res;diff --git a/electron/plat/Kwai/index.ts b/electron/plat/Kwai/index.tsindex 1c36d5a5..ab12c99a 100644--- a/electron/plat/Kwai/index.ts+++ b/electron/plat/Kwai/index.ts@@ -1,4 +1,3 @@-import { Browser, chromium, webkit } from 'playwright';import requestNet from '../requestNet';import {IKwaiGetLocationsResponse,@@ -6,14 +5,12 @@ import {IKwaiGetUsersResponse,IKwaiPubVideoParams,IKwaiUserInfoResponse,- ILoginResponse-} from "./kwai.type";+ ILoginResponse,+} from './kwai.type';import { cookieToPlaywright, CookieToString } from '../utils';import { BrowserWindow } from 'electron';import { KwaiVisibleTypeEnum } from '../plat.common.type';-import { getChromiumPath } from '../../util/chromium';-import os from 'os';-import path from 'path';+import { getBrowser } from '../coomont';class KwaiPub {// 发布视频@@ -23,26 +20,10 @@ class KwaiPub {}> {const { callback } = params;return new Promise(async (resolve) => {- let browser: Browser;+ const browser = await getBrowser();try {- const platform = os.platform();+ if (!browser) throw 'playwright 初始化失败!';callback(5, '正在加载...');- if (platform === 'darwin') {- browser = await webkit.launch({- headless: import.meta.env.MODE !== 'development',- executablePath: path.join(- process.resourcesPath,- 'bin',- 'webkit',- 'pw_run.sh',- ),- });- } else {- browser = await chromium.launch({- headless: import.meta.env.MODE !== 'development',- executablePath: getChromiumPath(),- });- }const context = await browser.newContext();callback(10);diff --git a/electron/plat/coomont.ts b/electron/plat/coomont.tsnew file mode 100644index 00000000..037fc6c8--- /dev/null+++ b/electron/plat/coomont.ts@@ -0,0 +1,31 @@+import os from 'os';+import { Browser, chromium, webkit } from 'playwright';+import path from 'path';+import { getChromiumPath } from '../util/chromium';++export const getBrowser = async () => {+ let browser: Browser;+ const platform = os.platform();+ try {+ if (platform === 'darwin') {+ browser = await webkit.launch({+ headless: import.meta.env.MODE !== 'development',+ executablePath: path.join(+ process.resourcesPath,+ 'bin',+ 'webkit',+ 'pw_run.sh',+ ),+ });+ } else {+ browser = await chromium.launch({+ headless: import.meta.env.MODE !== 'development',+ executablePath: getChromiumPath(),+ });+ }+ return browser;+ } catch (e) {+ console.error(e);+ return undefined;+ }+};diff --git a/electron/plat/shipinhao/index.ts b/electron/plat/shipinhao/index.tsindex 8c72be7d..a16eb630 100644--- a/electron/plat/shipinhao/index.ts+++ b/electron/plat/shipinhao/index.ts@@ -130,7 +130,7 @@ export class ShipinhaoService {fansCount: res.data.finderUser.fansCount ?? 0,});} else {- reject(res.data.errMsg ?? '未知错误');+ reject(res.data?.errMsg ?? '未知错误');}} catch (err) {reject(err);@@ -261,7 +261,7 @@ export class ShipinhaoService {});}} else {- reject(res.data.errMsg ?? '未知错误');+ reject(res.data?.errMsg ?? '未知错误');}} catch (err) {reject(err);diff --git a/src/views/account/index.tsx b/src/views/account/index.tsxindex 1feabba4..ba3911a7 100644--- a/src/views/account/index.tsx+++ b/src/views/account/index.tsx@@ -12,13 +12,21 @@ import styles from './account.module.scss';import AccountSidebar from '@/views/account/components/AccountSidebar';import WebView from '@/components/WebView';import { AccountInfo, AccountPlatInfoMap } from '@/views/account/comment';+import { icpGetLocation } from '../../icp/view';const Account: React.FC = () => {const [activeAccountId, setActiveAccountId] = useState(-1);const [accountInfo, setAccountInfo] = useState<AccountInfo>();+ function getLocation() {+ icpGetLocation().then((res) => {+ console.log(res);+ });+ }+return (<div className={styles.account}>+ <button onClick={getLocation}>start</button><AccountSidebaractiveAccountId={activeAccountId}onAccountChange={useCallback((info) => {diff --git a/src/views/statistics/index.tsx b/src/views/statistics/index.tsxindex 95930aff..92f6c1e7 100644--- a/src/views/statistics/index.tsx+++ b/src/views/statistics/index.tsx@@ -245,6 +245,7 @@ const Statistics = () => {async function getAccountStatistics() {setDashboardData([]);const res: StatisticsInfo = await icpGetAccountStatistics();+ console.log(res);setStatisticsInfo(res);// 获取到账号列表后,遍历获取每个账号的看板数据if (res.list && res.list.length > 0) {@@ -264,7 +265,7 @@ const Statistics = () => {const dataAll = [];// 获取到账号列表后,遍历获取每个账号的看板数据- if (res.list && res.list.length > 0) {+ if (res?.list && res.list.length > 0) {// 只获取选中账户的数据const selectedAccountsList = res.list.filter((account: any) =>selectedAccounts.includes(account.id),