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.send.SendMessage
|
||||||
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText
|
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText
|
||||||
import org.telegram.telegrambots.meta.api.objects.Document
|
import org.telegram.telegrambots.meta.api.objects.Document
|
||||||
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
@ -57,7 +58,7 @@ object DefaultOneDriveTransferCallback : OneDriveTransferCallback {
|
|||||||
.text("""
|
.text("""
|
||||||
OneDrive 中转任务执行中
|
OneDrive 中转任务执行中
|
||||||
文件名: ${progress.currentTask.document.fileName}
|
文件名: ${progress.currentTask.document.fileName}
|
||||||
进度:${progress.progress.get() * 100}%
|
进度:${String.format("%.3f", progress.progress.get() * 100)}%
|
||||||
""".trimIndent())
|
""".trimIndent())
|
||||||
.build())
|
.build())
|
||||||
}
|
}
|
||||||
@ -158,8 +159,8 @@ class OneDriveTransferTaskExecutor(
|
|||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
} catch (e: Exception) {
|
} catch (e: TelegramApiException) {
|
||||||
if (e !is SocketTimeoutException) {
|
if (e.cause !is SocketTimeoutException) {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
if (++retryCount > maxRetryCount) {
|
if (++retryCount > maxRetryCount) {
|
||||||
|
@ -55,10 +55,18 @@ class OneDriveTransferSettingManager(private val authClient: ConfidentialClientA
|
|||||||
userName = result.account().username()
|
userName = result.account().username()
|
||||||
}
|
}
|
||||||
?: OneDriveTransferSetting.new {
|
?: OneDriveTransferSetting.new {
|
||||||
|
val drive = try {
|
||||||
|
OneDriveTransferService.createGraphClient(authClient, result.account())
|
||||||
|
.me().drive()
|
||||||
|
.buildRequest().get()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
telegramUserId = userId
|
telegramUserId = userId
|
||||||
accountId = result.account().homeAccountId()
|
accountId = result.account().homeAccountId()
|
||||||
userName = result.account().username()
|
userName = result.account().username()
|
||||||
driveId = ""
|
driveId = drive?.id ?: ""
|
||||||
storagePath = "Telegram Files/"
|
storagePath = "Telegram Files/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,11 +51,7 @@ class OneDriveTransferService(
|
|||||||
authClient.accounts.get().firstOrNull { account ->
|
authClient.accounts.get().firstOrNull { account ->
|
||||||
account.homeAccountId() == it.accountId
|
account.homeAccountId() == it.accountId
|
||||||
}
|
}
|
||||||
}?.let {
|
}?.let { Companion.createGraphClient(authClient, it) } ?: throw OneDriveNotLoginException()
|
||||||
GraphServiceClient.builder()
|
|
||||||
.httpClient(HttpClients.createDefault(MsalAuthorizationProvider(authClient, it)))
|
|
||||||
.buildClient()
|
|
||||||
} ?: throw OneDriveNotLoginException()
|
|
||||||
THREAD_CURRENT_GRAPH_CLIENT.set(ClientCache(userId, serviceClient))
|
THREAD_CURRENT_GRAPH_CLIENT.set(ClientCache(userId, serviceClient))
|
||||||
return serviceClient
|
return serviceClient
|
||||||
}
|
}
|
||||||
@ -127,6 +123,12 @@ class OneDriveTransferService(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val THREAD_CURRENT_GRAPH_CLIENT = ThreadLocal<ClientCache>()
|
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