Skip to content

Commit 3a97874

Browse files
committed
fix requestFullUrl on production env
1 parent b20efc9 commit 3a97874

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

composeApp/src/commonMain/kotlin/in/procyk/shin/component/FavouritesComponent.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,19 @@ private fun Settings.saveFavourites(favourites: Map<String, Favourite>) {
119119

120120
private suspend fun HttpClient.requestFullUrl(shortUrl: String): String? {
121121
val response = get(shortUrl)
122-
if (response.status !in REDIRECT_STATUS_CODES) return null
123-
124-
return response.call.response.headers[HttpHeaders.Location]
122+
if (response.status in REDIRECT_STATUS_CODES) {
123+
return response.call.response.headers[HttpHeaders.Location]
124+
}
125+
val index = shortUrl.indexOf("/#")
126+
if (index == -1) return null
127+
128+
val productionShortUrl = shortUrl.replaceRange(0..index + 1, "https://api-shorten-kotlin.koyeb.app/")
129+
val productionResponse = get(productionShortUrl)
130+
if (productionResponse.status in REDIRECT_STATUS_CODES) {
131+
return productionResponse.call.response.headers[HttpHeaders.Location]
132+
}
133+
134+
return null
125135
}
126136

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

0 commit comments

Comments
 (0)