Browse Source

Merge branch 'housekeeping/remove-old-auth-code' into 'develop'

Remove old authentication retry code

See merge request funkwhale/funkwhale-android!57
enhancement/speed-up-pipelines
Ryan Harg 3 years ago
parent
commit
36771dcafb
  1. 4
      app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt
  2. 30
      app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt
  3. 1
      app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt

4
app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt

@ -626,6 +626,7 @@ class MainActivity : AppCompatActivity() {
private fun incrementListenCount(track: Track?) { private fun incrementListenCount(track: Track?) {
track?.let { track?.let {
it.log("Incrementing listen count for track ${track.id}")
lifecycleScope.launch(IO) { lifecycleScope.launch(IO) {
try { try {
Fuel Fuel
@ -634,7 +635,8 @@ class MainActivity : AppCompatActivity() {
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.body(Gson().toJson(mapOf("track" to track.id))) .body(Gson().toJson(mapOf("track" to track.id)))
.awaitStringResponse() .awaitStringResponse()
} catch (_: Exception) { } catch (e: Exception) {
e.log()
} }
} }
} }

30
app/src/main/java/audio/funkwhale/ffa/repositories/HttpUpstream.kt

@ -7,7 +7,6 @@ import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.FuelError import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.ResponseDeserializable import com.github.kittinunf.fuel.core.ResponseDeserializable
import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult import com.github.kittinunf.fuel.coroutines.awaitObjectResponseResult
import com.github.kittinunf.fuel.coroutines.awaitObjectResult
import com.github.kittinunf.result.Result import com.github.kittinunf.result.Result
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -92,37 +91,10 @@ class HttpUpstream<D : Any, R : OtterResponse<D>>(
val request = Fuel.get(mustNormalizeUrl(url)).apply { val request = Fuel.get(mustNormalizeUrl(url)).apply {
authorize(context) authorize(context)
} }
val (_, _, result) = request.awaitObjectResponseResult(GenericDeserializer<R>(type))
val (_, response, result) = request.awaitObjectResponseResult(GenericDeserializer<R>(type))
if (response.statusCode == 401) {
return retryGet(url)
}
result result
} catch (e: Exception) { } catch (e: Exception) {
Result.error(FuelError.wrap(e)) Result.error(FuelError.wrap(e))
} }
} }
private suspend fun retryGet(url: String): Result<R, FuelError> {
context?.let {
return try {
return if (http.refresh()) {
val request = Fuel.get(mustNormalizeUrl(url)).apply {
if (!Settings.isAnonymous()) {
header("Authorization", "Bearer ${oAuth.state().accessToken}")
}
}
request.awaitObjectResult(GenericDeserializer(type))
} else {
Result.Failure(FuelError.wrap(RefreshError))
}
} catch (e: Exception) {
Result.error(FuelError.wrap(e))
}
}
throw IllegalStateException("Illegal state: context is null")
}
} }

1
app/src/test/java/audio/funkwhale/ffa/activities/SplashActivityTest.kt

@ -22,6 +22,5 @@ class SplashActivityTest {
val appContext = Shadows.shadowOf(ApplicationProvider.getApplicationContext<FFA>()) val appContext = Shadows.shadowOf(ApplicationProvider.getApplicationContext<FFA>())
expectThat(appContext.nextStartedActivity.component).isEqualTo(expectedIntent.component) expectThat(appContext.nextStartedActivity.component).isEqualTo(expectedIntent.component)
} }
} }
} }

Loading…
Cancel
Save