Skip to content

Commit 604e52f

Browse files
authored
refactor(publishing): consolidate social media API error handling and retry strategy in publishing (#188)
1 parent 45e190f commit 604e52f

File tree

195 files changed

+5120
-6104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+5120
-6104
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
CanActivate,
3+
createParamDecorator,
4+
ExecutionContext,
5+
Injectable,
6+
Logger,
7+
UnauthorizedException,
8+
} from '@nestjs/common'
9+
import { Reflector } from '@nestjs/core'
10+
import { SkKeyService } from '../../core/sk-key/sk-key.service'
11+
12+
export const GetSkKey = createParamDecorator(
13+
(data: string, ctx: ExecutionContext) => {
14+
const req = ctx.switchToHttp().getRequest()
15+
return req['skKey']
16+
},
17+
)
18+
19+
@Injectable()
20+
export class SkKeyAuthGuard implements CanActivate {
21+
private readonly logger = new Logger(SkKeyAuthGuard.name)
22+
constructor(
23+
private reflector: Reflector,
24+
private readonly skKeyService: SkKeyService,
25+
) {}
26+
27+
async canActivate(context: ExecutionContext): Promise<boolean> {
28+
const request = context.switchToHttp().getRequest()
29+
// 获取令牌sk
30+
const key = request.headers['sk-key'] || request.query['sk-key']
31+
32+
try {
33+
const keyInfo = await this.skKeyService.getInfo(key)
34+
if (!keyInfo) {
35+
throw new UnauthorizedException('令牌验证失败')
36+
}
37+
request['skKey'] = keyInfo
38+
}
39+
catch (error) {
40+
this.logger.error(error)
41+
throw new UnauthorizedException('令牌验证失败')
42+
}
43+
return true
44+
}
45+
}

project/backend/apps/aitoearn-channel/src/common/guards/skKeyAuth.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
UnauthorizedException,
88
} from '@nestjs/common'
99
import { Reflector } from '@nestjs/core'
10-
import { SkKeyService } from '../../core/skKey/skKey.service'
10+
import { SkKeyService } from '../../core/sk-key/sk-key.service'
1111

