[backend]: add minio, rename methods
This commit is contained in:
parent
586f2ce77f
commit
0fc00be0cb
@ -25,10 +25,26 @@ services:
|
||||
networks:
|
||||
- teastream-backend
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
container_name: teastream-minio
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
|
||||
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
|
||||
command: server /data --console-address ":9001"
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
networks:
|
||||
- teastream-backend
|
||||
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
minio_data:
|
||||
|
||||
networks:
|
||||
teastream-backend:
|
||||
|
||||
@ -142,7 +142,7 @@ type MakePaymentModel {
|
||||
type Mutation {
|
||||
changeChatSettings(data: ChangeChatSettingsInput!): StreamModel!
|
||||
changeEmail(data: ChangeEmailInput!): UserModel!
|
||||
changeNotificationSettigs(data: ChangeNotificationSettingsInput!): ChangeNotificationsSettingsResponse!
|
||||
changeNotificationSettings(data: ChangeNotificationSettingsInput!): ChangeNotificationsSettingsResponse!
|
||||
changePassword(data: ChangePasswordInput!): UserModel!
|
||||
changeProfileAvatar(avatar: Upload!): Boolean!
|
||||
changeProfileInfo(data: ChangeProfileInfoInput!): UserModel!
|
||||
@ -370,7 +370,7 @@ type UserModel {
|
||||
isVerified: Boolean!
|
||||
name: String!
|
||||
notification: [NotificationModel!]!
|
||||
notificationSettings: NotificationSettingsModel!
|
||||
notificationSettings: NotificationSettingsModel
|
||||
password: String!
|
||||
socialLink: [SocialLinkModel!]!
|
||||
stream: StreamModel!
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { BadRequestException, Logger } from '@nestjs/common';
|
||||
import { hash } from 'argon2';
|
||||
|
||||
import { Prisma, PrismaClient } from '@/prisma/generated';
|
||||
// eslint-disable-next-line
|
||||
import { Prisma, PrismaClient } from '../../../prisma/generated';
|
||||
|
||||
import { CATEGORIES } from './data/categories.data';
|
||||
import { STREAMS } from './data/streams.data';
|
||||
|
||||
@ -21,6 +21,11 @@ export class AccountService {
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
socialLink: true,
|
||||
stream: true,
|
||||
notificationSettings: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ export class UserModel implements User {
|
||||
@Field(() => [NotificationModel])
|
||||
notification: NotificationModel[];
|
||||
|
||||
@Field(() => NotificationSettingsModel)
|
||||
@Field(() => NotificationSettingsModel, { nullable: true })
|
||||
notificationSettings: NotificationSettingsModel;
|
||||
|
||||
@Field(() => Date)
|
||||
|
||||
@ -3,6 +3,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { verify } from 'argon2';
|
||||
|
||||
import { PrismaService } from '@/src/core/prisma/prisma.service';
|
||||
import { RedisService } from '@/src/core/redis/redis.service';
|
||||
import { DeactivateAccountInput } from '@/src/module/auth/deactivate/inputs/deactivate-account.input';
|
||||
import { MailService } from '@/src/module/libs/mail/mail.service';
|
||||
import { TelegramService } from '@/src/module/libs/telegram/telegram.service';
|
||||
@ -19,6 +20,7 @@ import type { Request } from 'express';
|
||||
export class DeactivateService {
|
||||
constructor(
|
||||
private readonly prismaService: PrismaService,
|
||||
private readonly redisService: RedisService,
|
||||
private readonly configService: ConfigService<ProcessEnv>,
|
||||
private readonly mailService: MailService,
|
||||
private readonly telegramService: TelegramService,
|
||||
@ -82,7 +84,7 @@ export class DeactivateService {
|
||||
throw new BadRequestException('Токен истек');
|
||||
}
|
||||
|
||||
await this.prismaService.user.update({
|
||||
const user = await this.prismaService.user.update({
|
||||
where: { id: existingToken.userId },
|
||||
data: {
|
||||
isDeactivated: true,
|
||||
@ -96,7 +98,24 @@ export class DeactivateService {
|
||||
type: TokenType.DEACTIVATE_ACCOUNT,
|
||||
},
|
||||
});
|
||||
await this.clearSessions(user.id);
|
||||
|
||||
return destroySession(req, this.configService);
|
||||
}
|
||||
|
||||
private async clearSessions(userId: string) {
|
||||
const keys = await this.redisService.keys('*');
|
||||
|
||||
for (const key of keys) {
|
||||
const sessionData = await this.redisService.get(key);
|
||||
|
||||
if (sessionData) {
|
||||
const session = JSON.parse(sessionData);
|
||||
|
||||
if (session.userId === userId) {
|
||||
await this.redisService.del(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { ConflictException, Injectable } from '@nestjs/common';
|
||||
import * as Upload from 'graphql-upload/Upload.js';
|
||||
import sharp from 'sharp';
|
||||
import * as sharp from 'sharp';
|
||||
|
||||
import { SocialLink, User } from '@/prisma/generated';
|
||||
import { PrismaService } from '@/src/core/prisma/prisma.service';
|
||||
|
||||
@ -89,7 +89,7 @@ export class SessionService {
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
if (!user || user.isDeactivated) {
|
||||
throw new NotFoundException('Пользователь не найден');
|
||||
}
|
||||
|
||||
|
||||
@ -20,15 +20,16 @@ export class StorageService {
|
||||
private readonly configService: ConfigService<ProcessEnv>,
|
||||
) {
|
||||
this.client = new S3Client({
|
||||
endpoint: this.configService.getOrThrow('S3_ENDPOINT'),
|
||||
region: this.configService.getOrThrow('S3_REGION'),
|
||||
endpoint: this.configService.getOrThrow('MINIO_ENDPOINT'),
|
||||
region: this.configService.getOrThrow('MINIO_REGION'),
|
||||
credentials: {
|
||||
accessKeyId: this.configService.getOrThrow('S3_ACCESS_KEY_ID'),
|
||||
secretAccessKey: this.configService.getOrThrow('S3_SECRET_KEY_ID'),
|
||||
accessKeyId: this.configService.getOrThrow('MINIO_ACCESS_KEY'),
|
||||
secretAccessKey: this.configService.getOrThrow('MINIO_SECRET_KEY'),
|
||||
},
|
||||
forcePathStyle: true,
|
||||
});
|
||||
|
||||
this.bucket = this.configService.getOrThrow('S3_BUCKET_NAME');
|
||||
this.bucket = this.configService.getOrThrow('MINIO_BUCKET_NAME');
|
||||
}
|
||||
|
||||
public async upload(buffer: Buffer, key: string, mimetype: string) {
|
||||
|
||||
@ -2,12 +2,12 @@ import {
|
||||
Args, Mutation, Query, Resolver,
|
||||
} from '@nestjs/graphql';
|
||||
|
||||
import { ChangeNotificationSettingsInput } from '@/src/module/notification/inputs/change-notification-settings.input';
|
||||
import { ChangeNotificationsSettingsResponse } from '@/src/module/notification/models/notification-settings.model';
|
||||
import { Authorization } from '@/src/shared/decorators/auth.decorator';
|
||||
import { Authorized } from '@/src/shared/decorators/authorized.decorator';
|
||||
import { User } from '@prisma/generated';
|
||||
|
||||
import { ChangeNotificationSettingsInput } from './inputs/change-notification-settings.input';
|
||||
import { ChangeNotificationsSettingsResponse } from './models/notification-settings.model';
|
||||
import { NotificationModel } from './models/notification.model';
|
||||
import { NotificationService } from './notification.service';
|
||||
|
||||
@ -28,7 +28,7 @@ export class NotificationResolver {
|
||||
}
|
||||
|
||||
@Authorization()
|
||||
@Mutation(() => ChangeNotificationsSettingsResponse, { name: 'changeNotificationSettigs' })
|
||||
@Mutation(() => ChangeNotificationsSettingsResponse, { name: 'changeNotificationSettings' })
|
||||
public async changeSettings(
|
||||
@Authorized() user: User,
|
||||
@Args('data') input: ChangeNotificationSettingsInput,
|
||||
|
||||
@ -42,7 +42,7 @@ export class NotificationService {
|
||||
public async changeSettings(user: User, input: ChangeNotificationSettingsInput) {
|
||||
const { siteNotifications, telegramNotifications } = input;
|
||||
|
||||
const notificationSetting = await this.prismaService.notificationSettings.upsert({
|
||||
const notificationSettings = await this.prismaService.notificationSettings.upsert({
|
||||
where: { userId: user.id },
|
||||
create: {
|
||||
siteNotifications,
|
||||
@ -53,7 +53,7 @@ export class NotificationService {
|
||||
include: { user: true },
|
||||
});
|
||||
|
||||
if (notificationSetting.telegramNotifications && !notificationSetting.user.telegramId) {
|
||||
if (notificationSettings.telegramNotifications && !notificationSettings.user.telegramId) {
|
||||
const telegramAuthToken = await generateToken(
|
||||
this.prismaService,
|
||||
user,
|
||||
@ -61,21 +61,21 @@ export class NotificationService {
|
||||
);
|
||||
|
||||
return {
|
||||
notificationSetting,
|
||||
notificationSettings,
|
||||
telegramAuthToken: telegramAuthToken.token,
|
||||
};
|
||||
}
|
||||
|
||||
if (!notificationSetting.telegramNotifications && notificationSetting.user.telegramId) {
|
||||
if (!notificationSettings.telegramNotifications && notificationSettings.user.telegramId) {
|
||||
await this.prismaService.user.update({
|
||||
where: { id: user.id },
|
||||
data: { telegramId: null },
|
||||
});
|
||||
|
||||
return { notificationSetting };
|
||||
return { notificationSettings };
|
||||
}
|
||||
|
||||
return { notificationSetting };
|
||||
return { notificationSettings };
|
||||
}
|
||||
|
||||
public async createStreamStart(userId: string, channel: User) {
|
||||
|
||||
8
backend/src/shared/types/env.d.ts
vendored
8
backend/src/shared/types/env.d.ts
vendored
@ -42,6 +42,14 @@ export type ProcessEnv = {
|
||||
S3_SECRET_KEY_ID: string;
|
||||
S3_BUCKET_NAME: string;
|
||||
|
||||
MINIO_ROOT_USER: string;
|
||||
MINIO_ROOT_PASSWORD: string;
|
||||
MINIO_ENDPOINT: string;
|
||||
MINIO_ACCESS_KEY: string;
|
||||
MINIO_SECRET_KEY: string;
|
||||
MINIO_BUCKET_NAME: string;
|
||||
MINIO_REGION: string;
|
||||
|
||||
LIVEKIT_URL: string;
|
||||
LIVEKIT_API_KEY: string;
|
||||
LIVEKIT_API_SECRET: string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user