Skip to content

Let's use AI to Earn!

fix: 1. 图文文案内容安全检测全部完成。 2. 一键检测登录状态优化,多个账号检测不会重复更新list,只会更新一次。 3. 修复了【抖音-账号】错误处理问题。

gaoSir45d489c14d20
diff --git a/electron/main/account/controller.ts b/electron/main/account/controller.ts
index de58468e..3bbb22fb 100644
--- a/electron/main/account/controller.ts
+++ b/electron/main/account/controller.ts
@@ -71,39 +71,45 @@ export class AccountController {
}
/**
- * 账户登录检测
+ * 账户登录检测-单个
*/
@Icp('ICP_ACCOUNT_LOGIN_CHECK')
async checkAccountLogin(
event: Electron.IpcMainInvokeEvent,
pType: AccountType,
uid: string,
+ isSendEvent: boolean = true,
): Promise<AccountModel | null> {
- const userInfo = getUserInfo();
-
- const accountInfo = await this.accountService.getAccountInfo({
- type: pType,
- userId: userInfo.id,
- uid: uid,
- });
- if (!accountInfo) return accountInfo;
- // 取出cookie
- if (!accountInfo.loginCookie) return accountInfo;
+ const account = await this.accountService.checkAccountLoginCore(pType, uid);
+ if (isSendEvent) {
+ windowOperate.sendRenderMsg(SendChannelEnum.AccountLoginFinish, account);
+ }
+ return account;
+ }
- const res = await platController
- .platLoginCheck(pType, accountInfo)
- .catch(() => ({
- online: false,
- account: undefined,
- }));
+ /**
+ * 账户登录检测-多个
+ */
+ @Icp('ICP_ACCOUNT_LOGIN_CHECK_MULTI')
+ async checkAccountLoginMulti(
+ event: Electron.IpcMainInvokeEvent,
+ checkAccounts: {
+ pType: AccountType;
+ uid: string;
+ }[],
+ ): Promise<(AccountModel | null)[]> {
+ const tasks: Promise<AccountModel | null>[] = [];
- 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;
+ for (const { pType, uid } of checkAccounts) {
+ tasks.push(this.accountService.checkAccountLoginCore(pType, uid));
+ }
+ const accounts = await Promise.all(tasks);
+ windowOperate.sendRenderMsg(
+ SendChannelEnum.AccountLoginFinish,
+ accounts[0],
+ accounts,
+ );
+ return accounts;
}
// 更新用户状态
diff --git a/electron/main/account/service.ts b/electron/main/account/service.ts
index c6d5bde6..8f49a223 100644
--- a/electron/main/account/service.ts
+++ b/electron/main/account/service.ts
@@ -9,12 +9,14 @@ import { AccountModel } from '../../db/models/account';
import { Injectable } from '../core/decorators';
import { FindOptionsWhere, In, Repository } from 'typeorm';
import {
+ AccountStatus,
AccountType,
defaultAccountGroupId,
} from '../../../commont/AccountEnum';
import platController from '../plat/index';
import { EtEvent } from '../../global/event';
import { AccountGroupModel } from '../../db/models/accountGroup';
+import { getUserInfo } from '../user/comment';
@Injectable()
export class AccountService {
@@ -60,6 +62,35 @@ export class AccountService {
return await this.accountGroupRepository.update({ id: data.id }, data);
}
+ // 单个账号登录状态检测core
+ async checkAccountLoginCore(pType: AccountType, uid: string) {
+ const userInfo = getUserInfo();
+
+ const accountInfo = await this.getAccountInfo({
+ type: pType,
+ userId: userInfo.id,
+ uid: uid,
+ });
+ if (!accountInfo) return accountInfo;
+ // 取出cookie
+ if (!accountInfo.loginCookie) return accountInfo;
+
+ const res = await platController
+ .platLoginCheck(pType, accountInfo)
+ .catch(() => ({
+ online: false,
+ account: undefined,
+ }));
+
+ await this.updateAccountInfo(accountInfo.id, {
+ status: res.online ? AccountStatus.USABLE : AccountStatus.DISABLE,
+ ...(res.online && typeof res.account === 'object' ? res.account : {}),
+ });
+ const account = await this.getAccountById(accountInfo!.id!);
+
+ return account || accountInfo;
+ }
+
// 没有就添加有就更新cookie
async addOrUpdateAccount(
query: {
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index 1755748e..d912dba4 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -593,9 +593,10 @@ export class Douyin extends PlatformBase {
params.keyword,
params.page,
);
+
return {
status: this.getCode(usersRes),
- data: usersRes.data.user_list.map((v) => {
+ data: usersRes?.data?.user_list?.map((v) => {
return {
image: 'https://p26.douyinpic.com/aweme/' + v.avatar_thumb.uri,
id: v.uid,
@@ -669,14 +670,16 @@ export class Douyin extends PlatformBase {
}
getCode(res: IRequestNetResult<any>) {
- return res?.data?.status_code === 8 ? 401 : res?.status;
+ return res?.data?.status_code === 8 || res?.data?.status_code === 7
+ ? 401
+ : res?.status;
}
async getMixList(cookie: CookiesType) {
const mixRes = await douyinService.getMixList(cookie);
return {
status: this.getCode(mixRes),
- data: mixRes?.data.mix_list.map((v) => {
+ data: mixRes?.data.mix_list?.map((v) => {
return {
id: v.mix_id,
name: v.mix_name,
diff --git a/src/icp/account.ts b/src/icp/account.ts
index dec0f8ab..a43edc5a 100644
--- a/src/icp/account.ts
+++ b/src/icp/account.ts
@@ -29,12 +29,31 @@ export async function ipcUpdateAccountStatus(
* 账户登录状态检测
* @param pType
* @param uid
+ * @param isSendEvent 是否发送账户更新的事件
*/
-export async function acpAccountLoginCheck(pType: AccountType, uid: string) {
+export async function acpAccountLoginCheck(
+ pType: AccountType,
+ uid: string,
+ isSendEvent: boolean = true,
+) {
const res: AccountInfo = await window.ipcRenderer.invoke(
'ICP_ACCOUNT_LOGIN_CHECK',
pType,
uid,
+ isSendEvent,
+ );
+ return res;
+}
+// 账户登录状态检测,多个账号
+export async function acpAccountLoginCheckMulti(
+ checkAccounts: {
+ pType: AccountType;
+ uid: string;
+ }[],
+) {
+ const res: AccountInfo[] = await window.ipcRenderer.invoke(
+ 'ICP_ACCOUNT_LOGIN_CHECK_MULTI',
+ checkAccounts,
);
return res;
}
diff --git a/src/icp/receiveMsg.ts b/src/icp/receiveMsg.ts
index a2461e0e..73d71c61 100644
--- a/src/icp/receiveMsg.ts
+++ b/src/icp/receiveMsg.ts
@@ -3,6 +3,7 @@ import { SendChannelEnum } from '../../commont/UtilsEnum';
import { PublishProgressRes } from '../../electron/main/plat/pub/PubItemVideo';
import IpcRendererEvent = Electron.IpcRendererEvent;
import { AccountModel } from '../../electron/db/models/account';
+import { AccountType } from '@@/AccountEnum';
// 绑定事件中间层方法
const bindEventCore = (
@@ -34,14 +35,17 @@ export const onInteractionProgress = (callback: (...args: any[]) => void) => {
});
};
-// 账户登录完成
+/**
+ * 账户登录完成的事件,可能为多个账户更新后的结果
+ * @param callback account=如果为多个账户更新的结果那么这个值是第一个,主要是为了兼容之前的单个账户的检测,accounts=如果是单个检测这个值为空,多个值检测这个值为更新后的账号结果
+ */
export const onAccountLoginFinish = (
- callback: (account: AccountModel) => void,
+ callback: (account: AccountModel, accounts?: AccountType[]) => void,
) => {
return bindEventCore(
SendChannelEnum.AccountLoginFinish,
- (e, account: AccountModel) => {
- callback(account);
+ (e, account: AccountModel, accounts?: AccountType[]) => {
+ callback(account, accounts);
},
);
};
diff --git a/src/store/account.ts b/src/store/account.ts
index 4b6a0e57..51e834cc 100644
--- a/src/store/account.ts
+++ b/src/store/account.ts
@@ -4,13 +4,12 @@ import lodash from 'lodash';
import { AccountInfo } from '@/views/account/comment';
import {
AccountGroup,
- acpAccountLoginCheck,
+ acpAccountLoginCheckMulti,
icpGetAccountGroup,
icpGetAccountList,
} from '@/icp/account';
import { onAccountLoginFinish } from '@/icp/receiveMsg';
import { sleep } from '@@/utils';
-import { AccountModel } from '../../electron/db/models/account';
export interface AccountGroupItem extends AccountGroup {
children: AccountInfo[];
@@ -114,22 +113,18 @@ export const useAccountStore = create(
await methods.getAccountList();
methods.timeingCheckAccount();
},
-
- // 轮询检测账户有效性 core
- async checkAccountCore(account: AccountModel) {
- await acpAccountLoginCheck(account.type, account.uid);
- },
// 轮询检测账户有效性
async timeingCheckAccount() {
return new Promise(async () => {
while (true) {
const { accountList } = get();
- const tasks: Promise<void>[] = [];
- for (let i = 0; i < accountList.length; i++) {
- const account = accountList[i];
- tasks.push(methods.checkAccountCore(account));
- }
- await Promise.all(tasks);
+
+ await acpAccountLoginCheckMulti(
+ accountList.map((v) => ({
+ pType: v.type,
+ uid: v.uid,
+ })),
+ );
// 等待24小时执行,如果用户没有关闭应用
await sleep(3600000 * 24);
diff --git a/src/views/publish/children/imagePage/image.module.scss b/src/views/publish/children/imagePage/image.module.scss
index 21f2d8ac..61b43328 100644
--- a/src/views/publish/children/imagePage/image.module.scss
+++ b/src/views/publish/children/imagePage/image.module.scss
@@ -20,6 +20,12 @@
border-top: 1px solid var(--grayColor3);
padding: 15px 0;
text-align: center;
+ button {
+ margin-right: 20px;
+ &:last-of-type {
+ margin-right: 0;
+ }
+ }
}
}
}
diff --git a/src/views/publish/children/imagePage/page.tsx b/src/views/publish/children/imagePage/page.tsx
index 9f9d533a..d59df16b 100644
--- a/src/views/publish/children/imagePage/page.tsx
+++ b/src/views/publish/children/imagePage/page.tsx
@@ -24,7 +24,9 @@ import { useAccountStore } from '../../../../store/commont';
import { useNavigate } from 'react-router-dom';
import { usePubStroe } from '../../../../store/pubStroe';
import { ExclamationCircleFilled } from '@ant-design/icons';
-import { signInApi, SignInType } from '@/api/signIn';
+import { signInApi } from '@/api/signIn';
+import { toolsApi } from '@/api/tools';
+import { IImageAccountItem } from '@/views/publish/children/imagePage/imagePage.type';
const { confirm } = Modal;
@@ -84,6 +86,8 @@ export default function Page() {
Map<number, PublishProgressRes>
>(new Map());
const navigate = useNavigate();
+ // 敏感词检测
+ const [sensitiveDetLoading, setSensitiveDetLoading] = useState(false);
useEffect(() => {
setErrParamsMap(errParamsMap, warnParamsMap);
@@ -123,6 +127,7 @@ export default function Page() {
};
}, []);
+ // 发布
const pubCore = async () => {
setPubProgressModuleOpen(true);
setLoading(true);
@@ -186,6 +191,7 @@ export default function Page() {
});
};
+ // 进度
const pubProgressData = useMemo(() => {
return imageAccounts.map((v) => {
const progress = pubProgressMap.get(v.account!.id);
@@ -197,10 +203,24 @@ export default function Page() {
});
}, [pubProgressMap, imageAccounts]);
+ // 一键发布点击
const pubClick = () => {
pubAccountDetModuleRef.current!.startDet();
setLoading(true);
};
+
+ const sensitiveDetCore = async (
+ content: string,
+ accountItem: IImageAccountItem,
+ ) => {
+ const res = await toolsApi.textModeration(content);
+
+ return {
+ sensitive: res !== 'Normal',
+ accountItem,
+ };
+ };
+
return (
<div className={styles.image}>
<PubProgressModule
@@ -242,8 +262,59 @@ export default function Page() {
okText="确认"
cancelText="取消"
>
- <Button style={{ marginRight: '20px' }}>一键清空</Button>
+ <Button>一键清空</Button>
</Popconfirm>
+ <Button
+ loading={sensitiveDetLoading}
+ color="danger"
+ variant="solid"
+ disabled={imageAccounts.length === 0 || images.length === 0}
+ onClick={async () => {
+ setSensitiveDetLoading(true);
+ const tasks: Promise<{
+ // 作品
+ accountItem: IImageAccountItem;
+ // 是否敏感 true=敏感 false=正常
+ sensitive: boolean;
+ }>[] = [];
+ // 如果检测内容重复不会进行检测
+ const contentSet = new Set<string>();
+
+ imageAccounts.map((v) => {
+ const content = `
+ ${v.pubParams.title}
+ ${v.pubParams.describe}
+ `;
+ if (content.trim() !== '' && !contentSet.has(content)) {
+ contentSet.add(content);
+ tasks.push(sensitiveDetCore(content, v));
+ }
+ });
+ const res = await Promise.all(tasks);
+ setSensitiveDetLoading(false);
+
+ if (res.length === 0) return message.success('检测正常');
+
+ if (res.every((v) => !v.sensitive)) {
+ message.success('检测正常');
+ return;
+ }
+ for (const { sensitive, accountItem } of res) {
+ if (sensitive) {
+ message.warning('检测到此条作品异常!');
+ setActivePlat(accountItem.account.type);
+ const platActiveAccountMap = new Map(
+ useImagePageStore.getState().platActiveAccountMap,
+ );
+ platActiveAccountMap.set(accountItem.account.type, accountItem);
+ setPlatActiveAccountMap(platActiveAccountMap);
+ break;
+ }
+ }
+ }}
+ >
+ 内容安全检测
+ </Button>
<Button
loading={loading}
type="primary"
diff --git a/src/views/publish/components/PubAccountDetModule/PubAccountDetModule.tsx b/src/views/publish/components/PubAccountDetModule/PubAccountDetModule.tsx
index 05be3ed0..77204b62 100644
--- a/src/views/publish/components/PubAccountDetModule/PubAccountDetModule.tsx
+++ b/src/views/publish/components/PubAccountDetModule/PubAccountDetModule.tsx
@@ -78,9 +78,10 @@ const PubAccountDetModule = memo(
const [proxyInvalidAccountMap, setProxyInvalidAccountMap] = useState<
Map<number, AccountGroupItem>
>(new Map());
- const { accountGroupMap } = useAccountStore(
+ const { accountGroupMap, getAccountList } = useAccountStore(
useShallow((state) => ({
accountGroupMap: state.accountGroupMap,
+ getAccountList: state.getAccountList,
})),
);
@@ -105,7 +106,11 @@ const PubAccountDetModule = memo(
// 检测账户状态
const retLoginStatusCore = async (account: AccountInfo) => {
- const res = await acpAccountLoginCheck(account.type, account.uid);
+ const res = await acpAccountLoginCheck(
+ account.type,
+ account.uid,
+ false,
+ );
setProgress((prevProgress) => prevProgress + 1);
return res;
};
@@ -150,6 +155,7 @@ const PubAccountDetModule = memo(
tasksAccountStatus.push(retLoginStatusCore(account));
if (isCheckProxy) {
+ // 代理有效性检测
if (!proxyGroupSet.has(account.groupId!)) {
const group = accountGroupMap.get(account.groupId!)!;
if (group.proxyOpen) {
@@ -162,8 +168,12 @@ const PubAccountDetModule = memo(
}
}
+ // 等待代理和账号有效性检测...
const resGroupProxyStatus = await Promise.all(tasksProxyCheck);
const resAccountStatus = await Promise.all(tasksAccountStatus);
+
+ await getAccountList();
+
setTimeout(() => {
if (onDetFinish) onDetFinish(resAccountStatus);
setDetLoading(false);
@@ -184,7 +194,7 @@ const PubAccountDetModule = memo(
});
}
});
- }, 100);
+ }, 50);
},
};
useImperativeHandle(ref, () => imperative);