Skip to content

Commit 9626378

Browse files
committed
fix: lint and fix cache service
Signed-off-by: Innei <[email protected]>
1 parent 128b92c commit 9626378

File tree

68 files changed

+139
-219
lines changed

Some content is hidden

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

68 files changed

+139
-219
lines changed

.github/workflows/api-client.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ on:
1010
- main
1111
paths:
1212
- 'packages/api-client/**'
13-
- '.github/workflows/api-client.yml'
13+
- .github/workflows/api-client.yml
1414
pull_request:
1515
branches: [master, main]
1616
paths:
1717
- 'packages/api-client/**'
18-
- '.github/workflows/api-client.yml'
18+
- .github/workflows/api-client.yml
1919

2020
jobs:
2121
build:

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
tags-ignore:
44
- 'v*'
55
paths-ignore:
6-
- 'CHANGELOG.MD'
6+
- CHANGELOG.MD
77
branches: master
88
pull_request:
99
workflow_dispatch:

.github/workflows/release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
name: Download release
9696
with:
9797
tag: ${{ github.ref_name }}
98-
fileName: 'release-linux.zip'
98+
fileName: release-linux.zip
9999
- name: copy file via ssh password
100100
uses: appleboy/[email protected]
101101
with:
@@ -104,8 +104,8 @@ jobs:
104104
password: ${{ secrets.PASSWORD }}
105105
# port: ${{ secrets.PORT }}
106106
key: ${{ secrets.KEY }}
107-
source: 'release-linux.zip'
108-
target: '/tmp/mx-core'
107+
source: release-linux.zip
108+
target: /tmp/mx-core
109109

110110
- name: Exec deploy script with SSH
111111
uses: appleboy/ssh-action@master
@@ -134,7 +134,7 @@ jobs:
134134
strategy:
135135
matrix:
136136
os: [ubuntu-latest]
137-
arch: ['amd64']
137+
arch: [amd64]
138138
steps:
139139
- name: Checkout
140140
uses: actions/checkout@v4

.vscode/settings.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
"editor.defaultFormatter": "esbenp.prettier-vscode"
1414
},
1515
"material-icon-theme.activeIconPack": "nest",
16-
"cSpell.words": [
17-
"qaqdmin"
18-
],
16+
"cSpell.words": ["qaqdmin"],
1917
"typescript.tsdk": "node_modules/typescript/lib",
2018
"yaml.schemas": {
2119
"https://json.schemastore.org/github-workflow.json": "file:///Users/xiaoxun/github/innei-repo/mx-space/mx-server/.github/workflows/build.yml"
2220
},
2321
"typescript.preferences.preferTypeOnlyAutoImports": false
24-
}
22+
}

