1- import { BadRequestException , Injectable } from "@nestjs/common" ;
1+ import { BadRequestException , Injectable , Logger } from "@nestjs/common" ;
22import { ConfigService } from "@nestjs/config" ;
33
44// ---- Third Party Libraries
@@ -18,87 +18,70 @@ export class BlobStorageService {
1818 private containerClient : ContainerClient ;
1919 private aiContainerClient : ContainerClient ;
2020 private downGradeHubClient : ContainerClient ;
21+ private readonly logger = new Logger ( BlobStorageService . name ) ;
2122
2223 /**
2324 * Constructor to initialize BlobStorageService with required dependencies.
2425 * @param configService - Injected ConfigService to access environment variables.
2526 */
2627 constructor ( private configService : ConfigService ) {
27- const AZURE_STORAGE_CONNECTION_STRING = this . configService . get (
28- "azure.connectionString" ,
29- ) ;
30- const feedbackBlobContainer = this . configService . get (
31- "feedbackBlob.container" ,
32- ) ;
33- const aiConversationBLobContainer = this . configService . get (
34- "ai.conversationConatiner" ,
35- ) ;
36-
3728 try {
38- /**
39- * Create an instance of BlobServiceClient using the connection string.
40- */
41-
4229 const azureConnectionString = this . configService . get (
4330 "azure.connectionString" ,
4431 ) ;
32+ const feedbackBlobContainer = this . configService . get (
33+ "feedbackBlob.container" ,
34+ ) ;
35+ const aiConversationBLobContainer = this . configService . get (
36+ "ai.conversationConatiner" ,
37+ ) ;
38+ const downgradeHubBlobContainer = this . configService . get (
39+ "downgradeHub.container" ,
40+ ) ;
4541
4642 if ( ! azureConnectionString ) {
47- console . warn (
48- "Azure Storage is disabled: No connection string provided. " ,
43+ this . logger . warn (
44+ "Azure Storage disabled: Connection string not provided" ,
4945 ) ;
5046 return ;
5147 }
5248
53- const feedbackBlobContainer = this . configService . get (
54- "feedbackBlob.container" ,
55- ) ;
56-
5749 if ( ! feedbackBlobContainer ) {
58- console . warn ( "Feedback Blob is disabled: No container provided. " ) ;
50+ this . logger . warn ( "Feedback Blob disabled: Container not provided" ) ;
5951 return ;
6052 }
6153
62- const aiConversationBLobContainer = this . configService . get (
63- "ai.conversationConatiner" ,
64- ) ;
65-
6654 if ( ! aiConversationBLobContainer ) {
67- console . warn (
68- "AI Conversation Blob is disabled: No container provided. " ,
55+ this . logger . warn (
56+ "AI Conversation Blob disabled: Container not provided" ,
6957 ) ;
7058 return ;
7159 }
7260
73- const downgradeHubBlobContainer = this . configService . get (
74- "downgradeHub.container" ,
75- ) ;
76-
7761 if ( ! downgradeHubBlobContainer ) {
78- console . warn ( "Downgrade Blob is disabled: No container provided. " ) ;
62+ this . logger . warn ( "Downgrade Blob disabled: Container not provided" ) ;
7963 return ;
8064 }
8165
8266 this . blobServiceClient = BlobServiceClient . fromConnectionString (
8367 azureConnectionString ,
8468 ) ;
85- /**
86- * Get a ContainerClient instance for the 'feedbackfiles' container.
87- */
8869 this . containerClient = this . blobServiceClient . getContainerClient (
8970 feedbackBlobContainer ,
9071 ) ;
91- /**
92- * Get a ContainerClient instance for the 'AI Conversation Doc' container.
93- */
9472 this . aiContainerClient = this . blobServiceClient . getContainerClient (
9573 aiConversationBLobContainer ,
9674 ) ;
9775 this . downGradeHubClient = this . blobServiceClient . getContainerClient (
9876 downgradeHubBlobContainer ,
9977 ) ;
100- } catch ( e ) {
101- console . error ( e ) ;
78+
79+ this . logger . log ( "Azure Blob Storage initialized successfully" ) ;
80+ } catch ( error ) {
81+ this . logger . error (
82+ `Azure Blob Storage initialization failed: ${ error . message } ` ,
83+ ) ;
84+ throw error ;
10285 }
10386 }
10487
0 commit comments