File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed 
backend/FwLite/LcmCrdt/MediaServer Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ public interface IMediaServerClient
88    [ Get ( "/api/media/{fileId}" ) ] 
99    Task < HttpResponseMessage >  DownloadFile ( Guid  fileId ) ; 
1010
11+     [ Get ( "/api/media/metadata/{fileId}" ) ] 
12+     Task < HttpResponseMessage >  GetFileMetadata ( Guid  fileId ) ; 
13+ 
1114    [ Post ( "/api/media" ) ] 
1215    [ Multipart ] 
1316    Task < MediaUploadFileResponse >  UploadFile ( MultipartItem  file , 
Original file line number Diff line number Diff line change 77using  LcmCrdt . RemoteSync ; 
88using  Microsoft . Extensions . Logging ; 
99using  MiniLcm . Media ; 
10+ using  System . Net . Http . Json ; 
1011
1112namespace  LcmCrdt . MediaServer ; 
1213
@@ -69,6 +70,29 @@ public async Task<ReadFileResponse> GetFileStream(Guid fileId)
6970        return  new ( File . OpenRead ( localResource . LocalPath ) ,  Path . GetFileName ( localResource . LocalPath ) ) ; 
7071    } 
7172
73+     public  async  Task < LcmFileMetadata >  GetFileMetadata ( Guid  fileId ) 
74+     { 
75+         var  mediaClient  =  await  MediaServerClient ( ) ; 
76+         var  response  =  await  mediaClient . GetFileMetadata ( fileId ) ; 
77+         if  ( ! response . IsSuccessStatusCode ) 
78+         { 
79+             throw  new  Exception ( $ "Failed to retrieve metadata for file { fileId } : { response . StatusCode }  { response . ReasonPhrase } ") ; 
80+         } 
81+         var  metadata  =  await  response . Content . ReadFromJsonAsync < LcmFileMetadata > ( ) ; 
82+         if  ( metadata  is  null ) 
83+         { 
84+             // Try to get content into error message, but if buffering not enabled for this request, give up 
85+             var  content  =  "" ; 
86+             try 
87+             { 
88+                 content  =  await  response . Content . ReadAsStringAsync ( ) ; 
89+             } 
90+             catch  {  }  // Oh well, we tried 
91+             throw  new  Exception ( $ "Failed to retrieve metadata for file { fileId } : response was in incorrect format. { content } ") ; 
92+         } 
93+         return  metadata ; 
94+     } 
95+ 
7296    private  async  Task < ( Stream ?  stream ,  string ?  filename ) >  RequestMediaFile ( Guid  fileId ) 
7397    { 
7498        var  mediaClient  =  await  MediaServerClient ( ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments