Skip to content

Let's use AI to Earn!

fix: 修复发布

Nevinb0f17056e240
diff --git a/aitoearn_web/server/aitoearn-channel/src/core/file/file.service.ts b/aitoearn_web/server/aitoearn-channel/src/core/file/file.service.ts
index 29ebdf0d..8528c589 100644
--- a/aitoearn_web/server/aitoearn-channel/src/core/file/file.service.ts
+++ b/aitoearn_web/server/aitoearn-channel/src/core/file/file.service.ts
@@ -82,17 +82,34 @@ export class FileService {
return res.key;
}
- // 根据URL上传文件
+ /**
+ * aws 根据URL上传文件
+ * @param url 远程地址
+ * @param option
+ * @returns
+ */
async upFileByUrl(
url: string,
- option: { path?: string; permanent?: boolean; fileType?: string },
+ option: { path?: string; permanent?: boolean; },
): Promise<string> {
- const { path, permanent, fileType } = option;
- const objectName = `${config.env}/${permanent ? '' : 'temp/'}${path || 'nopath'}${`/${moment().format('YYYYMM')}/${uuidv4()}.${fileType || 'jpg'}`}`;
+ const { path, permanent } = option;
+ // 从URL下载文件内容
+ const response = await fetch(url);
+ if (!response.ok) {
+ throw new Error(`Failed to download file from URL: ${url}`);
+ }
+ const arrayBuffer = await response.arrayBuffer();
+ const buffer = Buffer.from(arrayBuffer);
+
+ // 根据响应内容类型获取文件后缀
+ const contentType = response.headers.get('content-type') || 'application/octet-stream';
+ const fileType = mime.extension(contentType) || 'jpg';
+ const objectName = `${config.env}/${permanent ? '' : 'temp/'}${path || 'nopath'}${`/${moment().format('YYYYMM')}/${uuidv4()}.${fileType}`}`;
+
const res = await this.s3Service.uploadFile(
objectName,
- Buffer.from(url, 'base64'),
- `application/${fileType || 'octet-stream'}`,
+ buffer,
+ contentType,
);
return res.key;
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 0ee4fdb5..c5051f36 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
@@ -54,27 +54,25 @@ export class PluginController {
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, '发布时间不能小于当前时间');
- }
- }
+ const { publishTime } = body;
+
+ // 如果publishTime为空,或者转换时间有误,则使用publishTimeDate
+ if (!publishTime || !moment(publishTime).isValid()) {
+ publishTimeDate = new Date(Date.now() + 2 * 60 * 1000);
}
- catch (error) {
- Logger.error('mcp publish createPub', error);
- throw new AppException(1, '发布时间格式有误');
+ else {
+ publishTimeDate = new Date(publishTime);
}
+
try {
body = plainToInstance(CreatePublishDto, body);
const accountInfo = await this.accountService.getAccountInfo(
body.accountId,
);
- if (!accountInfo)
+ if (!accountInfo) {
throw new AppException(ExceptionCode.File, '账号信息获取失败');
+ }
const { imgUrlList, topics } = body;
// B站默认值
@@ -118,8 +116,8 @@ export class PluginController {
return ret;
}
catch (error) {
- Logger.debug('----------- in createPub error ------------', error);
- Logger.error(error);
+ Logger.debug('----------- plugin createPub error ------------', error);
+ Logger.error('----------- plugin createPub error ------------', error);
}
}