11using ByteSync . Common . Business . SharedFiles ;
22using ByteSync . ServerCommon . Business . Auth ;
33using ByteSync . ServerCommon . Business . Sessions ;
4+ using ByteSync . ServerCommon . Business . Settings ;
45using ByteSync . ServerCommon . Interfaces . Repositories ;
56using ByteSync . ServerCommon . Interfaces . Services ;
67using ByteSync . ServerCommon . Interfaces . Services . Storage ;
78using Microsoft . Extensions . Logging ;
9+ using Microsoft . Extensions . Options ;
810
911namespace ByteSync . ServerCommon . Services ;
1012
@@ -13,19 +15,21 @@ public class SharedFilesService : ISharedFilesService
1315 private readonly ISharedFilesRepository _sharedFilesRepository ;
1416 private readonly IAzureBlobStorageService _azureBlobStorageService ;
1517 private readonly ICloudflareR2Service _cloudflareR2Service ;
16-
18+ private readonly AppSettings _appSettings ;
1719 private readonly ILogger < SharedFilesService > _logger ;
1820
1921 public SharedFilesService (
2022 ISharedFilesRepository sharedFilesRepository ,
2123 IAzureBlobStorageService azureBlobStorageService ,
2224 ICloudflareR2Service cloudflareR2Service ,
23- ILogger < SharedFilesService > logger )
25+ ILogger < SharedFilesService > logger ,
26+ IOptions < AppSettings > appSettings )
2427 {
2528 _sharedFilesRepository = sharedFilesRepository ;
2629 _azureBlobStorageService = azureBlobStorageService ;
2730 _cloudflareR2Service = cloudflareR2Service ;
2831 _logger = logger ;
32+ _appSettings = appSettings . Value ;
2933 }
3034
3135 public async Task AssertFilePartIsUploaded ( TransferParameters transferParameters , ICollection < string > recipients )
@@ -63,7 +67,7 @@ public async Task AssertFilePartIsDownloaded(Client downloadedBy, TransferParame
6367 {
6468 var sharedFileDefinition = transferParameters . SharedFileDefinition ;
6569 var partNumber = transferParameters . PartNumber ! . Value ;
66- bool deleteBlob = false ;
70+ bool objectDeletable = false ;
6771 bool unregister = false ;
6872
6973 await _sharedFilesRepository . AddOrUpdate ( sharedFileDefinition , sharedFileData =>
@@ -77,7 +81,7 @@ await _sharedFilesRepository.AddOrUpdate(sharedFileDefinition, sharedFileData =>
7781
7882 if ( sharedFileData . IsPartFullyDownloaded ( partNumber ) )
7983 {
80- deleteBlob = true ;
84+ objectDeletable = true ;
8185 }
8286
8387 if ( sharedFileData . IsFullyDownloaded )
@@ -88,7 +92,7 @@ await _sharedFilesRepository.AddOrUpdate(sharedFileDefinition, sharedFileData =>
8892 return sharedFileData ;
8993 } ) ;
9094
91- if ( deleteBlob )
95+ if ( ( objectDeletable ) & & ( ! _appSettings . RetainFilesAfterTransfer ) )
9296 {
9397 try
9498 {
0 commit comments