Skip to content

Commit

Permalink
fix requestFullUrl on production env
Browse files Browse the repository at this point in the history
  • Loading branch information
avan1235 committed May 21, 2024
1 parent b20efc9 commit 3a97874
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,19 @@ private fun Settings.saveFavourites(favourites: Map<String, Favourite>) {

private suspend fun HttpClient.requestFullUrl(shortUrl: String): String? {
val response = get(shortUrl)
if (response.status !in REDIRECT_STATUS_CODES) return null

return response.call.response.headers[HttpHeaders.Location]
if (response.status in REDIRECT_STATUS_CODES) {
return response.call.response.headers[HttpHeaders.Location]
}
val index = shortUrl.indexOf("/#")
if (index == -1) return null

val productionShortUrl = shortUrl.replaceRange(0..index + 1, "https://api-shorten-kotlin.koyeb.app/")
val productionResponse = get(productionShortUrl)
if (productionResponse.status in REDIRECT_STATUS_CODES) {
return productionResponse.call.response.headers[HttpHeaders.Location]
}

return null
}

private val REDIRECT_STATUS_CODES: Set<HttpStatusCode> = setOf(HttpStatusCode.MovedPermanently, HttpStatusCode.Found)

0 comments on commit 3a97874

Please sign in to comment.