This commit is contained in:
Den Piligrim
2026-03-21 13:24:47 +03:00
parent 21ae964012
commit 5b2870e04a
17 changed files with 386 additions and 152 deletions
@@ -11,6 +11,10 @@ export class InboundConfigDto {
@IsString()
@IsOptional()
sni?: string | 'random';
@IsString()
@IsOptional()
link?: string;
}
export class CreateSubscriptionDto {
@@ -15,6 +15,9 @@ export class Subscription {
@Column({ default: true })
isEnabled: boolean;
@Column({ type: 'simple-json', nullable: true })
inboundsConfig: any[];
@OneToMany(() => Inbound, (inbound) => inbound.subscription)
inbounds: Inbound[];
@@ -1,5 +1,6 @@
import { Controller, Get, Post, Delete, Body, Param } 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';
@Controller('subscriptions')
export class SubscriptionsController {
@@ -11,8 +12,13 @@ export class SubscriptionsController {
}
@Post()
create(@Body('name') name: string) {
return this.subscriptionsService.create(name);
create(@Body() createSubscriptionDto: CreateSubscriptionDto) {
return this.subscriptionsService.create(createSubscriptionDto);
}
@Put(':id')
update(@Param('id') id: string, @Body() updateSubscriptionDto: CreateSubscriptionDto) {
return this.subscriptionsService.update(id, updateSubscriptionDto);
}
@Delete(':id')
@@ -1,9 +1,9 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Subscription } from './entities/subscription.entity';
import { Inbound } from '../inbounds/entities/inbound.entity';
import { XuiService } from '../xui/xui.service';
import { CreateSubscriptionDto } from './dto/create-subscription.dto';
import { v4 as uuidv4 } from 'uuid';
@Injectable()
@@ -18,11 +18,32 @@ export class SubscriptionsService {
return this.subRepo.find({ relations: ['inbounds'], order: { createdAt: 'DESC' } });
}
async create(name: string) {
async create(dto: CreateSubscriptionDto) {
const sub = this.subRepo.create({
name,
name: dto.name,
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']
});
if (!sub) {
throw new NotFoundException(`Subscription with ID ${id} not found`);
}
sub.name = dto.name;
if (dto.inboundsConfig) {
sub.inboundsConfig = dto.inboundsConfig;
}
return this.subRepo.save(sub);
}
@@ -30,7 +51,7 @@ export class SubscriptionsService {
const sub = await this.subRepo.findOne({ where: { id }, relations: ['inbounds'] });
if (!sub) return;
if (sub.inbounds) {
if (sub.inbounds && sub.inbounds.length > 0) {
for (const inbound of sub.inbounds) {
await this.xuiService.deleteInbound(inbound.xuiId);
}