apps/core/download-latest-admin-assets-dev.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!env node
2-
const { appendFileSync } = require('fs')
3-
const { join } = require('path')
2+
const { appendFileSync } = require('node:fs')
3+
const { join } = require('node:path')
44
const { fetch, $ } = require('zx-cjs')
55
const {
66
dashboard: { repo, version },

apps/core/download-latest-admin-assets.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!env node
2-
const { appendFileSync } = require('fs')
3-
const { join } = require('path')
2+
const { appendFileSync } = require('node:fs')
3+
const { join } = require('node:path')
44
const { fetch, $ } = require('zx-cjs')
55
const {
66
dashboard: { repo, version },

apps/core/ecosystem.dev.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { execSync } = require('child_process')
1+
const { execSync } = require('node:child_process')
22
const nodePath = execSync(`npm root --quiet -g`, { encoding: 'utf-8' }).split(
33
'\n',
44
)[0]

apps/core/src/app.controller.ts

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { IpLocation, IpRecord } from './common/decorators/ip.decorator'
2020
import { AllowAllCorsInterceptor } from './common/interceptors/allow-all-cors.interceptor'
2121
import { RedisKeys } from './constants/cache.constant'
2222
import { OptionModel } from './modules/configs/configs.model'
23-
import { CacheService } from './processors/redis/cache.service'
2423
import { RedisService } from './processors/redis/redis.service'
2524
import { getRedisKey } from './utils/redis.util'
2625

apps/core/src/bootstrap.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { performance } from 'node:perf_hooks'
33
import wcmatch from 'wildcard-match'
44
import type { FastifyCorsOptions } from '@fastify/cors'
55
import type { LogLevel } from '@nestjs/common'
6-
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface'
76
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
87

98
import { Logger } from '@innei/pretty-logger-nestjs'

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

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as SYSTEM from '~/constants/system.constant'
2323
import { REFLECTOR } from '~/constants/system.constant'
2424
import { AnalyzeModel } from '~/modules/analyze/analyze.model'
2525
import { OptionModel } from '~/modules/configs/configs.model'
26-
import { CacheService } from '~/processors/redis/cache.service'
2726
import { RedisService } from '~/processors/redis/redis.service'
2827
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
2928
import { InjectModel } from '~/transformers/model.transformer'

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

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
HTTP_IDEMPOTENCE_OPTIONS,
2020
} from '~/constants/meta.constant'
2121
import { REFLECTOR } from '~/constants/system.constant'
22-
import { CacheService } from '~/processors/redis/cache.service'
2322
import { RedisService } from '~/processors/redis/redis.service'
2423
import { getIp } from '~/utils/ip.util'
2524
import { getRedisKey } from '~/utils/redis.util'

apps/core/src/constants/business-event.constant.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
21
export enum BusinessEvents {
32
GATEWAY_CONNECT = 'GATEWAY_CONNECT',
43
GATEWAY_DISCONNECT = 'GATEWAY_DISCONNECT',

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

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { omit, pick, uniqBy } from 'lodash'
22
import { ObjectId } from 'mongodb'
3-
import { Types } from 'mongoose'
43
import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'
5-
import type { Collection } from 'mongodb'
64
import type { Document } from 'mongoose'
75
import type { Socket } from 'socket.io'
86
import type { NoteModel } from '../note/note.model'

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

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
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'
20-
import { CacheService } from '~/processors/redis/cache.service'
2120
import { RedisService } from '~/processors/redis/redis.service'
2221
import { addYearCondition } from '~/transformers/db-query.transformer'
2322
import { getRedisKey } from '~/utils/redis.util'

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { BusinessEvents } from '~/constants/business-event.constant'
1010
import { CollectionRefTypes } from '~/constants/db.constant'
1111
import { ErrorCodeEnum } from '~/constants/error-code.constant'
1212
import { DatabaseService } from '~/processors/database/database.service'
13-
import { CacheService } from '~/processors/redis/cache.service'
1413
import { RedisService } from '~/processors/redis/redis.service'
1514
import { InjectModel } from '~/transformers/model.transformer'
1615
import { transformDataToPaginate } from '~/transformers/paginate.transformer'

apps/core/src/modules/ai/ai.constants.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { OpenAI } from 'openai'
21
import type { ChatModel } from 'openai/resources'
32

43
export const DEFAULT_SUMMARY_LANG = 'zh'

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

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ApiController } from '~/common/decorators/api-controller.decorator'
77
import { Auth } from '~/common/decorators/auth.decorator'
88
import { Paginator } from '~/common/decorators/http.decorator'
99
import { RedisKeys } from '~/constants/cache.constant'
10-
import { CacheService } from '~/processors/redis/cache.service'
1110
import { RedisService } from '~/processors/redis/redis.service'
1211
import { getRedisKey } from '~/utils/redis.util'
1312
import { getTodayEarly, getWeekStart } from '~/utils/time.util'

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

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Injectable } from '@nestjs/common'
66
import { ReturnModelType } from '@typegoose/typegoose'
77

88
import { RedisKeys } from '~/constants/cache.constant'
9-
import { CacheService } from '~/processors/redis/cache.service'
109
import { RedisService } from '~/processors/redis/redis.service'
1110
import { InjectModel } from '~/transformers/model.transformer'
1211
import { getRedisKey } from '~/utils/redis.util'

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ReturnModelType } from '@typegoose/typegoose'
2121

2222
import { RequestContext } from '~/common/contexts/request.context'
2323
import { RedisKeys } from '~/constants/cache.constant'
24-
import { CacheService } from '~/processors/redis/cache.service'
24+
import { RedisService } from '~/processors/redis/redis.service'
2525
import { InjectModel } from '~/transformers/model.transformer'
2626
import { getRedisKey } from '~/utils/redis.util'
2727

@@ -38,7 +38,7 @@ export class AuthnService {
3838
@InjectModel(AuthnModel)
3939
private readonly authnModel: ReturnModelType<typeof AuthnModel>,
4040

41-
private readonly cacheService: CacheService,
41+
private readonly redisService: RedisService,
4242
private readonly configService: ConfigsService,
4343
) {}
4444

@@ -109,16 +109,14 @@ export class AuthnService {
109109
}
110110

