2022-08-17 20:20:31 +00:00
|
|
|
package com.lagradost
|
|
|
|
|
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
|
|
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
|
|
|
import com.lagradost.cloudstream3.R
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.AccountManager
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.AuthAPI
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI
|
|
|
|
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager
|
|
|
|
|
|
|
|
class NginxApi(index: Int) : InAppAuthAPIManager(index) {
|
|
|
|
override val name = "Nginx"
|
|
|
|
override val idPrefix = "nginx"
|
2022-08-19 13:57:09 +00:00
|
|
|
override val icon = R.drawable.ic_baseline_extension_24
|
2022-08-17 20:20:31 +00:00
|
|
|
override val requiresUsername = true
|
|
|
|
override val requiresPassword = true
|
|
|
|
override val requiresServer = true
|
2022-10-17 10:10:11 +00:00
|
|
|
override val createAccountUrl = "https://www.cloudstream.cf/docs/users/use-nginx.md"
|
2022-08-17 20:20:31 +00:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val NGINX_USER_KEY: String = "nginx_user"
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
|
|
|
return getKey(accountId, NGINX_USER_KEY)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun loginInfo(): AuthAPI.LoginInfo? {
|
|
|
|
val data = getLatestLoginData() ?: return null
|
|
|
|
return AuthAPI.LoginInfo(name = data.username ?: data.server, accountIndex = accountIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {
|
|
|
|
if (data.server.isNullOrBlank()) return false // we require a server
|
|
|
|
switchToNewAccount()
|
|
|
|
setKey(accountId, NGINX_USER_KEY, data)
|
|
|
|
registerAccount()
|
|
|
|
initialize()
|
|
|
|
AccountManager.inAppAuths
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun logOut() {
|
|
|
|
removeAccountKeys()
|
|
|
|
initializeData()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun initializeData() {
|
|
|
|
val data = getLatestLoginData() ?: run {
|
|
|
|
NginxProvider.overrideUrl = null
|
|
|
|
NginxProvider.loginCredentials = null
|
|
|
|
return
|
|
|
|
}
|
2022-08-28 13:01:55 +00:00
|
|
|
NginxProvider.overrideUrl = data.server?.removeSuffix("/") + "/"
|
2022-08-17 20:20:31 +00:00
|
|
|
NginxProvider.loginCredentials = "${data.username ?: ""}:${data.password ?: ""}"
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun initialize() {
|
|
|
|
initializeData()
|
|
|
|
}
|
2022-08-19 13:57:09 +00:00
|
|
|
}
|