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,27 +89,49 @@ 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"
"Accept" to "application/vnd.github+json", }
"Authorization" to "token $githubToken" if (repo?.isEmpty() == true) {
), val response = app.post(
requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody( "https://api.github.com/user/repos",
RequestBodyTypes.JSON.toMediaTypeOrNull())) 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} if (!response.isSuccessful) {
val repoUrl = tryParseJson<repodata>(response.text).let {
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
token = githubToken,
repoUrl = it?.repoUrl?: run {
return false return false
})) }
it.repoUrl
} val repoUrl = tryParseJson<repodata>(response.text).let {
commitFile(repoUrl, githubToken) setKey(
return true 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 { override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {