Skip to content

Let's use AI to Earn!

fix(publishing): delete linedin/bilibili post (#276)

wheat8bf75df0e7cf
diff --git a/project/backend/apps/aitoearn-channel/src/core/platforms/platforms.service.ts b/project/backend/apps/aitoearn-channel/src/core/platforms/platforms.service.ts
index 827bf535..040669f9 100644
--- a/project/backend/apps/aitoearn-channel/src/core/platforms/platforms.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/core/platforms/platforms.service.ts
@@ -1,6 +1,7 @@
import { Inject, Injectable, Logger } from '@nestjs/common'
-import { AccountType } from '@yikart/common'
+import { AccountType, AppException, ResponseCode } from '@yikart/common'
import { RedisService } from '@yikart/redis'
+import { SocialMediaError } from '../../libs/exception/base'
import { AccountService } from '../account/account.service'
import { PlatformBaseService } from './base.service'
@@ -33,11 +34,22 @@ export class PlatformService {
}
async deletePost(accountId: string, platform: AccountType, postId: string) {
- const svc = this.platformServices[platform]
- if (svc) {
- return await svc.deletePost(accountId, postId)
+ try {
+ const svc = this.platformServices[platform]
+ if (svc) {
+ return await svc.deletePost(accountId, postId)
+ }
+ throw new AppException(ResponseCode.PlatformNotSupported)
+ }
+ catch (error) {
+ if (error instanceof SocialMediaError) {
+ throw new AppException(ResponseCode.DeletePostFailed, error.message)
+ }
+ if (error instanceof AppException) {
+ throw error
+ }
+ throw new AppException(ResponseCode.DeletePostFailed, 'Unknown error')
}
- return false
}
async updateAccountStatus(accountId: string, status: number) {
diff --git a/project/backend/apps/aitoearn-channel/src/libs/bilibili/bilibiliApi.service.ts b/project/backend/apps/aitoearn-channel/src/libs/bilibili/bilibiliApi.service.ts
index 5b23938c..fec1b758 100644
--- a/project/backend/apps/aitoearn-channel/src/libs/bilibili/bilibiliApi.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/libs/bilibili/bilibiliApi.service.ts
@@ -437,10 +437,8 @@ export class BilibiliApiService {
const url = 'https://member.bilibili.com/arcopen/fn/archive/delete'
const config: AxiosRequestConfig = {
method: 'POST',
- headers: this.generateHeader({ accessToken }),
- data: {
- resource_id: videoId,
- },
+ headers: this.generateHeader({ accessToken, body: { resource_id: videoId } }),
+ data: { resource_id: videoId },
}
const result = await this.request<DeleteVideoData>(url, config)
return result
diff --git a/project/backend/apps/aitoearn-channel/src/libs/bilibili/common.ts b/project/backend/apps/aitoearn-channel/src/libs/bilibili/common.ts
index 24a6189f..e8f96a5f 100644
--- a/project/backend/apps/aitoearn-channel/src/libs/bilibili/common.ts
+++ b/project/backend/apps/aitoearn-channel/src/libs/bilibili/common.ts
@@ -134,19 +134,3 @@ export interface etagData {
}
export interface DeleteVideoData {}
-
-export interface DeleteVideoResponse extends CommonResponse<DeleteVideoData> { }
-
-export interface ArchiveTypeListResponse extends CommonResponse<ArchiveTypeItem[]> { }
-export interface ArchiveListResponse extends CommonResponse<ArchiveListData> { }
-export interface UserStatResponse extends CommonResponse<UserStatData> { }
-export interface ArcStatResponse extends CommonResponse<ArcStatData> { }
-export interface ArcIncStatResponse extends CommonResponse<ArcIncStatData> { }
-export interface ArchiveAddByUtokenResponse extends CommonResponse<ArchiveAddByUtokenData> { }
-export interface AccessTokenResponse extends CommonResponse<AccessToken> { }
-export interface BilibiliUserInfoResponse extends CommonResponse<BilibiliUser> { }
-export interface AddArchiveResponse extends CommonResponse<AddArchiveData> { }
-export interface GrantScopesResponse extends CommonResponse<GrantScopes> { }
-export interface VideoInitialResponse extends CommonResponse<videoInitialData> { }
-export interface EtagResponse extends CommonResponse<etagData> { }
-export interface UploadCoverImgResponse extends CommonResponse<{ url: string }> { }
diff --git a/project/backend/apps/aitoearn-channel/src/libs/linkedin/linkedin.service.ts b/project/backend/apps/aitoearn-channel/src/libs/linkedin/linkedin.service.ts
index f1a1c1f7..9f279de2 100644
--- a/project/backend/apps/aitoearn-channel/src/libs/linkedin/linkedin.service.ts
+++ b/project/backend/apps/aitoearn-channel/src/libs/linkedin/linkedin.service.ts
@@ -121,7 +121,7 @@ export class LinkedinService {
}
}
- async deletePost(shareId: string, accessToken: string) {
+ async deletePost(accessToken: string, shareId: string) {
const url = `${this.apiBaseUrl}/ugcPosts/${encodeURIComponent(shareId)}`
const config: AxiosRequestConfig = {
headers: {
diff --git a/project/backend/apps/aitoearn-server/src/channel/channel.service.ts b/project/backend/apps/aitoearn-server/src/channel/channel.service.ts
index a013b9a9..21120e58 100644
--- a/project/backend/apps/aitoearn-server/src/channel/channel.service.ts
+++ b/project/backend/apps/aitoearn-server/src/channel/channel.service.ts
@@ -35,9 +35,17 @@ export class ChannelService {
if (!account || account.userId !== userId) {
throw new AppException(ResponseCode.AccountNotFound)
}
- const res = await this.channelApi.deletePost(
- { accountId, platform: account.type, postId },
- )
- return res
+ try {
+ const res = await this.channelApi.deletePost(
+ { accountId, platform: account.type, postId },
+ )
+ return res
+ }
+ catch (error) {
+ if (error instanceof AppException) {
+ throw error
+ }
+ throw new AppException(ResponseCode.DeletePostFailed, 'Unknown error')
+ }
}
}
diff --git a/project/backend/apps/aitoearn-server/src/channel/publish.service.ts b/project/backend/apps/aitoearn-server/src/channel/publish.service.ts
index c98a9810..d8ca7d4a 100644
--- a/project/backend/apps/aitoearn-server/src/channel/publish.service.ts
+++ b/project/backend/apps/aitoearn-server/src/channel/publish.service.ts
@@ -248,15 +248,19 @@ export class PublishService {
async getPublishRecordDetail(flowId: string, userId: string) {
try {
const record = await this.publishRecordService.getPublishRecordDetail({ flowId, userId })
- return record
+ this.logger.log(`Publish record detail for flowId ${flowId} and userId ${userId}: ${JSON.stringify(record)}`)
+ if (record) {
+ return record
+ }
}
catch (error: any) {
this.logger.error(`Failed to get publish record detail for flowId ${flowId} and userId ${userId}: ${error.message}`, error.stack)
}
const task = await this.platPublishNatsApi.getPublishTaskDetail(flowId, userId)
+ this.logger.log(`Publish task detail for flowId ${flowId} and userId ${userId}: ${JSON.stringify(task)}`)
if (!task) {
- throw new AppException(ResponseCode.PublishRecordNotFound, { flowId })
+ throw new AppException(ResponseCode.PublishRecordNotFound)
}
return task
}
diff --git a/project/backend/apps/aitoearn-server/src/transports/channel/api/publish.natsApi.ts b/project/backend/apps/aitoearn-server/src/transports/channel/api/publish.natsApi.ts
index bc39ec4a..17046ade 100644
--- a/project/backend/apps/aitoearn-server/src/transports/channel/api/publish.natsApi.ts
+++ b/project/backend/apps/aitoearn-server/src/transports/channel/api/publish.natsApi.ts
@@ -137,7 +137,7 @@ export class PlatPublishNatsApi extends ChannelBaseApi {
async getPublishTaskDetail(flowId: string, userId: string) {
const res = await this.sendMessage<PublishRecordItem | null>(
- `channel/publishing/task/detail`,
+ `channel/publishTask/detail`,
{
flowId,
userId,
diff --git a/project/backend/libs/common/src/enums/response-code.enum.ts b/project/backend/libs/common/src/enums/response-code.enum.ts
index da3c390d..16ce4cd4 100755
--- a/project/backend/libs/common/src/enums/response-code.enum.ts
+++ b/project/backend/libs/common/src/enums/response-code.enum.ts
@@ -99,4 +99,5 @@ export enum ResponseCode {
PostCategoryNotSupported = 15031,
PlatformNotSupported = 15032,
PublishTaskUpdateFailed = 15033,
+ DeletePostFailed = 15034,
}
diff --git a/project/backend/libs/common/src/i18n/messages.ts b/project/backend/libs/common/src/i18n/messages.ts
index b9fdc21a..1f32fe0c 100644
--- a/project/backend/libs/common/src/i18n/messages.ts
+++ b/project/backend/libs/common/src/i18n/messages.ts
@@ -300,4 +300,8 @@ export const messages: Record<ResponseCode, Record<Locale, MessageValue>> = {
'en-US': 'Failed to update publish task',
'zh-CN': '更新发布任务失败',
},
+ [ResponseCode.DeletePostFailed]: {
+ 'en-US': 'Failed to delete post',
+ 'zh-CN': '删除作品失败',
+ },
}