feat: 登录后先使用用户自己的驱动器.
This commit is contained in:
parent
e5e0ebe399
commit
43b9d5f182
@ -16,6 +16,7 @@ import org.telegram.telegrambots.meta.api.methods.GetFile
|
||||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage
|
||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText
|
||||
import org.telegram.telegrambots.meta.api.objects.Document
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.net.SocketTimeoutException
|
||||
@ -57,7 +58,7 @@ object DefaultOneDriveTransferCallback : OneDriveTransferCallback {
|
||||
.text("""
|
||||
OneDrive 中转任务执行中
|
||||
文件名: ${progress.currentTask.document.fileName}
|
||||
进度:${progress.progress.get() * 100}%
|
||||
进度:${String.format("%.3f", progress.progress.get() * 100)}%
|
||||
""".trimIndent())
|
||||
.build())
|
||||
}
|
||||
@ -158,8 +159,8 @@ class OneDriveTransferTaskExecutor(
|
||||
.build()
|
||||
)
|
||||
break
|
||||
} catch (e: Exception) {
|
||||
if (e !is SocketTimeoutException) {
|
||||
} catch (e: TelegramApiException) {
|
||||
if (e.cause !is SocketTimeoutException) {
|
||||
throw e
|
||||
}
|
||||
if (++retryCount > maxRetryCount) {
|
||||
|
@ -55,10 +55,18 @@ class OneDriveTransferSettingManager(private val authClient: ConfidentialClientA
|
||||
userName = result.account().username()
|
||||
}
|
||||
?: OneDriveTransferSetting.new {
|
||||
val drive = try {
|
||||
OneDriveTransferService.createGraphClient(authClient, result.account())
|
||||
.me().drive()
|
||||
.buildRequest().get()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
telegramUserId = userId
|
||||
accountId = result.account().homeAccountId()
|
||||
userName = result.account().username()
|
||||
driveId = ""
|
||||
driveId = drive?.id ?: ""
|
||||
storagePath = "Telegram Files/"
|
||||
}
|
||||
}
|
||||
|
@ -51,11 +51,7 @@ class OneDriveTransferService(
|
||||
authClient.accounts.get().firstOrNull { account ->
|
||||
account.homeAccountId() == it.accountId
|
||||
}
|
||||
}?.let {
|
||||
GraphServiceClient.builder()
|
||||
.httpClient(HttpClients.createDefault(MsalAuthorizationProvider(authClient, it)))
|
||||
.buildClient()
|
||||
} ?: throw OneDriveNotLoginException()
|
||||
}?.let { Companion.createGraphClient(authClient, it) } ?: throw OneDriveNotLoginException()
|
||||
THREAD_CURRENT_GRAPH_CLIENT.set(ClientCache(userId, serviceClient))
|
||||
return serviceClient
|
||||
}
|
||||
@ -127,6 +123,12 @@ class OneDriveTransferService(
|
||||
|
||||
companion object {
|
||||
private val THREAD_CURRENT_GRAPH_CLIENT = ThreadLocal<ClientCache>()
|
||||
|
||||
fun createGraphClient(authClient: ConfidentialClientApplication, iAccount: IAccount): GraphServiceClient<Request> {
|
||||
return GraphServiceClient.builder()
|
||||
.httpClient(HttpClients.createDefault(MsalAuthorizationProvider(authClient, iAccount)))
|
||||
.buildClient()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user