完善注释

This commit is contained in:
Jerry 2025-07-31 11:02:08 +08:00
parent 7c4b933e9d
commit 08f74445da
10 changed files with 108 additions and 3 deletions

View File

@ -26,7 +26,8 @@
"reflect-metadata": "^0.2.2", "reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
"simple-git": "^3.28.0", "simple-git": "^3.28.0",
"ssh2": "^1.16.0" "ssh2": "^1.16.0",
"ws": "^8.18.3"
}, },
"devDependencies": { "devDependencies": {
"@eslint/eslintrc": "^3.2.0", "@eslint/eslintrc": "^3.2.0",
@ -40,6 +41,7 @@
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
"@types/node": "^22.16.4", "@types/node": "^22.16.4",
"@types/supertest": "^6.0.2", "@types/supertest": "^6.0.2",
"@types/ws": "^8.18.1",
"eslint": "^9.18.0", "eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2", "eslint-plugin-prettier": "^5.2.2",

25
pnpm-lock.yaml generated
View File

@ -41,6 +41,9 @@ dependencies:
ssh2: ssh2:
specifier: ^1.16.0 specifier: ^1.16.0
version: 1.16.0 version: 1.16.0
ws:
specifier: ^8.18.3
version: 8.18.3
devDependencies: devDependencies:
'@eslint/eslintrc': '@eslint/eslintrc':
@ -76,6 +79,9 @@ devDependencies:
'@types/supertest': '@types/supertest':
specifier: ^6.0.2 specifier: ^6.0.2
version: 6.0.3 version: 6.0.3
'@types/ws':
specifier: ^8.18.1
version: 8.18.1
eslint: eslint:
specifier: ^9.18.0 specifier: ^9.18.0
version: 9.31.0 version: 9.31.0
@ -2008,6 +2014,12 @@ packages:
'@types/superagent': 8.1.9 '@types/superagent': 8.1.9
dev: true dev: true
/@types/ws@8.18.1:
resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==}
dependencies:
'@types/node': 22.16.5
dev: true
/@types/yargs-parser@21.0.3: /@types/yargs-parser@21.0.3:
resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==}
dev: true dev: true
@ -6487,6 +6499,19 @@ packages:
signal-exit: 3.0.7 signal-exit: 3.0.7
dev: true dev: true
/ws@8.18.3:
resolution: {integrity: sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==}
engines: {node: '>=10.0.0'}
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: '>=5.0.2'
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
dev: false
/xtend@4.0.2: /xtend@4.0.2:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'} engines: {node: '>=0.4'}

View File

