refactor: move JellyfinAuthInterceptor and JellyfinNetworkModule to the domain module

This commit is contained in:
2026-04-24 09:36:19 +02:00
parent a1239c907a
commit 57e2983527
4 changed files with 6 additions and 7 deletions

View File

@@ -1,22 +0,0 @@
package hu.bbara.purefin.data.jellyfin
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import hu.bbara.purefin.data.jellyfin.client.JellyfinAuthInterceptor
import okhttp3.OkHttpClient
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object JellyfinNetworkModule {
@Provides
@Singleton
fun provideOkHttpClient(authInterceptor: JellyfinAuthInterceptor): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(authInterceptor)
.build()
}
}

View File

@@ -1,35 +0,0 @@
package hu.bbara.purefin.data.jellyfin.client
import hu.bbara.purefin.data.session.UserSessionRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import okhttp3.Interceptor
import okhttp3.Response
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class JellyfinAuthInterceptor @Inject constructor(
userSessionRepository: UserSessionRepository
) : Interceptor {
@Volatile
private var cachedToken: String = ""
init {
userSessionRepository.accessToken
.onEach { cachedToken = it }
.launchIn(CoroutineScope(SupervisorJob() + Dispatchers.IO))
}
override fun intercept(chain: Interceptor.Chain): Response {
val token = cachedToken
val request = chain.request().newBuilder()
.addHeader("X-Emby-Token", token)
.build()
return chain.proceed(request)
}
}