09101136
This commit is contained in:
parent
35d781c3a6
commit
3f306f07a1
|
@ -39,12 +39,12 @@
|
||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"ioredis": "^5.4.1",
|
"ioredis": "^5.4.1",
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
|
"minio": "^8.0.1",
|
||||||
"reflect-metadata": "^0.2.0",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"socket.io": "^4.7.5",
|
"socket.io": "^4.7.5",
|
||||||
"superjson-cjs": "^2.2.3",
|
"superjson-cjs": "^2.2.3",
|
||||||
"tus-js-client": "^4.1.0",
|
"tus-js-client": "^4.1.0"
|
||||||
"zod": "^3.23.8"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^10.0.0",
|
"@nestjs/cli": "^10.0.0",
|
||||||
|
|
|
@ -12,12 +12,13 @@ import { ConfigService } from '@nestjs/config';
|
||||||
import { TasksModule } from './tasks/tasks.module';
|
import { TasksModule } from './tasks/tasks.module';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
import { env } from './env';
|
import { env } from './env';
|
||||||
|
import { MinioModule } from './minio/minio.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ScheduleModule.forRoot(), JwtModule.register({
|
imports: [ScheduleModule.forRoot(), JwtModule.register({
|
||||||
global: true,
|
global: true,
|
||||||
secret: env.JWT_SECRET
|
secret: env.JWT_SECRET
|
||||||
}), TrpcModule, RedisModule, QueueModule, TransformModule, AuthModule, TasksModule],
|
}), TrpcModule, RedisModule, QueueModule, TransformModule, AuthModule, TasksModule, MinioModule],
|
||||||
providers: [RedisService, SocketGateway, ConfigService],
|
providers: [RedisService, SocketGateway, ConfigService],
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import { Controller, Post, Body, UseGuards, Get, Req } from '@nestjs/common';
|
import { Controller, Post, Body, UseGuards, Get, Req } from '@nestjs/common';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { AuthSchema, JwtPayload } from '@nicestack/common';
|
import { AuthSchema, JwtPayload } from '@nicestack/common';
|
||||||
|
import { z } from '@nicestack/common';
|
||||||
import { z } from 'zod';
|
|
||||||
import { AuthGuard } from './auth.guard';
|
import { AuthGuard } from './auth.guard';
|
||||||
|
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly authService: AuthService) { }
|
constructor(private readonly authService: AuthService) { }
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { InitService } from './init.service';
|
import { InitService } from './init.service';
|
||||||
import { AuthModule } from '@server/auth/auth.module';
|
import { AuthModule } from '@server/auth/auth.module';
|
||||||
|
import { MinioModule } from '@server/minio/minio.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [AuthModule],
|
imports: [AuthModule, MinioModule],
|
||||||
providers: [InitService],
|
providers: [InitService],
|
||||||
exports: [InitService]
|
exports: [InitService]
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { db, InitRoles, InitTaxonomies, ObjectType } from "@nicestack/common";
|
import { db, InitRoles, InitTaxonomies, ObjectType } from "@nicestack/common";
|
||||||
import { AuthService } from '@server/auth/auth.service';
|
import { AuthService } from '@server/auth/auth.service';
|
||||||
|
import { MinioService } from '@server/minio/minio.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InitService {
|
export class InitService {
|
||||||
private readonly logger = new Logger(InitService.name);
|
private readonly logger = new Logger(InitService.name);
|
||||||
constructor(private readonly authService: AuthService) { }
|
constructor(private readonly authService: AuthService, private readonly minioService: MinioService) { }
|
||||||
private async createRoles() {
|
private async createRoles() {
|
||||||
this.logger.log('Checking existing system roles');
|
this.logger.log('Checking existing system roles');
|
||||||
for (const role of InitRoles) {
|
for (const role of InitRoles) {
|
||||||
|
@ -41,7 +42,9 @@ export class InitService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async createBucket() {
|
||||||
|
await this.minioService.createBucket('app')
|
||||||
|
}
|
||||||
private async createRoot() {
|
private async createRoot() {
|
||||||
this.logger.log('Checking for root account');
|
this.logger.log('Checking for root account');
|
||||||
const rootAccountExists = await db.staff.findFirst({
|
const rootAccountExists = await db.staff.findFirst({
|
||||||
|
@ -91,5 +94,8 @@ export class InitService {
|
||||||
|
|
||||||
this.logger.log('Initializing taxonomies');
|
this.logger.log('Initializing taxonomies');
|
||||||
await this.createTaxonomy();
|
await this.createTaxonomy();
|
||||||
|
|
||||||
|
this.logger.log('Initialize minio')
|
||||||
|
await this.createBucket()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { MinioService } from './minio.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [MinioService],
|
||||||
|
exports: [MinioService]
|
||||||
|
})
|
||||||
|
export class MinioModule {}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { MinioService } from './minio.service';
|
||||||
|
|
||||||
|
describe('MinioService', () => {
|
||||||
|
let service: MinioService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [MinioService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<MinioService>(MinioService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import * as Minio from 'minio';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class MinioService {
|
||||||
|
private readonly logger = new Logger(MinioService.name)
|
||||||
|
private readonly minioClient: Minio.Client;
|
||||||
|
constructor() {
|
||||||
|
this.minioClient = new Minio.Client({
|
||||||
|
endPoint: 'localhost',
|
||||||
|
port: 9000,
|
||||||
|
useSSL: false,
|
||||||
|
accessKey: process.env.MINIO_ACCESS_KEY || 'minioadmin',
|
||||||
|
secretKey: process.env.MINIO_SECRET_KEY || 'minioadmin'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async createBucket(bucketName: string): Promise<void> {
|
||||||
|
const exists = await this.minioClient.bucketExists(bucketName);
|
||||||
|
if (!exists) {
|
||||||
|
await this.minioClient.makeBucket(bucketName, '');
|
||||||
|
this.logger.log(`Bucket ${bucketName} created successfully.`);
|
||||||
|
} else {
|
||||||
|
this.logger.log(`Bucket ${bucketName} already exists.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue