refactor: massive codebase stabilization, strict TS, UI/UX overhaul, and central logging
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { IsString, IsArray, ValidateNested, IsOptional, Min, Max, ArrayMinSize, ArrayMaxSize } from 'class-validator';
|
||||
import {
|
||||
IsString,
|
||||
IsArray,
|
||||
ValidateNested,
|
||||
IsOptional,
|
||||
ArrayMinSize,
|
||||
ArrayMaxSize,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class InboundConfigDto {
|
||||
@@ -6,11 +13,11 @@ export class InboundConfigDto {
|
||||
type: string;
|
||||
|
||||
@IsOptional()
|
||||
port?: number | 'random';
|
||||
port?: number | string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
sni?: string | 'random';
|
||||
sni?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@@ -28,4 +35,4 @@ export class CreateSubscriptionDto {
|
||||
@ArrayMaxSize(20)
|
||||
@IsOptional()
|
||||
inboundsConfig?: InboundConfigDto[];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, OneToMany } from 'typeorm';
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
OneToMany,
|
||||
} from 'typeorm';
|
||||
import { Inbound } from '../../inbounds/entities/inbound.entity';
|
||||
|
||||
@Entity()
|
||||
@@ -16,7 +23,12 @@ export class Subscription {
|
||||
isEnabled: boolean;
|
||||
|
||||
@Column({ type: 'simple-json', nullable: true })
|
||||
inboundsConfig: any[];
|
||||
inboundsConfig: Array<{
|
||||
type?: string;
|
||||
port?: number | string;
|
||||
sni?: string;
|
||||
link?: string;
|
||||
}>;
|
||||
|
||||
@OneToMany(() => Inbound, (inbound) => inbound.subscription)
|
||||
inbounds: Inbound[];
|
||||
@@ -26,4 +38,4 @@ export class Subscription {
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { Controller, Get, Post, Delete, Body, Param, Put } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { SubscriptionsService } from './subscriptions.service';
|
||||
import { CreateSubscriptionDto } from './dto/create-subscription.dto';
|
||||
|
||||
@@ -17,7 +25,10 @@ export class SubscriptionsController {
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
update(@Param('id') id: string, @Body() updateSubscriptionDto: CreateSubscriptionDto) {
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Body() updateSubscriptionDto: CreateSubscriptionDto,
|
||||
) {
|
||||
return this.subscriptionsService.update(id, updateSubscriptionDto);
|
||||
}
|
||||
|
||||
@@ -25,4 +36,4 @@ export class SubscriptionsController {
|
||||
remove(@Param('id') id: string) {
|
||||
return this.subscriptionsService.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ import { XuiModule } from '../xui/xui.module';
|
||||
providers: [SubscriptionsService],
|
||||
exports: [SubscriptionsService],
|
||||
})
|
||||
export class SubscriptionsModule {}
|
||||
export class SubscriptionsModule {}
|
||||
|
||||
@@ -15,7 +15,10 @@ export class SubscriptionsService {
|
||||
) {}
|
||||
|
||||
findAll() {
|
||||
return this.subRepo.find({ relations: ['inbounds'], order: { createdAt: 'DESC' } });
|
||||
return this.subRepo.find({
|
||||
relations: ['inbounds'],
|
||||
order: { createdAt: 'DESC' },
|
||||
});
|
||||
}
|
||||
|
||||
async create(dto: CreateSubscriptionDto) {
|
||||
@@ -24,14 +27,14 @@ export class SubscriptionsService {
|
||||
uuid: uuidv4(),
|
||||
inboundsConfig: dto.inboundsConfig || [],
|
||||
});
|
||||
|
||||
|
||||
return this.subRepo.save(sub);
|
||||
}
|
||||
|
||||
async update(id: string, dto: CreateSubscriptionDto) {
|
||||
const sub = await this.subRepo.findOne({
|
||||
where: { id },
|
||||
relations: ['inbounds']
|
||||
const sub = await this.subRepo.findOne({
|
||||
where: { id },
|
||||
relations: ['inbounds'],
|
||||
});
|
||||
|
||||
if (!sub) {
|
||||
@@ -39,7 +42,7 @@ export class SubscriptionsService {
|
||||
}
|
||||
|
||||
sub.name = dto.name;
|
||||
|
||||
|
||||
if (dto.inboundsConfig) {
|
||||
sub.inboundsConfig = dto.inboundsConfig;
|
||||
}
|
||||
@@ -48,7 +51,10 @@ export class SubscriptionsService {
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
const sub = await this.subRepo.findOne({ where: { id }, relations: ['inbounds'] });
|
||||
const sub = await this.subRepo.findOne({
|
||||
where: { id },
|
||||
relations: ['inbounds'],
|
||||
});
|
||||
if (!sub) return;
|
||||
|
||||
if (sub.inbounds && sub.inbounds.length > 0) {
|
||||
@@ -59,4 +65,4 @@ export class SubscriptionsService {
|
||||
|
||||
return this.subRepo.remove(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user