This commit is contained in:
Antony 2022-08-24 02:48:13 +02:00
parent df54745294
commit d9824b5b8a

View file

@ -78,7 +78,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
.call(); .call();
tmpDir.delete() tmpDir.delete()
} }
private class repos ( private class reposElements (
@JsonProperty("full_name") var repoName: String @JsonProperty("full_name") var repoName: String
) )
@ -89,28 +89,50 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
"Authorization" to "token $githubToken" "Authorization" to "token $githubToken"
) )
) )
val if (repoResponse.isSuccessful) {
val response = app.post("https://api.github.com/user/repos", val repo = tryParseJson<List<reposElements>>(repoResponse.text)?.filter {
headers= mapOf( 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", "Accept" to "application/vnd.github+json",
"Authorization" to "token $githubToken" "Authorization" to "token $githubToken"
), ),
requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody( requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody(
RequestBodyTypes.JSON.toMediaTypeOrNull())) RequestBodyTypes.JSON.toMediaTypeOrNull()
)
)
if (!response.isSuccessful) {return false} if (!response.isSuccessful) {
return false
}
val repoUrl = tryParseJson<repodata>(response.text).let { val repoUrl = tryParseJson<repodata>(response.text).let {
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( setKey(
accountId, GITHUB_USER_KEY, GithubOAuthEntity(
token = githubToken, token = githubToken,
repoUrl = it?.repoUrl?: run { repoUrl = it?.repoUrl ?: run {
return false return false
})) })
)
it.repoUrl it.repoUrl
} }
commitFile(repoUrl, githubToken) commitFile(repoUrl, githubToken)
return true 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 { override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {
switchToNewAccount() switchToNewAccount()