Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 【小红书】捕获账号异常逻辑完成。
gaoSirf215728e8319
diff --git a/commont/AccountEnum.ts b/commont/AccountEnum.tsindex ef40d624..c34504bc 100644--- a/commont/AccountEnum.ts+++ b/commont/AccountEnum.ts@@ -14,4 +14,12 @@ export enum AccountStatus {DISABLE = 1,}+// 小红书账号异常状态+export enum XhsAccountAbnormal {+ // 账号正常+ Normal = 1,+ // 账号异常(无法发布视频)+ Abnormal = 2,+}+export const defaultAccountGroupId = 1;diff --git a/electron/db/models/account.ts b/electron/db/models/account.tsindex bc3fe15a..84add540 100644--- a/electron/db/models/account.ts+++ b/electron/db/models/account.ts@@ -7,7 +7,7 @@*/import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';import { TempModel } from './temp';-import { AccountStatus, AccountType } from '../../../commont/AccountEnum';+import {AccountStatus, AccountType, XhsAccountAbnormal} from '../../../commont/AccountEnum';@Entity({ name: 'account' })export class AccountModel extends TempModel {@@ -93,6 +93,12 @@ export class AccountModel extends TempModel {@Column({ type: 'bigint', nullable: false, comment: '收益', default: 0 })income?: number;+ // 账号异常状态,异常状态无法发视频+ @Column({ type: 'json', nullable: true })+ abnormalStatus?: {+ [AccountType.Xhs]: XhsAccountAbnormal;+ };+// 登录状态,判断是否失效@Column({type: 'tinyint',diff --git a/electron/main/account/controller.ts b/electron/main/account/controller.tsindex d01801fe..cc4513db 100644--- a/electron/main/account/controller.ts+++ b/electron/main/account/controller.ts@@ -90,14 +90,13 @@ export class AccountController {// 取出cookieif (!accountInfo.loginCookie) return accountInfo;- const res = await platController- .platLoginCheck(pType, accountInfo)- .catch(() => false);- console.log(res);- const account = await this.accountService.updateAccountStatus(- accountInfo!.id!,- res ? AccountStatus.USABLE : AccountStatus.DISABLE,- );+ const res = await platController.platLoginCheck(pType, accountInfo);++ await this.accountService.updateAccountInfo(accountInfo.id, {+ status: res.online ? AccountStatus.USABLE : AccountStatus.DISABLE,+ ...(res.online && typeof res.account === 'object' ? res.account : {}),+ });+ const account = await this.accountService.getAccountById(accountInfo!.id!);windowOperate.sendRenderMsg(SendChannelEnum.AccountLoginFinish, account);return account || accountInfo;}diff --git a/electron/main/account/service.ts b/electron/main/account/service.tsindex ea5f738d..c6d5bde6 100644--- a/electron/main/account/service.ts+++ b/electron/main/account/service.ts@@ -212,7 +212,7 @@ export class AccountService {// 更新用户信息async updateAccountInfo(id: number, data: Partial<AccountModel>) {- await this.accountRepository.update(id, data);+ return await this.accountRepository.update(id, data);}// 更新账户的统计信息diff --git a/electron/main/plat/PlatformBase.ts b/electron/main/plat/PlatformBase.tsindex 6c75066a..e207440b 100644--- a/electron/main/plat/PlatformBase.ts+++ b/electron/main/plat/PlatformBase.ts@@ -50,7 +50,12 @@ export abstract class PlatformBase {* 登录状态检测* @param account*/- abstract loginCheck(account: AccountModel): Promise<boolean>;+ abstract loginCheck(account: AccountModel): Promise<{+ // true=在线,false=离线+ online: boolean;+ // 要额外更新的账户数据+ account?: Partial<AccountModel>;+ }>;/*** 获取该平台的用户信息diff --git a/electron/main/plat/platforms/Kwai/index.ts b/electron/main/plat/platforms/Kwai/index.tsindex c5bf94f3..9b3ecb57 100644--- a/electron/main/plat/platforms/Kwai/index.ts+++ b/electron/main/plat/platforms/Kwai/index.ts@@ -485,14 +485,18 @@ export class Kwai extends PlatformBase {return false;}- async loginCheck(account: AccountModel): Promise<boolean> {+ async loginCheck(account: AccountModel) {+ let online = false;try {const res = await kwaiPub.getAccountInfo(JSON.parse(account.loginCookie));- return !(res?.status !== 200 || !res?.data?.data?.userInfo?.userId);+ online = !(res?.status !== 200 || !res?.data?.data?.userInfo?.userId);} catch (e) {console.warn('快手登录状态检测错误:', e);- return false;+ online = false;}+ return {+ online,+ };}async getTopics({diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.tsindex 56579857..1755748e 100644--- a/electron/main/plat/platforms/douyin/index.ts+++ b/electron/main/plat/platforms/douyin/index.ts@@ -82,8 +82,11 @@ export class Douyin extends PlatformBase {}}- async loginCheck(account: AccountModel): Promise<boolean> {- return await douyinService.checkLoginStatus(account.loginCookie);+ async loginCheck(account: AccountModel) {+ const online = await douyinService.checkLoginStatus(account.loginCookie);+ return {+ online,+ };}async getAccountInfo(params: IAccountInfoParams): Promise<AccountInfoTypeRV> {diff --git a/electron/main/plat/platforms/wxSph/index.ts b/electron/main/plat/platforms/wxSph/index.tsindex 0dc4081f..f4959c83 100644--- a/electron/main/plat/platforms/wxSph/index.ts+++ b/electron/main/plat/platforms/wxSph/index.ts@@ -68,8 +68,11 @@ export class WxSph extends PlatformBase {}}- async loginCheck(account: AccountModel): Promise<boolean> {- return await shipinhaoService.checkLoginStatus(account.loginCookie);+ async loginCheck(account: AccountModel) {+ const online = await shipinhaoService.checkLoginStatus(account.loginCookie);+ return {+ online,+ };}async getAccountInfo(params: IAccountInfoParams): Promise<AccountInfoTypeRV> {diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.tsindex 1c68e370..797e3459 100644--- a/electron/main/plat/platforms/xhs/index.ts+++ b/electron/main/plat/platforms/xhs/index.ts@@ -73,16 +73,27 @@ export class Xhs extends PlatformBase {}}- async loginCheck(account: AccountModel): Promise<boolean> {+ async loginCheck(account: AccountModel) {try {const userInfo = await xiaohongshuService.getUserInfo(JSON.parse(account.loginCookie),);- return !!userInfo.authorId;+ return {+ online: !!userInfo.authorId,+ account: {+ avatar: userInfo.avatar,+ nickname: userInfo.nickname,+ fansCount: userInfo.fansCount,+ abnormalStatus: {+ [AccountType.Xhs]: userInfo.diagnosis_status,+ },+ },+ };} catch (error) {- console.log('-----xhs loginCheck-- error', error);-- return false;+ console.error(error);+ return {+ online: false,+ };}}diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.tsindex 6a00d689..8ba24a9f 100644--- a/electron/plat/xiaohongshu/index.ts+++ b/electron/plat/xiaohongshu/index.ts@@ -264,6 +264,7 @@ export class XiaohongshuService {nickname: userInfo.data.nickname || '',avatar: userInfo.data.imageb || '',fansCount: fansInfo.data.fans_count || 0,+ diagnosis_status: fansInfo.data.diagnosis_status,};}diff --git a/src/views/account/components/AccountSidebar/AccountSidebar.tsx b/src/views/account/components/AccountSidebar/AccountSidebar.tsxindex 5867d945..0f8df389 100644--- a/src/views/account/components/AccountSidebar/AccountSidebar.tsx+++ b/src/views/account/components/AccountSidebar/AccountSidebar.tsx@@ -2,23 +2,27 @@ import {ForwardedRef,forwardRef,memo,+ useMemo,useRef,useState,- useMemo,} from 'react';import styles from './AccountSidebar.module.scss';import { AccountInfo, AccountPlatInfoMap } from '../../comment';import { Avatar, Button, Collapse, message, Popover, Tooltip } from 'antd';import { accountLogin, acpAccountLoginCheck } from '@/icp/account';import AddAccountModal from '../AddAccountModal';-import { AccountStatus, defaultAccountGroupId } from '@@/AccountEnum';+import {+ AccountStatus,+ AccountType,+ defaultAccountGroupId,+ XhsAccountAbnormal,+} from '@@/AccountEnum';import Icon, {CheckCircleOutlined,PlusOutlined,UserOutlined,WarningOutlined,} from '@ant-design/icons';-import useCssVariables from '../../../../hooks/useCssVariables';import PubAccountDetModule, {IPubAccountDetModuleRef,} from '../../../publish/components/PubAccountDetModule/PubAccountDetModule';@@ -27,6 +31,7 @@ import { useAccountStore } from '@/store/account';import UserManageModal, { IUserManageModalRef } from './UserManageModal';import ProxyManage from '@/views/account/components/AccountSidebar/ProxyManage';import ProxyIcon from '@/assets/svgs/proxy.svg?react';+import { AccountModel } from '../../../../../electron/db/models/account';export interface IAccountSidebarRef {}@@ -39,9 +44,39 @@ export interface IAccountSidebarProps {excludePlatforms?: string[];}+const AccountStatusView = ({ account }: { account: AccountModel }) => {+ if (+ account.type === AccountType.Xhs &&+ account.abnormalStatus &&+ account.abnormalStatus[AccountType.Xhs] === XhsAccountAbnormal.Abnormal+ ) {+ return (+ <Tooltip title="账号状态异常,无法发布作品,请检查后重试!">+ <WarningOutlined style={{ color: 'var(--warningColor)' }} />+ 异常+ </Tooltip>+ );+ }++ if (account.status === AccountStatus.USABLE) {+ return (+ <>+ <CheckCircleOutlined style={{ color: 'var(--successColor)' }} />+ 在线+ </>+ );+ }++ return (+ <>+ <WarningOutlined style={{ color: 'var(--warningColor)' }} />+ 离线+ </>+ );+};+const AccountPopoverInfo = ({ accountInfo }: { accountInfo: AccountInfo }) => {const platInfo = AccountPlatInfoMap.get(accountInfo.type)!;- const cssVars = useCssVariables();const [detLoading, setDetLoading] = useState(false);return (@@ -69,19 +104,7 @@ const AccountPopoverInfo = ({ accountInfo }: { accountInfo: AccountInfo }) => {<div className="accountPopoverInfo-item"><p>登录状态:</p><p>- {accountInfo.status === AccountStatus.USABLE ? (- <>- <CheckCircleOutlined- style={{ color: cssVars['--successColor'] }}- />- 在线- </>- ) : (- <>- <WarningOutlined style={{ color: cssVars['--warningColor'] }} />- 离线- </>- )}+ <AccountStatusView account={accountInfo} /><Buttontype="link"style={{ padding: '0 0 0 5px' }}@@ -235,7 +258,11 @@ const AccountSidebar = memo(className={['accountList-item',`${activeAccountId === account.id ? 'accountList-item--active' : ''}`,- account.status === AccountStatus.DISABLE &&+ // 失效状态+ (account.status === AccountStatus.DISABLE ||+ (account.abnormalStatus &&+ account.abnormalStatus[AccountType.Xhs] ===+ XhsAccountAbnormal.Abnormal)) &&'accountList-item--disable',].join(' ')}key={account.id}diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsxindex 484f934e..a8c24a02 100644--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx@@ -55,7 +55,7 @@ import {NoticeType,useBellMessageStroe,} from '../../../../../../store/bellMessageStroe';-import { signInApi, SignInType } from '@/api/signIn';+import { signInApi } from '@/api/signIn';export interface IVideoPubSetModalRef {}diff --git a/src/views/publish/hooks/usePubParamsVerify.tsx b/src/views/publish/hooks/usePubParamsVerify.tsxindex 065791f0..bf301fb6 100644--- a/src/views/publish/hooks/usePubParamsVerify.tsx+++ b/src/views/publish/hooks/usePubParamsVerify.tsx@@ -6,7 +6,11 @@ import {import { IPubParams } from '../children/videoPage/videoPage';import { memo, useMemo } from 'react';import { parseTopicString } from '../../../utils';-import { AccountStatus, AccountType } from '../../../../commont/AccountEnum';+import {+ AccountStatus,+ AccountType,+ XhsAccountAbnormal,+} from '../../../../commont/AccountEnum';import { Alert, Tooltip } from 'antd';import { InfoCircleOutlined } from '@ant-design/icons';@@ -19,10 +23,13 @@ export enum PubParamsErrStatusEnum {}export interface ErrPubParamsItem {+ // 这个错误提示会在账户tab显示message: string;+ // 错误类型,用户区分是否需要显示重新登录的错误提示errType: PubParamsErrStatusEnum;// 参数错误提示消息parErrMsg?: string;+ // 发生错误的平台plat?: AccountType;}@@ -108,10 +115,23 @@ export default function <T>(errType: PubParamsErrStatusEnum.PARAMS,parErrMsg: `话题 + 活动奖励不能超过${topicMax}个`,});+ } else if (+ v.account?.type === AccountType.Xhs &&+ v.account.abnormalStatus &&+ v.account.abnormalStatus[AccountType.Xhs] ===+ XhsAccountAbnormal.Abnormal+ ) {+ // 小红书账号异常情况处理+ errParamsMapTemp.set(v.id, {+ message: '账号错误',+ errType: PubParamsErrStatusEnum.PARAMS,+ parErrMsg: `小红书账号异常,无法发布作品,请检查后重试!`,+ });} else {if (moreVerify?.moreErrorVerifyCallback)moreVerify?.moreErrorVerifyCallback(v, errParamsMapTemp, platInfo);}+// 通用参数if (errParamsMapTemp.has(v.id)) {errParamsMapTemp.set(v.id, {