@@ -67,7 +67,7 @@ public protocol AccountManageable: AnyObject {
67
67
func forceReload( )
68
68
func reloadTokensAndAccounts( )
69
69
func getDriveFileManager( for driveId: Int , userId: Int ) -> DriveFileManager ?
70
- func getFirstAvailableDriveFileManager ( for userId : Int ) throws -> DriveFileManager
70
+ func getBestAvailableDriveFileManager ( for account : Account ) async throws -> DriveFileManager
71
71
72
72
/// Create on the fly an "in memory" DriveFileManager for a specific share
73
73
func getInMemoryDriveFileManager( for publicShareId: String , driveId: Int , rootFileId: Int ) -> DriveFileManager ?
@@ -227,22 +227,22 @@ public class AccountManager: RefreshTokenDelegate, AccountManageable {
227
227
return DriveFileManager ( drive: frozenPublicShareDrive, apiFetcher: DriveApiFetcher ( ) , context: context)
228
228
}
229
229
230
- public func getFirstAvailableDriveFileManager ( for userId : Int ) throws -> DriveFileManager {
231
- let userDrives = driveInfosManager. getDrives ( for: userId)
230
+ public func getBestAvailableDriveFileManager ( for account : Account ) async throws -> DriveFileManager {
231
+ let userDrives = Array ( driveInfosManager. getDrives ( for: account . userId) )
232
232
233
233
guard !userDrives. isEmpty else {
234
234
throw DriveError . NoDriveError. noDrive
235
235
}
236
236
237
- guard let firstAvailableDrive = userDrives . first ( where : { !$0 . inMaintenance } ) else {
237
+ guard let mainDrive = try ? await bestAvailableDrive ( from : userDrives , account : account ) else {
238
238
if userDrives [ 0 ] . isInTechnicalMaintenance {
239
239
throw DriveError . NoDriveError. maintenance ( drive: userDrives [ 0 ] )
240
240
} else {
241
241
throw DriveError . NoDriveError. blocked ( drive: userDrives [ 0 ] )
242
242
}
243
243
}
244
244
245
- guard let driveFileManager = getDriveFileManager ( for: firstAvailableDrive . id, userId: firstAvailableDrive . userId) else {
245
+ guard let driveFileManager = getDriveFileManager ( for: mainDrive . id, userId: mainDrive . userId) else {
246
246
// We should always have a driveFileManager here
247
247
throw DriveError . NoDriveError. noDriveFileManager
248
248
}
0 commit comments