@@ -19,16 +19,30 @@ public async Task<IEnumerable<MessageFileModel>> GetMessageFileScreenshotsAsync(
1919
2020        foreach  ( var  messageId  in  messageIds ) 
2121        { 
22+             if  ( string . IsNullOrWhiteSpace ( messageId ) ) 
23+             { 
24+                 continue ; 
25+             } 
26+ 
2227            var  dir  =  Path . Combine ( pathPrefix ,  messageId ,  FileSourceType . User ) ; 
23-             if  ( ! ExistDirectory ( dir ) )  continue ; 
28+             if  ( ! ExistDirectory ( dir ) ) 
29+             { 
30+                 continue ; 
31+             } 
2432
2533            foreach  ( var  subDir  in  Directory . GetDirectories ( dir ) ) 
2634            { 
2735                var  file  =  Directory . GetFiles ( subDir ) . FirstOrDefault ( ) ; 
28-                 if  ( file  ==  null )  continue ; 
36+                 if  ( file  ==  null ) 
37+                 { 
38+                     continue ; 
39+                 } 
2940
3041                var  screenshots  =  await  GetScreenshots ( file ,  subDir ,  messageId ,  source ) ; 
31-                 if  ( screenshots . IsNullOrEmpty ( ) )  continue ; 
42+                 if  ( screenshots . IsNullOrEmpty ( ) ) 
43+                 { 
44+                     continue ; 
45+                 } 
3246
3347                files . AddRange ( screenshots ) ; 
3448            } 
@@ -41,10 +55,18 @@ public IEnumerable<MessageFileModel> GetMessageFiles(string conversationId, IEnu
4155        string  source ,  IEnumerable < string > ?  contentTypes  =  null ) 
4256    { 
4357        var  files  =  new  List < MessageFileModel > ( ) ; 
44-         if  ( string . IsNullOrWhiteSpace ( conversationId )  ||  messageIds . IsNullOrEmpty ( ) )  return  files ; 
58+         if  ( string . IsNullOrWhiteSpace ( conversationId )  ||  messageIds . IsNullOrEmpty ( ) ) 
59+         { 
60+             return  files ; 
61+         } 
4562
4663        foreach  ( var  messageId  in  messageIds ) 
4764        { 
65+             if  ( string . IsNullOrWhiteSpace ( messageId ) ) 
66+             { 
67+                 continue ; 
68+             } 
69+ 
4870            var  dir  =  Path . Combine ( _baseDir ,  CONVERSATION_FOLDER ,  conversationId ,  FILE_FOLDER ,  messageId ,  source ) ; 
4971            if  ( ! ExistDirectory ( dir ) ) 
5072            { 
@@ -85,6 +107,14 @@ public IEnumerable<MessageFileModel> GetMessageFiles(string conversationId, IEnu
85107
86108    public  string  GetMessageFile ( string  conversationId ,  string  messageId ,  string  source ,  string  index ,  string  fileName ) 
87109    { 
110+         if  ( string . IsNullOrWhiteSpace ( conversationId ) 
111+             ||  string . IsNullOrWhiteSpace ( messageId ) 
112+             ||  string . IsNullOrWhiteSpace ( source ) 
113+             ||  string . IsNullOrWhiteSpace ( index ) ) 
114+         { 
115+             return  string . Empty ; 
116+         } 
117+ 
88118        var  dir  =  Path . Combine ( _baseDir ,  CONVERSATION_FOLDER ,  conversationId ,  FILE_FOLDER ,  messageId ,  source ,  index ) ; 
89119        if  ( ! ExistDirectory ( dir ) ) 
90120        { 
@@ -98,10 +128,18 @@ public string GetMessageFile(string conversationId, string messageId, string sou
98128    public  IEnumerable < MessageFileModel >  GetMessagesWithFile ( string  conversationId ,  IEnumerable < string >  messageIds ) 
99129    { 
100130        var  foundMsgs  =  new  List < MessageFileModel > ( ) ; 
101-         if  ( string . IsNullOrWhiteSpace ( conversationId )  ||  messageIds . IsNullOrEmpty ( ) )  return  foundMsgs ; 
131+         if  ( string . IsNullOrWhiteSpace ( conversationId )  ||  messageIds . IsNullOrEmpty ( ) ) 
132+         { 
133+             return  foundMsgs ; 
134+         } 
102135
103136        foreach  ( var  messageId  in  messageIds ) 
104137        { 
138+             if  ( string . IsNullOrWhiteSpace ( messageId ) ) 
139+             { 
140+                 continue ; 
141+             } 
142+ 
105143            var  prefix  =  Path . Combine ( _baseDir ,  CONVERSATION_FOLDER ,  conversationId ,  FILE_FOLDER ,  messageId ) ; 
106144            var  userDir  =  Path . Combine ( prefix ,  FileSourceType . User ) ; 
107145            if  ( ExistDirectory ( userDir ) ) 
@@ -121,10 +159,19 @@ public IEnumerable<MessageFileModel> GetMessagesWithFile(string conversationId,
121159
122160    public  bool  SaveMessageFiles ( string  conversationId ,  string  messageId ,  string  source ,  List < FileDataModel >  files ) 
123161    { 
124-         if  ( files . IsNullOrEmpty ( ) )  return  false ; 
162+         if  ( string . IsNullOrWhiteSpace ( conversationId ) 
163+             ||  string . IsNullOrWhiteSpace ( messageId ) 
164+             ||  string . IsNullOrWhiteSpace ( source ) 
165+             ||  files . IsNullOrEmpty ( ) ) 
166+         { 
167+             return  false ; 
168+         } 
125169
126170        var  dir  =  GetConversationFileDirectory ( conversationId ,  messageId ,  createNewDir :  true ) ; 
127-         if  ( ! ExistDirectory ( dir ) )  return  false ; 
171+         if  ( ! ExistDirectory ( dir ) ) 
172+         { 
173+             return  false ; 
174+         } 
128175
129176        for  ( int  i  =  0 ;  i  <  files . Count ;  i ++ ) 
130177        { 
@@ -164,7 +211,10 @@ public bool SaveMessageFiles(string conversationId, string messageId, string sou
164211
165212    public  bool  DeleteMessageFiles ( string  conversationId ,  IEnumerable < string >  messageIds ,  string  targetMessageId ,  string ?  newMessageId  =  null ) 
166213    { 
167-         if  ( string . IsNullOrEmpty ( conversationId )  ||  messageIds  ==  null )  return  false ; 
214+         if  ( string . IsNullOrEmpty ( conversationId )  ||  messageIds  ==  null ) 
215+         { 
216+             return  false ; 
217+         } 
168218
169219        if  ( ! string . IsNullOrEmpty ( targetMessageId )  &&  ! string . IsNullOrEmpty ( newMessageId ) ) 
170220        { 
@@ -192,7 +242,10 @@ public bool DeleteMessageFiles(string conversationId, IEnumerable<string> messag
192242        foreach  ( var  messageId  in  messageIds ) 
193243        { 
194244            var  dir  =  GetConversationFileDirectory ( conversationId ,  messageId ) ; 
195-             if  ( ! ExistDirectory ( dir ) )  continue ; 
245+             if  ( ! ExistDirectory ( dir ) ) 
246+             { 
247+                 continue ; 
248+             } 
196249
197250            DeleteDirectory ( dir ) ; 
198251            Thread . Sleep ( 100 ) ; 
@@ -203,12 +256,18 @@ public bool DeleteMessageFiles(string conversationId, IEnumerable<string> messag
203256
204257    public  bool  DeleteConversationFiles ( IEnumerable < string >  conversationIds ) 
205258    { 
206-         if  ( conversationIds . IsNullOrEmpty ( ) )  return  false ; 
259+         if  ( conversationIds . IsNullOrEmpty ( ) ) 
260+         { 
261+             return  false ; 
262+         } 
207263
208264        foreach  ( var  conversationId  in  conversationIds ) 
209265        { 
210266            var  convDir  =  GetConversationDirectory ( conversationId ) ; 
211-             if  ( ! ExistDirectory ( convDir ) )  continue ; 
267+             if  ( ! ExistDirectory ( convDir ) ) 
268+             { 
269+                 continue ; 
270+             } 
212271
213272            DeleteDirectory ( convDir ) ; 
214273        } 
@@ -241,7 +300,10 @@ private string GetConversationFileDirectory(string? conversationId, string? mess
241300
242301    private  IEnumerable < string >  GetMessageIds ( IEnumerable < RoleDialogModel >  dialogs ,  int ?  offset  =  null ) 
243302    { 
244-         if  ( dialogs . IsNullOrEmpty ( ) )  return  Enumerable . Empty < string > ( ) ; 
303+         if  ( dialogs . IsNullOrEmpty ( ) ) 
304+         { 
305+             return  Enumerable . Empty < string > ( ) ; 
306+         } 
245307
246308        if  ( offset . HasValue  &&  offset  <  1 ) 
247309        { 
@@ -264,13 +326,17 @@ private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> dialogs,
264326    private  async  Task < IEnumerable < string > >  ConvertPdfToImages ( string  pdfLoc ,  string  imageLoc ) 
265327    { 
266328        var  converters  =  _services . GetServices < IPdf2ImageConverter > ( ) ; 
267-         if  ( converters . IsNullOrEmpty ( ) )  return  Enumerable . Empty < string > ( ) ; 
329+         if  ( converters . IsNullOrEmpty ( ) ) 
330+         { 
331+             return  Enumerable . Empty < string > ( ) ; 
332+         } 
268333
269334        var  converter  =  GetPdf2ImageConverter ( ) ; 
270335        if  ( converter  ==  null ) 
271336        { 
272337            return  Enumerable . Empty < string > ( ) ; 
273338        } 
339+ 
274340        return  await  converter . ConvertPdfToImages ( pdfLoc ,  imageLoc ) ; 
275341    } 
276342
0 commit comments