fix(all/googledriveindex): fix file sizes & use parseAs function (#1828)
This commit is contained in:
@ -6,7 +6,7 @@ ext {
|
|||||||
extName = 'GoogleDriveIndex'
|
extName = 'GoogleDriveIndex'
|
||||||
pkgNameSuffix = 'all.googledriveindex'
|
pkgNameSuffix = 'all.googledriveindex'
|
||||||
extClass = '.GoogleDriveIndex'
|
extClass = '.GoogleDriveIndex'
|
||||||
extVersionCode = 6
|
extVersionCode = 7
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,10 +282,9 @@ class GoogleDriveIndex : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
|
|
||||||
val popBody = "password=&page_token=$newToken&page_index=$newPageIndex".toRequestBody("application/x-www-form-urlencoded".toMediaType())
|
val popBody = "password=&page_token=$newToken&page_index=$newPageIndex".toRequestBody("application/x-www-form-urlencoded".toMediaType())
|
||||||
|
|
||||||
val parsedBody = client.newCall(
|
val parsed = client.newCall(
|
||||||
POST(newParsed.url, body = popBody, headers = popHeaders),
|
POST(newParsed.url, body = popBody, headers = popHeaders),
|
||||||
).execute().body.string().decrypt()
|
).execute().parseAs<ResponseData> { it.decrypt() }
|
||||||
val parsed = json.decodeFromString<ResponseData>(parsedBody)
|
|
||||||
|
|
||||||
parsed.data.files.forEach { item ->
|
parsed.data.files.forEach { item ->
|
||||||
if (item.mimeType.startsWith("image/") && item.name.startsWith("cover", true)) {
|
if (item.mimeType.startsWith("image/") && item.name.startsWith("cover", true)) {
|
||||||
@ -386,10 +385,9 @@ class GoogleDriveIndex : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
|
|
||||||
val popBody = "password=&page_token=$newToken&page_index=$newPageIndex".toRequestBody("application/x-www-form-urlencoded".toMediaType())
|
val popBody = "password=&page_token=$newToken&page_index=$newPageIndex".toRequestBody("application/x-www-form-urlencoded".toMediaType())
|
||||||
|
|
||||||
val parsedBody = client.newCall(
|
val parsed = client.newCall(
|
||||||
POST(url, body = popBody, headers = popHeaders),
|
POST(url, body = popBody, headers = popHeaders),
|
||||||
).execute().body.string().decrypt()
|
).execute().parseAs<ResponseData> { it.decrypt() }
|
||||||
val parsed = json.decodeFromString<ResponseData>(parsedBody)
|
|
||||||
|
|
||||||
parsed.data.files.forEach { item ->
|
parsed.data.files.forEach { item ->
|
||||||
if (item.mimeType.endsWith("folder")) {
|
if (item.mimeType.endsWith("folder")) {
|
||||||
@ -493,6 +491,11 @@ class GoogleDriveIndex : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
|
|
||||||
// ============================= Utilities ==============================
|
// ============================= Utilities ==============================
|
||||||
|
|
||||||
|
private inline fun <reified T> Response.parseAs(transform: (String) -> String = { it }): T {
|
||||||
|
val responseBody = use { transform(it.body.string()) }
|
||||||
|
return json.decodeFromString(responseBody)
|
||||||
|
}
|
||||||
|
|
||||||
private fun HttpUrl.hostAndCred(): String {
|
private fun HttpUrl.hostAndCred(): String {
|
||||||
return if (this.password.isNotBlank() && this.username.isNotBlank()) {
|
return if (this.password.isNotBlank() && this.username.isNotBlank()) {
|
||||||
"${this.username}:${this.password}@${this.host}"
|
"${this.username}:${this.password}@${this.host}"
|
||||||
@ -532,9 +535,9 @@ class GoogleDriveIndex : ConfigurableAnimeSource, AnimeHttpSource() {
|
|||||||
|
|
||||||
private fun formatFileSize(bytes: Long): String {
|
private fun formatFileSize(bytes: Long): String {
|
||||||
return when {
|
return when {
|
||||||
bytes >= 1073741824 -> "%.2f GB".format(bytes / 1073741824.0)
|
bytes >= 1_000_000_000 -> "%.2f GB".format(bytes / 1_000_000_000.0)
|
||||||
bytes >= 1048576 -> "%.2f MB".format(bytes / 1048576.0)
|
bytes >= 1_000_000 -> "%.2f MB".format(bytes / 1_000_000.0)
|
||||||
bytes >= 1024 -> "%.2f KB".format(bytes / 1024.0)
|
bytes >= 1_000 -> "%.2f KB".format(bytes / 1_000.0)
|
||||||
bytes > 1 -> "$bytes bytes"
|
bytes > 1 -> "$bytes bytes"
|
||||||
bytes == 1L -> "$bytes byte"
|
bytes == 1L -> "$bytes byte"
|
||||||
else -> ""
|
else -> ""
|
||||||
|
Reference in New Issue
Block a user