Skip to content

Commit b1f69c7

Browse files
committed
feat!: upgrade nest to v11
Signed-off-by: Innei <tukon479@gmail.com>
1 parent 4d0d85e commit b1f69c7

Some content is hidden

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

41 files changed

+656
-597
lines changed

apps/core/package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,41 @@
5959
"@babel/plugin-transform-modules-commonjs": "7.26.3",
6060
"@babel/plugin-transform-typescript": "7.26.7",
6161
"@babel/types": "^7.26.7",
62-
"@fastify/cookie": "9.4.0",
63-
"@fastify/multipart": "8.3.0",
62+
"@fastify/cookie": "11.0.2",
63+
"@fastify/multipart": "9.0.3",
6464
"@fastify/static": "8.1.0",
6565
"@innei/next-async": "0.3.0",
6666
"@innei/pretty-logger-nestjs": "0.3.3",
67-
"@langchain/openai": "0.3.17",
67+
"@keyv/redis": "4.2.0",
68+
"@langchain/openai": "0.4.2",
6869
"@mx-space/compiled": "workspace:*",
69-
"@nestjs/cache-manager": "2.3.0",
70-
"@nestjs/common": "10.4.15",
71-
"@nestjs/core": "10.4.15",
72-
"@nestjs/event-emitter": "2.1.1",
70+
"@nestjs/cache-manager": "3.0.0",
71+
"@nestjs/common": "11.0.7",
72+
"@nestjs/core": "11.0.7",
73+
"@nestjs/event-emitter": "3.0.0",
7374
"@nestjs/mapped-types": "^2.1.0",
74-
"@nestjs/platform-fastify": "10.4.15",
75-
"@nestjs/platform-socket.io": "10.4.15",
76-
"@nestjs/schedule": "4.1.2",
75+
"@nestjs/platform-fastify": "11.0.7",
76+
"@nestjs/platform-socket.io": "11.0.7",
77+
"@nestjs/schedule": "5.0.1",
7778
"@nestjs/throttler": "6.4.0",
78-
"@nestjs/websockets": "10.4.15",
79+
"@nestjs/websockets": "11.0.7",
7980
"@simplewebauthn/server": "10.0.1",
8081
"@socket.io/redis-adapter": "8.3.0",
8182
"@socket.io/redis-emitter": "5.1.0",
8283
"@typegoose/auto-increment": "4.9.0",
8384
"@typegoose/typegoose": "12.8.0",
8485
"@types/jsonwebtoken": "9.0.8",
8586
"algoliasearch": "4.24.0",
86-
"axios": "^1.7.8",
87+
"axios": "^1.7.9",
8788
"axios-retry": "4.5.0",
8889
"bcryptjs": "^2.4.3",
8990
"blurhash": "2.0.5",
90-
"cache-manager": "5.7.6",
91-
"cache-manager-ioredis-yet": "2.1.2",
91+
"cache-manager": "6.4.0",
9292
"class-transformer": "0.5.1",
9393
"class-validator": "0.13.2",
9494
"class-validator-jsonschema": "npm:@innei/class-validator-jsonschema@3.1.2",
9595
"cls-hooked": "^4.2.2",
96-
"commander": "12.1.0",
96+
"commander": "13.1.0",
9797
"dayjs": "1.11.13",
9898
"ejs": "3.1.10",
9999
"form-data": "4.0.1",
@@ -103,6 +103,7 @@
103103
"json5": "2.2.3",
104104
"jsonwebtoken": "9.0.2",
105105
"jszip": "3.10.1",
106+
"keyv": "5.2.3",
106107
"langchain": "0.3.15",
107108
"linkedom": "0.18.7",
108109
"lodash": "^4.17.21",
@@ -111,13 +112,13 @@
111112
"mime-types": "^2.1.35",
112113
"mkdirp": "^3.0.1",
113114
"mongoose": "8.7.0",
114-
"mongoose-aggregate-paginate-v2": "1.1.2",
115+
"mongoose-aggregate-paginate-v2": "1.1.3",
115116
"mongoose-autopopulate": "1.1.0",
116117
"mongoose-lean-getters": "2.1.1",
117-
"mongoose-lean-virtuals": "1.0.0",
118+
"mongoose-lean-virtuals": "1.1.0",
118119
"mongoose-paginate-v2": "1.9.0",
119120
"node-machine-id": "1.1.12",
120-
"nodemailer": "6.9.16",
121+
"nodemailer": "6.10.0",
121122
"openai": "4.82.0",
122123
"pluralize": "^8.0.0",
123124
"qs": "6.14.0",
@@ -143,12 +144,12 @@
143144
"@swc/core": "1.10.14",
144145
"@types/babel__core": "7.20.5",
145146
"@types/bcryptjs": "^2.4.6",
146-
"@types/cache-manager": "4.0.6",
147+
"@types/cache-manager": "5.0.0",
147148
"@types/cls-hooked": "^4.3.9",
148149
"@types/ejs": "3.1.5",
149150
"@types/get-image-colors": "4.0.5",
150151
"@types/js-yaml": "4.0.9",
151-
"@types/lodash": "4.17.14",
152+
"@types/lodash": "4.17.15",
152153
"@types/mime-types": "2.1.4",
153154
"@types/mongoose-aggregate-paginate-v2": "1.0.12",
154155
"@types/node": "22.13.1",
@@ -169,4 +170,4 @@
169170
"vitest": "1.5.2",
170171
"zx": "7.2.3"
171172
}
172-
}
173+
}

