feat: Manage Images using Minio Service

This commit is contained in:
diallolatoile 2026-01-13 04:00:22 +00:00
parent 5e5ecb6cd1
commit bdbbaeaa65

View File

@ -3,14 +3,12 @@ import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom } from 'rxjs';
import { UserInfo, UserServiceClient } from '../interfaces/user.service.interface'; import { UserInfo, UserServiceClient } from '../interfaces/user.service.interface';
import { KeycloakConfig } from 'src/config/keycloak.config';
@Injectable() @Injectable()
export class HttpUserServiceClient implements UserServiceClient { export class HttpUserServiceClient implements UserServiceClient {
private readonly baseUrl: string; private readonly baseUrl: string;
private readonly keycloakUrl: string; private readonly keycloakConfig: KeycloakConfig;
private readonly keycloakRealm: string;
private readonly clientId: string;
private readonly clientSecret: string;
private accessToken: string | null = null; private accessToken: string | null = null;
private tokenExpiry: number = 0; private tokenExpiry: number = 0;
@ -19,21 +17,17 @@ export class HttpUserServiceClient implements UserServiceClient {
private readonly httpService: HttpService, private readonly httpService: HttpService,
private readonly configService: ConfigService, private readonly configService: ConfigService,
) { ) {
this.keycloakConfig = this.getKeycloakConfig();
this.baseUrl = this.configService.get<string>('USER_SERVICE') || 'http://localhost:3001'; this.baseUrl = this.configService.get<string>('USER_SERVICE') || 'http://localhost:3001';
}
const keycloakUrl = this.configService.get<string>('KEYCLOAK_SERVER_URL'); // === CONFIGURATION ===
const keycloakRealm = this.configService.get<string>('KEYCLOAK_REALM'); private getKeycloakConfig(): KeycloakConfig {
const clientId = this.configService.get<string>('KEYCLOAK_CLIENT_ID'); const config = this.configService.get<KeycloakConfig>('keycloak');
const clientSecret = this.configService.get<string>('KEYCLOAK_CLIENT_SECRET'); if (!config) {
throw new Error('Keycloak configuration not found');
if (!keycloakUrl || !keycloakRealm || !clientId || !clientSecret) {
throw new Error('Missing required Keycloak configuration');
} }
return config;
this.keycloakUrl = keycloakUrl;
this.keycloakRealm = keycloakRealm;
this.clientId = clientId;
this.clientSecret = clientSecret;
} }
private async getAccessToken(): Promise<string> { private async getAccessToken(): Promise<string> {
@ -43,12 +37,12 @@ export class HttpUserServiceClient implements UserServiceClient {
} }
try { try {
const tokenUrl = `${this.keycloakUrl}/realms/${this.keycloakRealm}/protocol/openid-connect/token`; const tokenUrl = `${this.keycloakConfig.serverUrl}/realms/${this.keycloakConfig.realm}/protocol/openid-connect/token`;
const params = new URLSearchParams(); const params = new URLSearchParams();
params.append('grant_type', 'client_credentials'); params.append('grant_type', 'client_credentials');
params.append('client_id', this.clientId); params.append('client_id', this.keycloakConfig.authClientId);
params.append('client_secret', this.clientSecret); params.append('client_secret', this.keycloakConfig.authClientSecret);
const response = await firstValueFrom( const response = await firstValueFrom(
this.httpService.post(tokenUrl, params.toString(), { this.httpService.post(tokenUrl, params.toString(), {