@@ -1280,6 +1280,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
12801280 int waitForNextAttempt = 1000 ;
12811281 UploadModel um = new UploadModel ( ) ;
12821282 um . tis = _tis ;
1283+ um . startDate = DateTime . Now ;
12831284 um . path = currentFilePath ;
12841285 um . chatName = _ts . getChatName ( Convert . ToInt64 ( dbName ) ) ;
12851286 // add upload to task list
@@ -1335,6 +1336,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
13351336 um . chatName = _ts . getChatName ( Convert . ToInt64 ( dbName ) ) ;
13361337 // add upload to task list
13371338 idt . addUpload ( um ) ;
1339+ um . startDate = DateTime . Now ;
13381340 while ( attempts != 0 || um . state == StateTask . Canceled )
13391341 try
13401342 {
@@ -1586,43 +1588,65 @@ public bool isChannelRefreshing(string channelId)
15861588
15871589 public async Task UploadFile ( string dbName , string currentPath , UploadFiles file ) // ItemsUploadedEventArgs<FileManagerDirectoryContent> args)
15881590 {
1591+ _logger . LogInformation ( "UploadFile started - DbName: {DbName}, CurrentPath: {CurrentPath}, FileName: {FileName}, FileSize: {FileSize} bytes ({FileSizeMB:F2} MB)" ,
1592+ dbName , currentPath , file . File . Name , file . File . Size , file . File . Size / 1024.0 / 1024.0 ) ;
1593+
15891594 try
15901595 {
15911596 string currentFilePath = System . IO . Path . Combine ( TEMPDIR , dbName + currentPath ) ;
1592- await SaveToFile ( file . File , currentFilePath ) ;
1597+ _logger . LogDebug ( "Saving file to temp path: {TempPath}" , currentFilePath ) ;
15931598
1599+ await SaveToFile ( file . File , currentFilePath ) ;
1600+ _logger . LogDebug ( "File saved to temp successfully" ) ;
15941601
15951602 BsonFileManagerModel model = new BsonFileManagerModel ( ) ;
15961603 model . Size = file . File . Size ;
15971604 TL . Message m = null ;
1605+
15981606 if ( file . File . Size > MaxSize )
15991607 {
1608+ _logger . LogInformation ( "File exceeds MaxSize ({MaxSizeMB:F2} MB), splitting file into chunks" , MaxSize / 1024.0 / 1024.0 ) ;
16001609
16011610 List < string > files = await splitFileStreamAsync ( currentFilePath , file . File . Name , MaxSize ) ;
1611+ _logger . LogDebug ( "File split into {ChunkCount} chunks" , files . Count ) ;
1612+
16021613 File . Delete ( System . IO . Path . Combine ( currentFilePath , file . File . Name ) ) ;
16031614 int i = 1 ;
16041615 model . ListMessageId = new List < int > ( ) ;
16051616 model . isSplit = true ;
1617+
16061618 foreach ( string s in files )
16071619 {
1620+ _logger . LogDebug ( "Uploading chunk {ChunkNumber} of {TotalChunks}: {ChunkPath}" , i , files . Count , s ) ;
1621+
16081622 using ( FileStream fs = new FileStream ( s , FileMode . Open , FileAccess . Read , FileShare . Read ) )
16091623 m = await _ts . uploadFile ( dbName , fs , $ "({ i } of { files . Count } ) - " + file . File . Name , caption : getCaption ( currentPath ) ) ;
1624+
16101625 model . ListMessageId . Add ( m . ID ) ;
1626+ _logger . LogDebug ( "Chunk {ChunkNumber} uploaded successfully, MessageId: {MessageId}" , i , m . ID ) ;
1627+
16111628 File . Delete ( s ) ;
16121629 i ++ ;
16131630 }
16141631
1632+ _logger . LogInformation ( "All {ChunkCount} chunks uploaded successfully" , files . Count ) ;
16151633 }
16161634 else
16171635 {
1636+ _logger . LogDebug ( "Uploading single file to Telegram" ) ;
1637+
16181638 using ( FileStream ms = new FileStream ( System . IO . Path . Combine ( currentFilePath , file . File . Name ) , FileMode . Open ) )
16191639 {
16201640 m = await _ts . uploadFile ( dbName , ms , file . File . Name , caption : getCaption ( currentPath ) ) ;
16211641 }
16221642 model . MessageId = m . ID ;
1643+
1644+ _logger . LogDebug ( "File uploaded to Telegram, MessageId: {MessageId}" , m . ID ) ;
16231645 }
16241646
16251647 BsonFileManagerModel parent = await _db . getParentDirectoryByPath ( dbName , currentPath ) ;
1648+ _logger . LogDebug ( "Parent directory found - ParentId: {ParentId}, ParentName: {ParentName}" , parent ? . Id , parent ? . Name ) ;
1649+
16261650 model . Name = file . File . Name ;
16271651 model . IsFile = true ;
16281652 model . HasChild = false ;
@@ -1635,13 +1659,20 @@ public async Task UploadFile(string dbName, string currentPath, UploadFiles file
16351659 model . Type = file . File . Name . Split ( "." ) . LastOrDefault ( ) != null ? "." + file . File . Name . Split ( "." ) . LastOrDefault ( ) : file . File . ContentType ;
16361660
16371661 await _db . createEntry ( dbName , model ) ;
1662+ _logger . LogDebug ( "Database entry created for file" ) ;
1663+
16381664 await _db . addBytesToFolder ( dbName , model . ParentId , model . Size ) ;
1665+ _logger . LogDebug ( "Folder size updated" ) ;
16391666
16401667 GC . Collect ( ) ;
1668+
1669+ _logger . LogInformation ( "UploadFile completed successfully - FileName: {FileName}, IsSplit: {IsSplit}, MessageId: {MessageId}" ,
1670+ file . File . Name , model . isSplit , model . isSplit ? string . Join ( "," , model . ListMessageId ) : model . MessageId . ToString ( ) ) ;
16411671 }
16421672 catch ( Exception ex )
16431673 {
1644- _logger . LogError ( ex , "Error on uploadFile - FileName: {FileName}, Message: {Message}" , file . File . Name , ex . Message ) ;
1674+ _logger . LogError ( ex , "Error on uploadFile - FileName: {FileName}, CurrentPath: {CurrentPath}, DbName: {DbName}, Message: {Message}" ,
1675+ file . File . Name , currentPath , dbName , ex . Message ) ;
16451676 NotificationModel nm = new NotificationModel ( ) ;
16461677 nm . sendEvent ( new Notification ( $ "Error on UploadFile: { file . File . Name } ", "Error" , NotificationTypes . Error ) ) ;
16471678 throw ex ;
0 commit comments