apps/core/src/app.controller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import { AllowAllCorsInterceptor } from './common/interceptors/allow-all-cors.in
2121
import { RedisKeys } from './constants/cache.constant'
2222
import { OptionModel } from './modules/configs/configs.model'
2323
import { CacheService } from './processors/redis/cache.service'
24+
import { RedisService } from './processors/redis/redis.service'
2425
import { getRedisKey } from './utils/redis.util'
2526

2627
@ApiController()
2728
export class AppController {
2829
constructor(
29-
private readonly cacheService: CacheService,
30+
private readonly redisService: RedisService,
3031
@InjectModel(OptionModel)
3132
private readonly optionModel: MongooseModel<OptionModel>,
3233
) {}
@@ -64,7 +65,7 @@ export class AppController {
6465
@HttpCache.disable
6566
@HttpCode(204)
6667
async likeThis(@IpLocation() { ip }: IpRecord) {
67-
const redis = this.cacheService.getClient()
68+
const redis = this.redisService.getClient()
6869

6970
const isLikedBefore = await redis.sismember(
7071
getRedisKey(RedisKeys.LikeSite),
@@ -100,13 +101,13 @@ export class AppController {
100101
@HttpCache.disable
101102
@Auth()
102103
async cleanCatch() {
103-
await this.cacheService.cleanCatch()
104+
await this.redisService.cleanCatch()
104105
}
105106

106107
@Get('/clean_redis')
107108
@HttpCache.disable
108109
@Auth()
109110
async cleanAllRedisKey() {
110-
await this.cacheService.cleanAllRedisKey()
111+
await this.redisService.cleanAllRedisKey()
111112
}
112113
}

apps/core/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ export class AppModule implements NestModule {
175175
}
176176
}
177177
configure(consumer: MiddlewareConsumer) {
178-
consumer.apply(RequestContextMiddleware).forRoutes('(.*)')
178+
consumer.apply(RequestContextMiddleware).forRoutes('*app')
179179
}
180180
}

apps/core/src/bootstrap.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import cluster from 'node:cluster'
22
import { performance } from 'node:perf_hooks'
33
import wcmatch from 'wildcard-match'
4+
import type { FastifyCorsOptions } from '@fastify/cors'
45
import type { LogLevel } from '@nestjs/common'
56
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface'
67
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
@@ -40,11 +41,12 @@ export async function bootstrap() {
4041
},
4142
)
4243

43-
const allowAllCors: CorsOptions = {
44+
const allowAllCors: FastifyCorsOptions = {
4445
credentials: true,
45-
origin: (origin, callback) => callback(null, origin),
46+
origin: (origin, callback) => callback(null, origin || ''),
4647
}
4748
// Origin 如果不是数组就全部允许跨域
49+
4850
app.enableCors(
4951
isDev
5052
? allowAllCors
@@ -53,14 +55,14 @@ export async function bootstrap() {
5355
origin: (origin, callback) => {
5456
let currentHost: string
5557
try {
56-
currentHost = new URL(origin).host
58+
currentHost = new URL(origin || '').host
5759
} catch {
58-
currentHost = origin
60+
currentHost = origin || ''
5961
}
6062
const allow = Origin.some((host) => wcmatch(host)(currentHost))
6163

6264
if (allow) {
63-
callback(null, origin)
65+
callback(null, origin || '')
6466
} else {
6567
callback(null, false)
6668
}

apps/core/src/common/interceptors/analyze.interceptor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { REFLECTOR } from '~/constants/system.constant'
2424
import { AnalyzeModel } from '~/modules/analyze/analyze.model'
2525
import { OptionModel } from '~/modules/configs/configs.model'
2626
import { CacheService } from '~/processors/redis/cache.service'
27+
import { RedisService } from '~/processors/redis/redis.service'
2728
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
2829
import { InjectModel } from '~/transformers/model.transformer'
2930
import { getIp } from '~/utils/ip.util'
@@ -40,7 +41,7 @@ export class AnalyzeInterceptor implements NestInterceptor {
4041
private readonly model: ReturnModelType<typeof AnalyzeModel>,
4142
@InjectModel(OptionModel)
4243
private readonly options: ReturnModelType<typeof OptionModel>,
43-
private readonly cacheService: CacheService,
44+
private readonly redisService: RedisService,
4445
@Inject(REFLECTOR) private readonly reflector: Reflector,
4546
) {
4647
this.init()
@@ -121,7 +122,7 @@ export class AnalyzeInterceptor implements NestInterceptor {
121122
})
122123

123124
// ip access in redis
124-
const client = this.cacheService.getClient()
125+
const client = this.redisService.getClient()
125126

126127
const count = await client.sadd(getRedisKey(RedisKeys.AccessIp), ip)
127128
if (count) {

apps/core/src/common/interceptors/idempotence.interceptor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '~/constants/meta.constant'
2121
import { REFLECTOR } from '~/constants/system.constant'
2222
import { CacheService } from '~/processors/redis/cache.service'
23+
import { RedisService } from '~/processors/redis/redis.service'
2324
import { getIp } from '~/utils/ip.util'
2425
import { getRedisKey } from '~/utils/redis.util'
2526
import { hashString } from '~/utils/tool.util'
@@ -56,7 +57,7 @@ export type IdempotenceOption = {
5657
@Injectable()
5758
export class IdempotenceInterceptor implements NestInterceptor {
5859
constructor(
59-
private readonly cacheService: CacheService,
60+
private readonly redisService: RedisService,
6061
@Inject(REFLECTOR) private readonly reflector: Reflector,
6162
) {}
6263

@@ -85,7 +86,7 @@ export class IdempotenceInterceptor implements NestInterceptor {
8586
expired = 60,
8687
disableGenerateKey = false,
8788
} = options
88-
const redis = this.cacheService.getClient()
89+
const redis = this.redisService.getClient()
8990

9091
const idempotence = request.headers[IdempotenceHeaderKey] as string
9192
const key = disableGenerateKey

apps/core/src/modules/aggregate/aggregate.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { EventBusEvents } from '~/constants/event-bus.constant'
1818
import { WebEventsGateway } from '~/processors/gateway/web/events.gateway'
1919
import { UrlBuilderService } from '~/processors/helper/helper.url-builder.service'
2020
import { CacheService } from '~/processors/redis/cache.service'
21+
import { RedisService } from '~/processors/redis/redis.service'
2122
import { addYearCondition } from '~/transformers/db-query.transformer'
2223
import { getRedisKey } from '~/utils/redis.util'
2324
import { getShortDate } from '~/utils/time.util'
@@ -66,7 +67,7 @@ export class AggregateService {
6667

6768
private readonly configs: ConfigsService,
6869
private readonly gateway: WebEventsGateway,
69-
private readonly cacheService: CacheService,
70+
private readonly redisService: RedisService,
7071
) {}
7172

7273
getAllCategory() {
@@ -353,7 +354,7 @@ export class AggregateService {
353354
}
354355

355356
async getCounts() {
356-
const redisClient = this.cacheService.getClient()
357+
const redisClient = this.redisService.getClient()
357358
const dateFormat = getShortDate(new Date())
358359

359360
const [
@@ -423,7 +424,7 @@ export class AggregateService {
423424

424425
@OnEvent(EventBusEvents.CleanAggregateCache, { async: true })
425426
public clearAggregateCache() {
426-
const redis = this.cacheService.getClient()
427+
const redis = this.redisService.getClient()
427428
return Promise.all([
428429
redis.del(CacheKeys.RSS),
429430
redis.del(CacheKeys.RSSXml),

apps/core/src/modules/ai/ai-summary/ai-summary.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CollectionRefTypes } from '~/constants/db.constant'
1111
import { ErrorCodeEnum } from '~/constants/error-code.constant'
1212
import { DatabaseService } from '~/processors/database/database.service'
1313
import { CacheService } from '~/processors/redis/cache.service'
14+
import { RedisService } from '~/processors/redis/redis.service'
1415
import { InjectModel } from '~/transformers/model.transformer'
1516
import { transformDataToPaginate } from '~/transformers/paginate.transformer'
1617
import { md5 } from '~/utils/tool.util'
@@ -29,7 +30,7 @@ export class AiSummaryService {
2930
private readonly databaseService: DatabaseService,
3031
private readonly configService: ConfigsService,
3132

32-
private readonly cacheService: CacheService,
33+
private readonly redisService: RedisService,
3334
private readonly aiService: AiService,
3435
) {
3536
this.logger = new Logger(AiSummaryService.name)
@@ -108,7 +109,7 @@ export class AiSummaryService {
108109
if (this.cachedTaskId2AiPromise.has(taskId)) {
109110
return this.cachedTaskId2AiPromise.get(taskId)
110111
}
111-
const redis = this.cacheService.getClient()
112+
const redis = this.redisService.getClient()
112113

113114
const isProcessing = await redis.get(taskId)
114115

apps/core/src/modules/analyze/analyze.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Auth } from '~/common/decorators/auth.decorator'
88
import { Paginator } from '~/common/decorators/http.decorator'
99
import { RedisKeys } from '~/constants/cache.constant'
1010
import { CacheService } from '~/processors/redis/cache.service'
11+
import { RedisService } from '~/processors/redis/redis.service'
1112
import { getRedisKey } from '~/utils/redis.util'
1213
import { getTodayEarly, getWeekStart } from '~/utils/time.util'
1314

@@ -19,7 +20,7 @@ import { AnalyzeService } from './analyze.service'
1920
export class AnalyzeController {
2021
constructor(
2122
private readonly service: AnalyzeService,
22-
private readonly cacheService: CacheService,
23+
private readonly redisService: RedisService,
2324
) {}
2425

2526
@Get('/')
@@ -148,7 +149,7 @@ export class AnalyzeController {
148149

149150
@Get('/like')
150151
async getTodayLikedArticle() {
151-
const client = this.cacheService.getClient()
152+
const client = this.redisService.getClient()
152153
const keys = await client.keys(getRedisKey(RedisKeys.Like, '*'))
153154

154155
return Promise.all(

apps/core/src/modules/analyze/analyze.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ReturnModelType } from '@typegoose/typegoose'
77

88
import { RedisKeys } from '~/constants/cache.constant'
99
import { CacheService } from '~/processors/redis/cache.service'
10+
import { RedisService } from '~/processors/redis/redis.service'
1011
import { InjectModel } from '~/transformers/model.transformer'
1112
import { getRedisKey } from '~/utils/redis.util'
1213

@@ -20,7 +21,7 @@ export class AnalyzeService {
2021
private readonly options: ReturnModelType<typeof OptionModel>,
2122
@InjectModel(AnalyzeModel)
2223
private readonly analyzeModel: MongooseModel<AnalyzeModel>,
23-
private readonly cacheService: CacheService,
24+
private readonly redisService: RedisService,
2425
) {}
2526

2627
public get model() {
@@ -289,7 +290,7 @@ export class AnalyzeService {
289290
}
290291

291292
async getTodayAccessIp(): Promise<string[]> {
292-
const redis = this.cacheService.getClient()
293+
const redis = this.redisService.getClient()
293294
const fromRedisIps = await redis.smembers(getRedisKey(RedisKeys.AccessIp))
294295

295296
return fromRedisIps

0 commit comments

Comments
 (0)