Skip to content

Commit

Permalink
Bug修复: 修复Alist子账户根目录获取失败问题
Browse files Browse the repository at this point in the history
close #235
  • Loading branch information
xieyy committed May 18, 2024
1 parent 4de171d commit 7d4a9a2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ object AlistRepository : BaseRepository() {
}

/**
* 获取Alist根目录
* 获取Alist当前用户信息
*/
suspend fun getRootFile(url: String, token: String) = request()
suspend fun getUserInfo(url: String, token: String) = request()
.doGet {
Retrofit.alistService.getRootPath(url, token)
Retrofit.alistService.getUserInfo(url, token)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface AlistService {
): CommonJsonModel<AlistLoginData>

@GET("/api/me")
suspend fun getRootPath(
suspend fun getUserInfo(
@Header(HeaderKey.BASE_URL) baseUrl: String,
@Header(HeaderKey.AUTHORIZATION) authorization: String?,
): CommonJsonModel<AlistRootData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.xyoye.common_component.network.repository.ResourceRepository
import com.xyoye.common_component.storage.AbstractStorage
import com.xyoye.common_component.storage.file.StorageFile
import com.xyoye.common_component.storage.file.impl.AlistStorageFile
import com.xyoye.common_component.weight.ToastCenter
import com.xyoye.data_component.data.alist.AlistFileData
import com.xyoye.data_component.entity.MediaLibraryEntity
import com.xyoye.data_component.entity.PlayHistoryEntity
Expand Down Expand Up @@ -37,10 +38,16 @@ class AlistStorage(
val newToken = refreshToken() ?: return null
this.token = newToken

return AlistRepository.getRootFile(rootUrl, token).getOrNull()
val result = AlistRepository.getUserInfo(rootUrl, token)
if (result.isFailure) {
ToastCenter.showToast("${result.exceptionOrNull()?.message}")
return null
}

return result.getOrNull()
?.successData
?.let {
AlistFileData(it.rootPath, true)
AlistFileData("/", true)
}?.let {
AlistStorageFile("", it, this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import kotlinx.parcelize.Parcelize
@JsonClass(generateAdapter = true)
data class AlistRootData(
@NullToEmptyString
@Json(name = "base_path")
val rootPath: String = ""
@Json(name = "username")
val userName: String = ""
) : Parcelable

0 comments on commit 7d4a9a2

Please sign in to comment.