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