@ -6,6 +6,9 @@ import {
HttpStatus, HttpStatus,
} from '@nestjs/common'; } from '@nestjs/common';
/**
*
*/
@Catch() @Catch()
export class AllExceptionsFilter implements ExceptionFilter { export class AllExceptionsFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) { catch(exception: unknown, host: ArgumentsHost) {

View File

@ -7,6 +7,9 @@ import {
import { Observable, map } from 'rxjs'; import { Observable, map } from 'rxjs';
import { ApiResponse } from '../response-format'; import { ApiResponse } from '../response-format';
/**
*
*/
@Injectable() @Injectable()
export class ResponseInterceptor<T> export class ResponseInterceptor<T>
implements NestInterceptor<T, ApiResponse<T>> implements NestInterceptor<T, ApiResponse<T>>

View File

@ -14,6 +14,11 @@ export class AppConfigService implements OnModuleInit {
this.checkRequiredVariables(); this.checkRequiredVariables();
} }
/**
*
* @param key
* @param defaultValue
*/
get<T = string>(key: string, defaultValue?: T): T | undefined { get<T = string>(key: string, defaultValue?: T): T | undefined {
const value = this.nestConfigService.get<T>(key); const value = this.nestConfigService.get<T>(key);
if (value === undefined || value === null) { if (value === undefined || value === null) {

View File

@ -22,7 +22,7 @@ export class AutoUpdateService {
} }
/** /**
* *
*/ */
async checkForUpdates(): Promise<boolean> { async checkForUpdates(): Promise<boolean> {
try { try {

View File

@ -28,6 +28,12 @@ export class PersistenceService {
} }
} }
/**
*
* @param dataName ->
* @param data
* @param fileName
*/
public async writeDataLocal<T>( public async writeDataLocal<T>(
dataName: string, dataName: string,
data: T, data: T,
@ -44,6 +50,11 @@ export class PersistenceService {
} }
} }
/**
*
* @param dataName ->
* @param fileName
*/
public async readDataLocal<T>( public async readDataLocal<T>(
dataName: string, dataName: string,
fileName: string, fileName: string,

View File

@ -63,7 +63,7 @@ export class RedisService implements OnModuleInit {
this.client.on('ready', () => { this.client.on('ready', () => {
this.isConnected = true; this.isConnected = true;
this.logger.debug('Redis连接就绪!'); this.logger.log('Redis连接就绪!');
}); });
this.client.on('reconnecting', () => { this.client.on('reconnecting', () => {
@ -71,6 +71,9 @@ export class RedisService implements OnModuleInit {
}); });
} }
/**
* redis就绪
*/
public async waitUntilReady(): Promise<void> { public async waitUntilReady(): Promise<void> {
if (this.isConnected) return; if (this.isConnected) return;
return new Promise((resolve) => { return new Promise((resolve) => {
@ -80,6 +83,9 @@ export class RedisService implements OnModuleInit {
}); });
} }
/**
* redis实例
*/
public getClient(): Redis { public getClient(): Redis {
if (!this.isConnected) { if (!this.isConnected) {
this.logger.error('Redis未连接'); this.logger.error('Redis未连接');
@ -87,11 +93,20 @@ export class RedisService implements OnModuleInit {
return this.client; return this.client;
} }
/**
*
*/
public async disconnect(): Promise<void> { public async disconnect(): Promise<void> {
await this.client.quit(); await this.client.quit();
this.isConnected = false; this.isConnected = false;
} }
/**
*
* @param key
* @param value
* @param ttl
*/
public async setObject<T>( public async setObject<T>(
key: string, key: string,
value: T, value: T,
@ -104,6 +119,10 @@ export class RedisService implements OnModuleInit {
} }
} }
/**
* redis中获取对象
* @param key
*/
public async getObject<T>(key: string): Promise<T | undefined> { public async getObject<T>(key: string): Promise<T | undefined> {
const serialized = await this.client.get(key); const serialized = await this.client.get(key);
if (!serialized) return undefined; if (!serialized) return undefined;
@ -111,6 +130,11 @@ export class RedisService implements OnModuleInit {
return RedisUtils.reviveDates(deserialized); return RedisUtils.reviveDates(deserialized);
} }
/**
* redis中的呃对象
* @param key
* @param updates
*/
public async update<T>(key: string, updates: T): Promise<T> { public async update<T>(key: string, updates: T): Promise<T> {
const existing = await this.getObject<T>(key); const existing = await this.getObject<T>(key);
if (!existing) { if (!existing) {
@ -121,6 +145,11 @@ export class RedisService implements OnModuleInit {
return updated; return updated;
} }
/**
* redis获取对象
* @param key /
* @param fileName
*/
public async fetch<T>(key: string, fileName: string): Promise<T | undefined> { public async fetch<T>(key: string, fileName: string): Promise<T | undefined> {
const data = await this.getObject<T>(key); const data = await this.getObject<T>(key);
if (data) return data; if (data) return data;
@ -134,6 +163,12 @@ export class RedisService implements OnModuleInit {
this.logger.error(`数据${key}不存在`); this.logger.error(`数据${key}不存在`);
} }
/**
*
* @param key
* @param data
* @param fileName
*/
public async persistData<T>( public async persistData<T>(
key: string, key: string,
data: T, data: T,

View File

@ -56,6 +56,9 @@ export class SystemService {
process.exit(0); process.exit(0);
} }
/**
*
*/
async checkUpdate(): Promise<void> { async checkUpdate(): Promise<void> {
const updated = await this.autoUpdateService.checkForUpdates(); const updated = await this.autoUpdateService.checkForUpdates();
if (updated) { if (updated) {

18
src/types/ws.ts Normal file
View File

@ -0,0 +1,18 @@
import WebSocket from 'ws';
export interface AuthenticatedSocket extends WebSocket {
isAuthed?: boolean;
clientId?: string;
heartbeat?: NodeJS.Timeout;
}
export interface WSMessage {
type: string;
[key: string]: unknown;
}
export interface AuthMessage extends WSMessage {
type: 'auth';
secret: string;
clientId: string;
}