mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
added check to previously made backups
This commit is contained in:
parent
d9824b5b8a
commit
98c85d7eb2
1 changed files with 44 additions and 40 deletions
|
@ -79,59 +79,63 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
tmpDir.delete()
|
tmpDir.delete()
|
||||||
}
|
}
|
||||||
private class reposElements (
|
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{
|
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(
|
headers= mapOf(
|
||||||
"Accept" to "application/vnd.github+json",
|
"Accept" to "application/vnd.github+json",
|
||||||
"Authorization" to "token $githubToken"
|
"Authorization" to "token $githubToken"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if (repoResponse.isSuccessful) {
|
if (!repoResponse.isSuccessful) {
|
||||||
val repo = tryParseJson<List<reposElements>>(repoResponse.text)?.filter {
|
return false
|
||||||
it.repoName == "sync-data-for-Cloudstream"
|
}
|
||||||
}
|
val repo = tryParseJson<List<reposElements>>(repoResponse.text)?.filter {
|
||||||
if (repo?.isEmpty() == true) {
|
it.shortRepoName == "sync-data-for-Cloudstream"
|
||||||
val response = app.post(
|
}
|
||||||
"https://api.github.com/user/repos",
|
if (repo?.isEmpty() == true) {
|
||||||
headers = mapOf(
|
val response = app.post(
|
||||||
"Accept" to "application/vnd.github+json",
|
"https://api.github.com/user/repos",
|
||||||
"Authorization" to "token $githubToken"
|
headers = mapOf(
|
||||||
),
|
"Accept" to "application/vnd.github+json",
|
||||||
requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody(
|
"Authorization" to "token $githubToken"
|
||||||
RequestBodyTypes.JSON.toMediaTypeOrNull()
|
),
|
||||||
)
|
requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody(
|
||||||
|
RequestBodyTypes.JSON.toMediaTypeOrNull()
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if (!response.isSuccessful) {
|
if (!response.isSuccessful) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val repoUrl = tryParseJson<repodata>(response.text).let {
|
val repoUrl = tryParseJson<repodata>(response.text).let {
|
||||||
setKey(
|
setKey(
|
||||||
accountId, GITHUB_USER_KEY, GithubOAuthEntity(
|
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
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
repo?.first().let {
|
||||||
|
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
|
||||||
|
token = githubToken,
|
||||||
|
repoUrl = it?.repoName?: run {
|
||||||
|
return false
|
||||||
|
}))
|
||||||
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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue