diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 72701cdd..dad84266 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -35,7 +35,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ var repoUrl: String, var token: String, var userName: String, - var userAvatar: String + var userAvatar: String, + var gistUrl: String ) companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile @@ -79,17 +80,18 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ tmpDir.deleteRecursively() } - private data class gistsElements ( + data class gistsElements ( @JsonProperty("git_pull_url") val gitUrl: String, + @JsonProperty("url") val gistUrl:String, @JsonProperty("files") val files: Map, @JsonProperty("owner") val owner: OwnerData ) - private data class OwnerData( + data class OwnerData( @JsonProperty("login") val userName: String, @JsonProperty("avatar_url") val userAvatar : String ) data class File ( - @JsonProperty("filename") val filename: String + @JsonProperty("raw_url") val rawUrl: String ) private suspend fun initLogin(githubToken: String): Boolean{ @@ -122,7 +124,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ return false }, userName = it.owner.userName, - userAvatar = it.owner.userAvatar + userAvatar = it.owner.userAvatar, + gistUrl = it.gistUrl )) } return true @@ -135,7 +138,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ return false }, userName = it.owner.userName, - userAvatar = it.owner.userAvatar + userAvatar = it.owner.userAvatar, + gistUrl = it.gistUrl )) return true } @@ -159,7 +163,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun getLatestLoginData(): InAppAuthAPI.LoginData? { val current = getAuthKey() ?: return null - return InAppAuthAPI.LoginData(email = current.repoUrl, password = current.token, username = current.userName) + return InAppAuthAPI.LoginData(email = current.repoUrl, password = current.token, username = current.userName, server = current.gistUrl) } override suspend fun initialize() { currentSession = getAuthKey() diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 63ff071a..9ef6bde1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.module.kotlin.readValue import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.plugins.PLUGINS_KEY import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL @@ -30,12 +31,9 @@ import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_S import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_TOKEN_KEY import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_UNIXTIME_KEY import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_USER_KEY -import com.lagradost.cloudstream3.syncproviders.providers.OpenSubtitlesApi import com.lagradost.cloudstream3.syncproviders.providers.OpenSubtitlesApi.Companion.OPEN_SUBTITLES_USER_KEY import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson -import com.lagradost.cloudstream3.utils.BackupUtils.restore -import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs @@ -54,7 +52,6 @@ import java.io.PrintWriter import java.lang.System.currentTimeMillis import java.text.SimpleDateFormat import java.util.* - object BackupUtils { /** @@ -297,7 +294,7 @@ object BackupUtils { } - fun FragmentActivity.BackupGithub(){ + fun FragmentActivity.backupGithub(){ val backup = this.getBackup() ioSafe { val tmpDir = createTempDir() @@ -339,20 +336,10 @@ object BackupUtils { fun FragmentActivity.restorePromptGithub() = ioSafe { - val tmpDir = createTempDir() - val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") - val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") - Git.cloneRepository() - .setURI(gitUrl) - .setDirectory(tmpDir) - .setTimeout(30) - .setCredentialsProvider( - UsernamePasswordCredentialsProvider(token, "") - ) - .call() - val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readText().toString() - val data = parseJson(jsondata?: "") - tmpDir.deleteRecursively() + val gitUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() + val jsondata = app.get(gitUrl).text + val dataurl = parseJson(jsondata ?: "").files.values.first().rawUrl + val data = parseJson(app.get(dataurl).text) this@restorePromptGithub.restore( data, restoreSettings = true, @@ -360,3 +347,4 @@ object BackupUtils { ) } } +