111111
private async setCurrentChallenge(challenge: string) {
112-
await this.cacheService.set(
113-
getRedisKey(RedisKeys.Authn),
114-
challenge,
115-
// 5 min
116-
1000 * 60 * 5,
117-
)
112+
const redisClient = this.redisService.getClient()
113+
await redisClient.set(getRedisKey(RedisKeys.Authn), challenge)
114+
// 5 min
115+
await redisClient.expire(getRedisKey(RedisKeys.Authn), 1000 * 60 * 5)
118116
}
119117

120118
private async getCurrentChallenge() {
121-
return await this.cacheService.get<string>(getRedisKey(RedisKeys.Authn))
119+
return await this.redisService.getClient().get(getRedisKey(RedisKeys.Authn))
122120
}
123121

124122
async verifyRegistrationResponse(

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

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
import { BACKUP_DIR, DATA_DIR } from '~/constants/path.constant'
2626
import { migrateDatabase } from '~/migration/migrate'
2727
import { EventManagerService } from '~/processors/helper/helper.event.service'
28-
import { CacheService } from '~/processors/redis/cache.service'
2928
import { RedisService } from '~/processors/redis/redis.service'
3029
import { scheduleManager } from '~/utils/schedule.util'
3130
import { getFolderSize, installPKG } from '~/utils/system.util'

apps/core/src/modules/markdown/markdown.util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ marked.use({
1616
)}\n</span>`
1717
},
1818
tokenizer(src) {
19-
const rule = /^\|\|([\S\s]+?)\|\|(?!\|)/
19+
const rule = /^\|\|([\s\S]+?)\|\|(?!\|)/
2020
const match = rule.exec(src)
2121
if (match) {
2222
return {
@@ -39,7 +39,7 @@ marked.use({
3939
return `<span class="katex-render">${token.text}</span>`
4040
},
4141
tokenizer(src) {
42-
const rule = /^\$([\S\s]+?)\$(?!\$)/
42+
const rule = /^\$([\s\S]+?)\$(?!\$)/
4343
const match = rule.exec(src)
4444
if (match) {
4545
return {
@@ -71,7 +71,7 @@ marked.use({
7171
},
7272
tokenizer(src) {
7373
const rule =
74-
/^{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))}\s?(?!\[.*?])/
74+
/^\{((?<prefix>(GH)|(TW)|(TG))@(?<name>\w+\b))\}\s?(?!\[.*?\])/
7575
const match = rule.exec(src)
7676
if (match) {
7777
const { groups } = match

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class PageProxyController {
4343
}
4444
const log = this.fetchLogs.pop() || '...'
4545

46-
reply.code(200).type('text/html').send(`${log}`)
46+
reply.code(200).type('text/html').send(String(log))
4747
return
4848
}
4949

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

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { RedisKeys } from '~/constants/cache.constant'
1515
import { CollectionRefTypes } from '~/constants/db.constant'
1616
import { DatabaseService } from '~/processors/database/database.service'
1717
import { EventManagerService } from '~/processors/helper/helper.event.service'
18-
import { CacheService } from '~/processors/redis/cache.service'
1918
import { RedisService } from '~/processors/redis/redis.service'
2019
import { InjectModel } from '~/transformers/model.transformer'
2120
import { getRedisKey } from '~/utils/redis.util'

apps/core/src/modules/serverless/serverless.readme.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ async function handler() {
1414

1515
const { BiliClient } = extra
1616
const bl = await context.getMaster().then((user) => user.socialIds.bilibili)
17-
const client = new BiliClient(parseInt(bl || uid))
18-
const bangumi = await client.getFavoriteBangumi(parseInt(len))
17+
const client = new BiliClient(Number.parseInt(bl || uid))
18+
const bangumi = await client.getFavoriteBangumi(Number.parseInt(len))
1919
return bangumi
2020
}
2121

@@ -35,9 +35,9 @@ const len = 10
3535

3636
```js
3737
// require built-in module
38-
const path = await require('path') // ok
38+
const path = await require('node:path') // ok
3939
// `os` `sys` module is banned, because is dangerous
40-
const os = await require('os') // error
40+
const os = await require('node:os') // error
4141

4242
// require third module, you can require some trusted third party modules.
4343
const axios = await require('axios') // ok, but you must install this module in data_dir/node_modules or other NODE_PATH
@@ -71,11 +71,8 @@ const remoteModule =
7171
用法如下:
7272

7373
```ts
74-
import axios from 'axios'
7574
// this is ok, will transformer to `var axios = await require('axios')`
76-
import { render } from 'ejs'
7775
// ok, transform to var _ejs = await require("ejs"); _ejs.render
78-
import * as ejs from 'ejs'
7976

8077
// bad, don't recommend
8178
```

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { DatabaseService } from '~/processors/database/database.service'
3434
import { AssetService } from '~/processors/helper/helper.asset.service'
3535
import { EventManagerService } from '~/processors/helper/helper.event.service'
3636
import { HttpService } from '~/processors/helper/helper.http.service'
37-
import { CacheService } from '~/processors/redis/cache.service'
3837
import { RedisService } from '~/processors/redis/redis.service'
3938
import { InjectModel } from '~/transformers/model.transformer'
4039
import { EncryptUtil } from '~/utils/encrypt.util'

apps/core/src/modules/serverless/serverless.util.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable import/no-duplicates */
21
import type { TransformOptions } from '@babel/core'
32
import type * as t from '@babel/types'
43
import type { VariableDeclaration } from '@babel/types'

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

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { EventScope } from '~/constants/business-event.constant'
1717
import { RedisKeys } from '~/constants/cache.constant'
1818
import { EventBusEvents } from '~/constants/event-bus.constant'
1919
import { EventManagerService } from '~/processors/helper/helper.event.service'
20-
import { CacheService } from '~/processors/redis/cache.service'
2120
import { RedisService } from '~/processors/redis/redis.service'
2221
import { InjectModel } from '~/transformers/model.transformer'
2322
import { getRedisKey } from '~/utils/redis.util'

apps/core/src/modules/topic/topic.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'class-validator'
88
import slugify from 'slugify'
99

10-
import { index, modelOptions, prop } from '@typegoose/typegoose'
10+
import { modelOptions, prop } from '@typegoose/typegoose'
1111

1212
import { TOPIC_COLLECTION_NAME } from '~/constants/db.constant'
1313
import { BaseModel } from '~/shared/model/base.model'

apps/core/src/processors/gateway/gateway.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { RedisKeys } from '~/constants/cache.constant'
1111
import { getRedisKey } from '~/utils/redis.util'
1212
import { safeJSONParse } from '~/utils/tool.util'
1313

14-
import { CacheService } from '../redis/cache.service'
1514
import { RedisService } from '../redis/redis.service'
1615

1716
export type SocketType =

apps/core/src/processors/gateway/shared/auth.gateway.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { EventBusEvents } from '~/constants/event-bus.constant'
1111
import { AuthService } from '~/modules/auth/auth.service'
1212
import { JWTService } from '~/processors/helper/helper.jwt.service'
13-
import { CacheService } from '~/processors/redis/cache.service'
1413
import { RedisService } from '~/processors/redis/redis.service'
1514

1615
import { BusinessEvents } from '../../../constants/business-event.constant'

apps/core/src/processors/gateway/web/events.gateway.ts

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323

2424
import { BusinessEvents } from '~/constants/business-event.constant'
2525
import { RedisKeys } from '~/constants/cache.constant'
26-
import { CacheService } from '~/processors/redis/cache.service'
2726
import { RedisService } from '~/processors/redis/redis.service'
2827
import { getRedisKey } from '~/utils/redis.util'
2928
import { scheduleManager } from '~/utils/schedule.util'

apps/core/src/processors/helper/helper.counting.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { RedisKeys } from '~/constants/cache.constant'
66
import { getRedisKey } from '~/utils/redis.util'
77

88
import { DatabaseService } from '../database/database.service'
9-
import { CacheService } from '../redis/cache.service'
109
import { RedisService } from '../redis/redis.service'
1110

1211
@Injectable()

apps/core/src/processors/helper/helper.http.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { RedisKeys } from '~/constants/cache.constant'
1010
import { getRedisKey } from '~/utils/redis.util'
1111

1212
import { version } from '../../../package.json'
13-
import { CacheService } from '../redis/cache.service'
1413
import { RedisService } from '../redis/redis.service'
1514

1615
const DEFAULT_UA = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 MX-Space/${version}`

apps/core/src/processors/helper/helper.jwt.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { logger } from '~/global/consola.global'
99
import { getRedisKey } from '~/utils/redis.util'
1010
import { md5 } from '~/utils/tool.util'
1111

12-
import { CacheService } from '../redis/cache.service'
1312
import { RedisService } from '../redis/redis.service'
1413

1514
@Injectable()

apps/core/src/processors/helper/helper.tq.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Injectable } from '@nestjs/common'
55

66
import { safeJSONParse } from '~/utils/tool.util'
77

8-
import { CacheService } from '../redis/cache.service'
98
import { RedisService } from '../redis/redis.service'
109

1110
type ITask = RedisMap<

0 commit comments

Comments
 (0)