-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(images): option to use external proxy (#313)
* feat: use external proxy for images * feat(images): use imgur as alternate provider * chore: update translation * chore: apply suggestion * fix(imgur): add missing declaration to git * refactor(imgur): merge response classes * chore: apply suggestions * chore: apply suggestions
- Loading branch information
Showing
37 changed files
with
258 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
data/src/main/java/com/my/kizzy/data/remote/ExternalAsset.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* | ||
* ****************************************************************** | ||
* * * Copyright (C) 2022 | ||
* * * ExternalAsset.kt is part of Kizzy | ||
* * * and can not be copied and/or distributed without the express | ||
* * * permission of yzziK(Vaibhav) | ||
* * ***************************************************************** | ||
* | ||
* | ||
*/ | ||
|
||
package com.my.kizzy.data.remote | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ExternalAsset( | ||
@SerialName("external_asset_path") | ||
val externalAssetPath: String, | ||
@SerialName("url") | ||
val url: String | ||
) |
66 changes: 66 additions & 0 deletions
66
data/src/main/java/com/my/kizzy/data/remote/ImgurApiService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* | ||
* ****************************************************************** | ||
* * * Copyright (C) 2022 | ||
* * * ImgurApiService.kt is part of Kizzy | ||
* * * and can not be copied and/or distributed without the express | ||
* * * permission of yzziK(Vaibhav) | ||
* * ***************************************************************** | ||
* | ||
* | ||
*/ | ||
|
||
package com.my.kizzy.data.remote | ||
|
||
import com.my.kizzy.data.rpc.Constants.APPLICATION_ID | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.request.forms.MultiPartFormDataContent | ||
import io.ktor.client.request.forms.formData | ||
import io.ktor.client.request.headers | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import io.ktor.client.request.url | ||
import io.ktor.client.statement.HttpResponse | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.contentType | ||
import java.io.File | ||
import javax.inject.Inject | ||
|
||
class ImgurApiService @Inject constructor( | ||
private val client: HttpClient, | ||
@Discord private val discordBaseUrl: String, | ||
@Imgur private val imgurBaseUrl: String, | ||
) { | ||
suspend fun getImage(url: String, token: String) = runCatching { | ||
client.post { | ||
url("$discordBaseUrl/applications/$APPLICATION_ID/external-assets") | ||
headers { | ||
append(HttpHeaders.Authorization, token) | ||
append(HttpHeaders.ContentType, "application/json") | ||
} | ||
setBody(mapOf("urls" to arrayOf(url))) | ||
} | ||
} | ||
|
||
suspend fun uploadImage(file: File) = runCatching { | ||
client.post { | ||
url("$imgurBaseUrl/image") | ||
headers { | ||
// Imgur web client API key, unchanged for at least >5 years as of 2024 | ||
append(HttpHeaders.Authorization, "Client-ID 546c25a59c58ad7") | ||
} | ||
contentType(ContentType.MultiPart.FormData) | ||
setBody( | ||
MultiPartFormDataContent( | ||
formData { | ||
append("image", file.readBytes()) | ||
append("type", "raw") | ||
} | ||
) | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.