diff --git a/app/build.gradle b/app/build.gradle index 9d869e48..291e71ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -199,7 +199,6 @@ dependencies { // Library/extensions searching with Levenshtein distance implementation 'me.xdrop:fuzzywuzzy:1.4.0' - } task androidSourcesJar(type: Jar) { 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 964f0e2e..42bf2b02 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 @@ -33,16 +33,17 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ var userName: String, var userAvatar: String, ) + companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile var currentSession: GithubOAuthEntity? = null } + private fun getAuthKey(): GithubOAuthEntity? { return getKey(accountId, GITHUB_USER_KEY) } - - data class gistsElements ( + data class GistsElements ( @JsonProperty("id") val gistId:String, @JsonProperty("files") val files: Map, @JsonProperty("owner") val owner: OwnerData @@ -54,6 +55,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ data class File ( @JsonProperty("content") val dataRaw: String? ) + data class GistRequestBody( @JsonProperty("description") val description: String, @JsonProperty("public") val public : Boolean, @@ -76,7 +78,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ if (!response.isSuccessful) { return false } - val repo = tryParseJson>(response.text)?.filter { + val repo = tryParseJson>(response.text)?.filter { it.files.keys.first() == "Cloudstream_Backup_data.txt" } @@ -89,13 +91,9 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ ), requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody( RequestBodyTypes.JSON.toMediaTypeOrNull())) - /* - """{"description":"Cloudstream private backup gist","public":false,"files":{"Cloudstream_Backup_data.txt":{"content":"initialization"}}}""".toRequestBody( - RequestBodyTypes.JSON.toMediaTypeOrNull())) - */ if (!gitresponse.isSuccessful) {return false} - tryParseJson(gitresponse.text).let { + tryParseJson(gitresponse.text).let { setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( token = githubToken, gistId = it?.gistId?: run { 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 bf3a45ee..a8ff94f6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -34,7 +34,6 @@ import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_U 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.getBackup import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs @@ -300,40 +299,7 @@ object BackupUtils { val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") - /* ioSafe { - val tmpDir = createTempDir() - val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") - val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") - val git = Git.cloneRepository() - .setURI(gitUrl) - .setDirectory(tmpDir) - .setTimeout(30) - .setCredentialsProvider( - UsernamePasswordCredentialsProvider(token, "") - ) - .call() - tmpDir.listFiles()?.first { it.name != ".git" }?.writeText(backup.toJson()) - git.add() - .addFilepattern(".") - .call() - git.commit() - .setAll(true) - .setMessage("Update backup") - .call() - git.remoteAdd() - .setName("origin") - .setUri(URIish(gitUrl)) - .call() - git.push() - .setRemote(gitUrl) - .setTimeout(30) - .setCredentialsProvider( - UsernamePasswordCredentialsProvider(token, "") - ) - .call(); - tmpDir.deleteRecursively() - } - */ + ioSafe { app.patch("https://api.github.com/gists/$gistId", headers= mapOf( @@ -358,7 +324,7 @@ object BackupUtils { val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() val jsondata = app.get(" https://api.github.com/gists/$gistId").text val dataraw = - parseJson(jsondata ?: "").files.values.first().dataRaw + parseJson(jsondata ?: "").files.values.first().dataRaw ?: throw IllegalAccessException() val data = parseJson(dataraw) restore(