mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
feat: proxy services
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
FROM node:lts-alpine
|
||||
FROM oven/bun:latest
|
||||
WORKDIR /app
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
COPY package.json pnpm-*.yaml ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
COPY package.json bun.lockb ./
|
||||
RUN bun install --frozen-lockfile
|
||||
COPY . .
|
||||
RUN pnpm build
|
||||
RUN bun run build
|
||||
EXPOSE 3000
|
||||
CMD [ "pnpm", "start:prod" ]
|
||||
CMD [ "bun", "run", "start:prod" ]
|
||||
|
||||
17
backend/libs/database/proxy_info.ts
Normal file
17
backend/libs/database/proxy_info.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
@Entity()
|
||||
export class ProxyInfo {
|
||||
constructor(props?: Partial<ProxyInfo>) {
|
||||
Object.assign(this, props);
|
||||
}
|
||||
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
public uuid!: string;
|
||||
|
||||
@Column()
|
||||
public enabled: boolean;
|
||||
|
||||
@Column()
|
||||
public text: string;
|
||||
}
|
||||
@@ -36,4 +36,7 @@ export class ProxyUser {
|
||||
|
||||
@OneToMany(() => Payment, (payment) => payment.user)
|
||||
public payments: Payment[];
|
||||
|
||||
@Column()
|
||||
public tg_id!: string;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,24 @@ import { Admin } from "./database/admin.entity";
|
||||
import { Image } from "./database/image.entity";
|
||||
import { Payment } from "./database/payment.entity";
|
||||
import { Post } from "./database/post.entity";
|
||||
import { ProxyInfo } from "./database/proxy_info";
|
||||
import { ProxyUser } from "./database/proxy_user.entity";
|
||||
import { BotSettings } from "./database/settings.entity";
|
||||
import { User } from "./database/user.entity";
|
||||
import { WebUser } from "./database/web_user.entity";
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User, Admin, Post, Image, Payment, ProxyUser, BotSettings, WebUser]),
|
||||
TypeOrmModule.forFeature([
|
||||
User,
|
||||
Admin,
|
||||
Post,
|
||||
Image,
|
||||
Payment,
|
||||
ProxyUser,
|
||||
BotSettings,
|
||||
WebUser,
|
||||
ProxyInfo,
|
||||
]),
|
||||
],
|
||||
exports: [TypeOrmModule],
|
||||
})
|
||||
|
||||
8164
backend/pnpm-lock.yaml
generated
8164
backend/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
import { Body, Controller, Get, Param, Post } from "@nestjs/common";
|
||||
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
||||
import { IOperation, IProxyUser } from "./proxy.dto";
|
||||
import { IOperation, IProxyInfoEnabled, IProxyInfoText, IProxyUser } from "./proxy.dto";
|
||||
import { ProxyService } from "./proxy.service";
|
||||
|
||||
@ApiTags("Proxy")
|
||||
@@ -43,4 +43,22 @@ export class ProxyController {
|
||||
async getAllOperations() {
|
||||
return this.proxyService.getAllOperations();
|
||||
}
|
||||
|
||||
@ApiOperation({ description: "get current info" })
|
||||
@Get("info")
|
||||
async getProxyInfo() {
|
||||
return this.proxyService.getProxyInfo();
|
||||
}
|
||||
|
||||
@ApiOperation({ description: "set proxy info text" })
|
||||
@Post("set-info-text")
|
||||
async setProxyInfoText(@Body() data: IProxyInfoText) {
|
||||
return this.proxyService.setProxyInfoText(data.text);
|
||||
}
|
||||
|
||||
@ApiOperation({ description: "set proxy info status" })
|
||||
@Post("set-info-status")
|
||||
async setProxyInfoStatus(@Body() data: IProxyInfoEnabled) {
|
||||
return this.proxyService.setProxyInfoStatus(data.enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,21 @@ export class IProxyUser {
|
||||
readonly link!: string;
|
||||
@ApiProperty({ description: "telegram user id to connect to user entity", example: "187564" })
|
||||
readonly user_id?: string;
|
||||
@ApiProperty({ description: "telegram user id", example: "111111" })
|
||||
readonly tg_id: string;
|
||||
}
|
||||
|
||||
export class IOperation {
|
||||
@ApiProperty({ description: "user name of user, that made new operation", example: "username" })
|
||||
readonly userName!: string;
|
||||
}
|
||||
|
||||
export class IProxyInfoText {
|
||||
@ApiProperty({ description: "proxy info text", example: "Working normal" })
|
||||
readonly text!: string;
|
||||
}
|
||||
|
||||
export class IProxyInfoEnabled {
|
||||
@ApiProperty({ description: "proxy info enabled", example: true })
|
||||
readonly enabled!: boolean;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { HttpException, HttpStatus, Injectable, Logger } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Payment } from "libs/database/payment.entity";
|
||||
import { ProxyInfo } from "libs/database/proxy_info";
|
||||
import { ProxyUser } from "libs/database/proxy_user.entity";
|
||||
import { User } from "libs/database/user.entity";
|
||||
import { Repository } from "typeorm";
|
||||
@@ -13,6 +14,7 @@ export class ProxyService {
|
||||
@InjectRepository(ProxyUser) private proxyUserRepository: Repository<ProxyUser>,
|
||||
@InjectRepository(Payment) private paymentRepository: Repository<Payment>,
|
||||
@InjectRepository(User) private userRepository: Repository<User>,
|
||||
@InjectRepository(ProxyInfo) private proxyInfoRepository: Repository<ProxyInfo>,
|
||||
) {}
|
||||
|
||||
async newUser(data: IProxyUser) {
|
||||
@@ -33,6 +35,7 @@ export class ProxyService {
|
||||
proxyUser.connectDate = new Date();
|
||||
proxyUser.userName = data.userName;
|
||||
proxyUser.link = data.link;
|
||||
proxyUser.tg_id = data.tg_id;
|
||||
return await this.proxyUserRepository.save(proxyUser);
|
||||
} catch (error) {
|
||||
if (error instanceof HttpException) {
|
||||
@@ -109,4 +112,38 @@ export class ProxyService {
|
||||
throw new HttpException("Bad data", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
async getProxyInfo() {
|
||||
try {
|
||||
return (await this.proxyInfoRepository.find({ select: { enabled: true, text: true } }))[0];
|
||||
} catch (error) {
|
||||
this.logger.debug(`[proxy.getProxyInfo] error: ${error}`);
|
||||
throw new HttpException("Bad data", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
async setProxyInfoText(text: string) {
|
||||
this.logger.log(`[proxy.setProxyInfoText] Data: ${text}`);
|
||||
try {
|
||||
const info = (await this.proxyInfoRepository.find())[0];
|
||||
info.text = text;
|
||||
|
||||
return await this.proxyInfoRepository.save(info);
|
||||
} catch (error) {
|
||||
this.logger.debug(`[proxy.setProxyInfoText] error: ${error}`);
|
||||
throw new HttpException("Bad data", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
async setProxyInfoStatus(status: boolean) {
|
||||
this.logger.log(`[proxy.setProxyInfoStatus] Data: ${status}`);
|
||||
try {
|
||||
const info = (await this.proxyInfoRepository.find())[0];
|
||||
info.enabled = status;
|
||||
return this.proxyInfoRepository.save(info);
|
||||
} catch (error) {
|
||||
this.logger.debug(`[proxy.setProxyInfoStatus] error: ${error}`);
|
||||
throw new HttpException("Bad data", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user