mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
BackupGithub fix
This commit is contained in:
parent
24009c5caa
commit
2e5e5020df
3 changed files with 21 additions and 14 deletions
|
@ -19,7 +19,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
|
|
||||||
data class GithubOAuthEntity(
|
data class GithubOAuthEntity(
|
||||||
var user: String,
|
var user: String,
|
||||||
var pass: String
|
var token: String
|
||||||
)
|
)
|
||||||
companion object {
|
companion object {
|
||||||
const val GITHUB_USER_KEY: String = "github_user" // user data like profile
|
const val GITHUB_USER_KEY: String = "github_user" // user data like profile
|
||||||
|
@ -30,10 +30,10 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
}
|
}
|
||||||
override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {
|
override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {
|
||||||
switchToNewAccount()
|
switchToNewAccount()
|
||||||
val username = data.username ?: throw IllegalArgumentException ("Requires Username")
|
val repoUrl = data.username ?: throw IllegalArgumentException ("Requires Username")
|
||||||
val password = data.password ?: throw IllegalArgumentException ("Requires Password")
|
val password = data.password ?: throw IllegalArgumentException ("Requires Password")
|
||||||
try {
|
try {
|
||||||
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(username, password))
|
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(repoUrl, password))
|
||||||
registerAccount()
|
registerAccount()
|
||||||
return true
|
return true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -46,11 +46,11 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
|
|
||||||
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
||||||
val current = getAuthKey() ?: return null
|
val current = getAuthKey() ?: return null
|
||||||
return InAppAuthAPI.LoginData(username = current.user, current.pass)
|
return InAppAuthAPI.LoginData(username = current.user, password = current.token)
|
||||||
}
|
}
|
||||||
override suspend fun initialize() {
|
override suspend fun initialize() {
|
||||||
currentSession = getAuthKey() ?: return // just in case the following fails
|
currentSession = getAuthKey() ?: return // just in case the following fails
|
||||||
setKey(currentSession!!.user, currentSession!!.pass)
|
setKey(currentSession!!.user, currentSession!!.token)
|
||||||
}
|
}
|
||||||
override fun logOut() {
|
override fun logOut() {
|
||||||
AcraApplication.removeKey(accountId, GITHUB_USER_KEY)
|
AcraApplication.removeKey(accountId, GITHUB_USER_KEY)
|
||||||
|
@ -63,7 +63,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
return AuthAPI.LoginInfo(
|
return AuthAPI.LoginInfo(
|
||||||
profilePicture = null,
|
profilePicture = null,
|
||||||
name = user.user,
|
name = user.user,
|
||||||
accountIndex = accountIndex
|
accountIndex = accountIndex,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
||||||
|
import com.lagradost.cloudstream3.utils.BackupUtils.BackupGithub
|
||||||
import com.lagradost.cloudstream3.utils.BackupUtils.backup
|
import com.lagradost.cloudstream3.utils.BackupUtils.backup
|
||||||
import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt
|
import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
|
@ -41,7 +42,7 @@ class SettingsUpdates : PreferenceFragmentCompat() {
|
||||||
//val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
//val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||||
|
|
||||||
getPref(R.string.backup_key)?.setOnPreferenceClickListener {
|
getPref(R.string.backup_key)?.setOnPreferenceClickListener {
|
||||||
activity?.backup()
|
activity?.BackupGithub()
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,13 @@ import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY
|
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY
|
||||||
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL
|
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL
|
||||||
|
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.githubApi
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_CACHED_LIST
|
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_CACHED_LIST
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_SHOULD_UPDATE_LIST
|
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_SHOULD_UPDATE_LIST
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_TOKEN_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_TOKEN_KEY
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_UNIXTIME_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_UNIXTIME_KEY
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_USER_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_USER_KEY
|
||||||
|
import com.lagradost.cloudstream3.syncproviders.providers.GithubApi
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_CACHED_LIST
|
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_CACHED_LIST
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_REFRESH_TOKEN_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_REFRESH_TOKEN_KEY
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_SHOULD_UPDATE_LIST
|
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_SHOULD_UPDATE_LIST
|
||||||
|
@ -298,12 +300,14 @@ object BackupUtils {
|
||||||
val backup = this.getBackup()
|
val backup = this.getBackup()
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val tmpDir = createTempDir()
|
val tmpDir = createTempDir()
|
||||||
|
val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username")
|
||||||
|
val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username")
|
||||||
val git = Git.cloneRepository()
|
val git = Git.cloneRepository()
|
||||||
.setURI("https://github.com/Github_USERNAME/Repo_NAME.git")
|
.setURI("$repoUrl.git")
|
||||||
.setDirectory(tmpDir)
|
.setDirectory(tmpDir)
|
||||||
.setTimeout(30)
|
.setTimeout(30)
|
||||||
.setCredentialsProvider(
|
.setCredentialsProvider(
|
||||||
UsernamePasswordCredentialsProvider("HERE GOES GITHUB TOKEN", "")
|
UsernamePasswordCredentialsProvider(token, "")
|
||||||
)
|
)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
|
@ -317,13 +321,13 @@ object BackupUtils {
|
||||||
.call()
|
.call()
|
||||||
git.remoteAdd()
|
git.remoteAdd()
|
||||||
.setName("origin")
|
.setName("origin")
|
||||||
.setUri(URIish("https://github.com/Github_USERNAME/Repo_NAME.git"))
|
.setUri(URIish("$repoUrl.git"))
|
||||||
.call()
|
.call()
|
||||||
git.push()
|
git.push()
|
||||||
.setRemote("https://github.com/Github_USERNAME/Repo_NAME.git")
|
.setRemote("$repoUrl.git")
|
||||||
.setTimeout(30)
|
.setTimeout(30)
|
||||||
.setCredentialsProvider(
|
.setCredentialsProvider(
|
||||||
UsernamePasswordCredentialsProvider("HERE GOES GITHUB TOKEN", "")
|
UsernamePasswordCredentialsProvider(token, "")
|
||||||
)
|
)
|
||||||
.call();
|
.call();
|
||||||
}
|
}
|
||||||
|
@ -335,12 +339,14 @@ object BackupUtils {
|
||||||
fun FragmentActivity.restorePromptGithub(){
|
fun FragmentActivity.restorePromptGithub(){
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val tmpDir = createTempDir()
|
val tmpDir = createTempDir()
|
||||||
|
val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username")
|
||||||
|
val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username")
|
||||||
Git.cloneRepository()
|
Git.cloneRepository()
|
||||||
.setURI("https://github.com/Github_USERNAME/Repo_NAME.git")
|
.setURI("$repoUrl.git")
|
||||||
.setDirectory(tmpDir)
|
.setDirectory(tmpDir)
|
||||||
.setTimeout(30)
|
.setTimeout(30)
|
||||||
.setCredentialsProvider(
|
.setCredentialsProvider(
|
||||||
UsernamePasswordCredentialsProvider("", "")
|
UsernamePasswordCredentialsProvider("$token", "")
|
||||||
)
|
)
|
||||||
.call()
|
.call()
|
||||||
val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readLines()
|
val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readLines()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue