Skip to content

Let's use AI to Earn!

feat: 更改mcp接口

Nevina66577b18e8b
diff --git a/aitoearn_web/server/aitoearn-channel/src/core/mcp/dto/publish.dto.ts b/aitoearn_web/server/aitoearn-channel/src/core/mcp/dto/publish.dto.ts
index 172369c4..05ba4c4a 100644
--- a/aitoearn_web/server/aitoearn-channel/src/core/mcp/dto/publish.dto.ts
+++ b/aitoearn_web/server/aitoearn-channel/src/core/mcp/dto/publish.dto.ts
@@ -11,9 +11,7 @@ export const CreatePublishSchema = z.object({
videoUrl: z.string().optional(),
coverUrl: z.string().optional(),
imgUrlList: z.string().optional(),
- publishTime: z
- .date()
- .default(() => new Date()),
+ publishTime: z.string().optional(),
topics: z.string(),
})
export class CreatePublishDto extends createZodDto(CreatePublishSchema) {}
diff --git a/aitoearn_web/server/aitoearn-channel/src/core/mcp/mcp.controller.ts b/aitoearn_web/server/aitoearn-channel/src/core/mcp/mcp.controller.ts
index 434b760d..189ce6ba 100644
--- a/aitoearn_web/server/aitoearn-channel/src/core/mcp/mcp.controller.ts
+++ b/aitoearn_web/server/aitoearn-channel/src/core/mcp/mcp.controller.ts
@@ -2,9 +2,10 @@ import {
CallToolResult,
GetPromptResult,
} from '@modelcontextprotocol/sdk/types';
-import { Controller } from '@nestjs/common';
+import { Controller, Logger } from '@nestjs/common';
import { Prompt, Tool } from '@rekog/mcp-nest';
import { plainToInstance } from 'class-transformer';
+import moment from 'moment';
import { AppException } from '@/common';
import { ExceptionCode } from '@/common/enums/exception-code.enum';
import { AccountType } from '@/transports/account/common';
@@ -58,6 +59,21 @@ export class McpController {
async createPub(data: CreatePublishDto) {
data = plainToInstance(CreatePublishDto, data);
+ let publishTimeDate: Date = new Date(Date.now() + 2 * 60 * 1000);
+ try {
+ const { publishTime } = data;
+ if (publishTime) {
+ publishTimeDate = moment(publishTime).toDate();
+ if (publishTimeDate.getTime() < Date.now()) {
+ throw new AppException(1, '发布时间不能小于当前时间');
+ }
+ }
+ }
+ catch (error) {
+ Logger.error('mcp publish createPub', error);
+ throw new AppException(1, '发布时间格式有误');
+ }
+
const accountInfo = await this.accountService.getAccountInfo(
data.accountId,
);
@@ -88,6 +104,7 @@ export class McpController {
userId: accountInfo.userId,
accountType: accountInfo.type,
...data,
+ publishTime: publishTimeDate,
imgUrlList: imgUrlList?.split(','),
topics: topics?.split(','),
});
diff --git a/aitoearn_web/server/aitoearn-channel/src/core/mcp/plugin.controller.ts b/aitoearn_web/server/aitoearn-channel/src/core/mcp/plugin.controller.ts
index 0b91a4d1..0ee4fdb5 100644
--- a/aitoearn_web/server/aitoearn-channel/src/core/mcp/plugin.controller.ts
+++ b/aitoearn_web/server/aitoearn-channel/src/core/mcp/plugin.controller.ts
@@ -3,11 +3,13 @@ import {
Controller,
Get,
HttpCode,
+ Logger,
Param,
Post,
UseGuards,
} from '@nestjs/common';
import { plainToInstance } from 'class-transformer';
+import moment from 'moment';
import { AppException } from '@/common';
import { ExceptionCode } from '@/common/enums/exception-code.enum';
import { GetSkKey, SkKeyAuthGuard } from '@/common/guards/skKeyAuth.guard';
@@ -26,7 +28,7 @@ export class PluginController {
private readonly skKeyService: SkKeyService,
private readonly publishTaskService: PublishTaskService,
private readonly publishRecordService: PublishRecordService,
- ) {}
+ ) { }
/**
* 获取key的账号列表
@@ -49,38 +51,76 @@ export class PluginController {
@HttpCode(200)
@UseGuards(SkKeyAuthGuard)
@Post('publish/create')
- async createPub(@Body() data: CreatePublishDto) {
- data = plainToInstance(CreatePublishDto, data);
+ async createPub(@Body() body: CreatePublishDto) {
+ // 发布时间处理
+ let publishTimeDate: Date = new Date(Date.now() + 2 * 60 * 1000);
+ try {
+ const { publishTime } = body;
+ if (publishTime) {
+ publishTimeDate = moment(publishTime).toDate();
+ if (publishTimeDate.getTime() < Date.now()) {
+ throw new AppException(1, '发布时间不能小于当前时间');
+ }
+ }
+ }
+ catch (error) {
+ Logger.error('mcp publish createPub', error);
+ throw new AppException(1, '发布时间格式有误');
+ }
+ try {
+ body = plainToInstance(CreatePublishDto, body);
- const accountInfo = await this.accountService.getAccountInfo(
- data.accountId,
- );
- if (!accountInfo)
- throw new AppException(ExceptionCode.File, '账号信息获取失败');
- const { imgUrlList, topics } = data;
+ const accountInfo = await this.accountService.getAccountInfo(
+ body.accountId,
+ );
+ if (!accountInfo)
+ throw new AppException(ExceptionCode.File, '账号信息获取失败');
+ const { imgUrlList, topics } = body;
- // B站默认值
- if (accountInfo.type === AccountType.BILIBILI) {
- (data as any).option = {
- bilibili: {
- tid: 160,
- copyright: 1,
- },
- };
- }
+ // B站默认值
+ if (accountInfo.type === AccountType.BILIBILI) {
+ (body as any).option = {
+ bilibili: {
+ tid: 160,
+ copyright: 1,
+ },
+ };
+ }
+
+ if (accountInfo.type === AccountType.FACEBOOK) {
+ (body as any).option = {
+ facebook: {
+ content_category: 'video',
+ },
+ };
+ }
- const ret = await this.publishTaskService.createPub({
- inQueue: false,
- queueId: '',
- uid: accountInfo.uid,
- userId: accountInfo.userId,
- accountType: accountInfo.type,
- ...data,
- imgUrlList: imgUrlList?.split(','),
- topics: topics?.split(','),
- });
+ if (accountInfo.type === AccountType.INSTAGRAM) {
+ (body as any).option = {
+ instagram: {
+ content_category: 'video',
+ },
+ };
+ }
- return ret;
+ const ret = await this.publishTaskService.createPub({
+ inQueue: false,
+ queueId: '',
+ uid: accountInfo.uid,
+ userId: accountInfo.userId,
+ accountType: accountInfo.type,
+ ...body,
+ publishTime: publishTimeDate,
+ imgUrlList: imgUrlList?.split(','),
+ topics: topics?.split(','),
+ });
+
+ return ret;
+ }
+ catch (error) {
+ Logger.debug('----------- in createPub error ------------', error);
+ Logger.error(error);
+ }
}
/**