1212
export const GetSkKey = createParamDecorator(
1313
(data: string, ctx: ExecutionContext) => {

project/backend/apps/aitoearn-channel/src/core/account/account.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Global, Module } from '@nestjs/common'
22
import { MongooseModule } from '@nestjs/mongoose'
33
import { Account, AccountSchema } from '../../libs/database/schema/account.schema'
44
import { AccountService } from './account.service'
5-
import { PublishRecordService } from './publishRecord.service'
5+
import { PublishRecordService } from './publish-record.service'
66

77
@Global()
88
@Module({

project/backend/apps/aitoearn-channel/src/core/account/publishRecord.service.ts renamed to project/backend/apps/aitoearn-channel/src/core/account/publish-record.service.ts

File renamed without changes.

project/backend/apps/aitoearn-channel/src/core/core.module.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
import { Module } from '@nestjs/common'
2-
import { McpModule as TheMcpModule } from '@rekog/mcp-nest'
3-
import { SkKeyAuthGuard } from '../common/guards/skKeyAuth.guard'
42
import { AliGreenModule } from '../core/ali-green/ali-green.module'
5-
import { PublishModule } from '../core/publish/publish.module'
63
import { AccountModule } from './account/account.module'
7-
import { DataCubeModule } from './dataCube/dataCube.module'
4+
import { DataCubeModule } from './data-cube/data-cube.module'
85
import { EngagementModule } from './engagement/engagement.module'
96
import { FileModule } from './file/file.module'
107
import { InteracteModule } from './interact/interact.module'
11-
import { McpModule } from './mcp/mcp.module'
12-
import { MetaModule } from './plat/meta/meta.module'
13-
import { PlatModule } from './plat/plat.module'
14-
import { TiktokModule } from './plat/tiktok/tiktok.module'
15-
import { TwitterModule } from './plat/twitter/twitter.module'
16-
import { WxPlatModule } from './plat/wxPlat/wxPlat.module'
17-
import { YoutubeModule } from './plat/youtube/youtube.module'
18-
import { SkKeyModule } from './skKey/skKey.module'
8+
import { MetaModule } from './platforms/meta/meta.module'
9+
import { PlatModule } from './platforms/platforms.module'
10+
import { TiktokModule } from './platforms/tiktok/tiktok.module'
11+
import { TwitterModule } from './platforms/twitter/twitter.module'
12+
import { WxPlatModule } from './platforms/wx-plat/wx-plat.module'
13+
import { YoutubeModule } from './platforms/youtube/youtube.module'
14+
import { PublishModule } from './publishing/publishing.module'
15+
import { SkKeyModule } from './sk-key/sk-key.module'
1916
import { TestModule } from './test/test.module'
2017

2118
@Module({
2219
imports: [
2320
TestModule,
2421
FileModule,
2522
SkKeyModule,
26-
McpModule,
27-
TheMcpModule.forRoot({
28-
name: 'channel-mcp-server',
29-
version: '1.0.0',
30-
guards: [SkKeyAuthGuard],
31-
}),
3223
AccountModule,
3324
PublishModule,
3425
TwitterModule,

project/backend/apps/aitoearn-channel/src/core/dataCube/bilibiliData.service.ts renamed to project/backend/apps/aitoearn-channel/src/core/data-cube/bilibili-data.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { Injectable, Logger } from '@nestjs/common'
99
import { OnEvent } from '@nestjs/event-emitter'
1010
import { AccountType, AitoearnServerClientService } from '@yikart/aitoearn-server-client'
11-
import { BilibiliService } from '../plat/bilibili/bilibili.service'
11+
import { BilibiliService } from '../platforms/bilibili/bilibili.service'
1212
import { DataCubeBase } from './data.base'
1313

1414
@Injectable()

project/backend/apps/aitoearn-channel/src/core/dataCube/dataCube.controller.ts renamed to project/backend/apps/aitoearn-channel/src/core/data-cube/data-cube.controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { Body, Controller, Post } from '@nestjs/common'
99
import { AccountType } from '@yikart/aitoearn-server-client'
1010
import { AppException, ResponseCode } from '@yikart/common'
1111
import { AccountService } from '../account/account.service'
12-
import { BilibiliDataService } from './bilibiliData.service'
12+
import { BilibiliDataService } from './bilibili-data.service'
1313
import { DataCubeBase } from './data.base'
14-
import { AccountDto, ArcDto } from './dto/dataCube.dto'
15-
import { WxGzhDataService } from './wxGzhData.service'
16-
import { YoutubeDataService } from './youtubeData.service'
14+
import { AccountDto, ArcDto } from './dto/data-cube.dto'
15+
import { WxGzhDataService } from './wx-gzh-data.service'
16+
import { YoutubeDataService } from './youtube-data.service'
1717

1818
@Controller()
1919
export class DataCubeController {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Module } from '@nestjs/common'
2+
import { PinterestDataService } from '../../core/data-cube/pinterest-data.service'
3+
import { PinterestModule } from '../../core/platforms/pinterest/pinterest.module'
4+
import { AccountModule } from '../account/account.module'
5+
import { BilibiliModule } from '../platforms/bilibili/bilibili.module'
6+
import { MetaModule } from '../platforms/meta/meta.module'
7+
import { WxPlatModule } from '../platforms/wx-plat/wx-plat.module'
8+
import { YoutubeModule } from '../platforms/youtube/youtube.module'
9+
import { BilibiliDataService } from './bilibili-data.service'
10+
import { DataCubeController } from './data-cube.controller'
11+
import { FacebookDataService } from './facebook-data.service'
12+
import { InstagramDataService } from './instagram.service'
13+
import { ThreadsDataService } from './threads.service'
14+
import { WxGzhDataService } from './wx-gzh-data.service'
15+
import { YoutubeDataService } from './youtube-data.service'
16+
17+
@Module({
18+
imports: [BilibiliModule, MetaModule, YoutubeModule, WxPlatModule, PinterestModule, AccountModule],
19+
controllers: [DataCubeController],
20+
providers: [BilibiliDataService, FacebookDataService, InstagramDataService, ThreadsDataService, YoutubeDataService, WxGzhDataService, PinterestDataService],
21+
exports: [BilibiliDataService, FacebookDataService, InstagramDataService, ThreadsDataService, YoutubeDataService, WxGzhDataService, PinterestDataService],
22+
})
23+
export class DataCubeModule {}

project/backend/apps/aitoearn-channel/src/core/dataCube/data.base.ts renamed to project/backend/apps/aitoearn-channel/src/core/data-cube/data.base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ChannelAccountDataCube,
44
ChannelArcDataBulk,
55
ChannelArcDataCube,
6-
} from '../plat/common'
6+
} from '../platforms/common'
77

88
export abstract class DataCubeBase {
99
/**

project/backend/apps/aitoearn-channel/src/core/dataCube/dto/dataCube.dto.ts renamed to project/backend/apps/aitoearn-channel/src/core/data-cube/dto/data-cube.dto.ts

File renamed without changes.

0 commit comments

Comments
 (0)