From d9824b5b8ac91d1086efe9be251f92484cf4705e Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Aug 2022 02:48:13 +0200 Subject: [PATCH] fixes --- .../syncproviders/providers/GithubApi.kt | 62 +++++++++++++------ 1 file changed, 42 insertions(+), 20 deletions(-) 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 bea24033..2189f6b8 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 @@ -78,7 +78,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ .call(); tmpDir.delete() } - private class repos ( + private class reposElements ( @JsonProperty("full_name") var repoName: String ) @@ -89,27 +89,49 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ "Authorization" to "token $githubToken" ) ) - val - val response = app.post("https://api.github.com/user/repos", - headers= mapOf( - "Accept" to "application/vnd.github+json", - "Authorization" to "token $githubToken" - ), - requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody( - RequestBodyTypes.JSON.toMediaTypeOrNull())) + if (repoResponse.isSuccessful) { + val repo = tryParseJson>(repoResponse.text)?.filter { + it.repoName == "sync-data-for-Cloudstream" + } + if (repo?.isEmpty() == true) { + val response = app.post( + "https://api.github.com/user/repos", + headers = mapOf( + "Accept" to "application/vnd.github+json", + "Authorization" to "token $githubToken" + ), + requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody( + RequestBodyTypes.JSON.toMediaTypeOrNull() + ) + ) - if (!response.isSuccessful) {return false} - - val repoUrl = tryParseJson(response.text).let { - setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( - token = githubToken, - repoUrl = it?.repoUrl?: run { + if (!response.isSuccessful) { return false - })) - it.repoUrl - } - commitFile(repoUrl, githubToken) - return true + } + + val repoUrl = tryParseJson(response.text).let { + setKey( + accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoUrl ?: run { + return false + }) + ) + it.repoUrl + } + commitFile(repoUrl, githubToken) + return true + } + else{ + repo.first().let { { + setKey( + accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoName ?: run { + return false + }) + ) + } } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {