added check to previously made backups

This commit is contained in:
Antony 2022-08-24 03:00:21 +02:00
parent d9824b5b8a
commit 98c85d7eb2

View file

@ -79,19 +79,23 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
tmpDir.delete()
}
private class reposElements (
@JsonProperty("full_name") var repoName: String
@JsonProperty("full_name") var repoName: String,
@JsonProperty("name") var shortRepoName: String
)
private suspend fun initLogin(githubToken: String): Boolean{
val repoResponse = app.post("https://api.github.com/user/repos",
val repoResponse = app.get("https://api.github.com/user/repos",
headers= mapOf(
"Accept" to "application/vnd.github+json",
"Authorization" to "token $githubToken"
)
)
if (repoResponse.isSuccessful) {
if (!repoResponse.isSuccessful) {
return false
}
val repo = tryParseJson<List<reposElements>>(repoResponse.text)?.filter {
it.repoName == "sync-data-for-Cloudstream"
it.shortRepoName == "sync-data-for-Cloudstream"
}
if (repo?.isEmpty() == true) {
val response = app.post(
@ -123,14 +127,14 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
return true
}
else{
repo.first().let { {
setKey(
accountId, GITHUB_USER_KEY, GithubOAuthEntity(
repo?.first().let {
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
token = githubToken,
repoUrl = it?.repoName ?: run {
repoUrl = it?.repoName?: run {
return false
})
)
}))
return true
}
}
}