switch on gist.github

This commit is contained in:
Antony 2022-08-25 14:15:26 +02:00
parent 801d608beb
commit 8e5198753f
2 changed files with 5 additions and 38 deletions

View file

@ -47,39 +47,6 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
}
private fun commitFile(repoUrl: String, githubToken: String){
val tmpDir = createTempDir()
val git = Git.cloneRepository()
.setURI("https://github.com/$repoUrl.git")
.setDirectory(tmpDir)
.setTimeout(30)
.setCredentialsProvider(
UsernamePasswordCredentialsProvider(githubToken, "")
)
.call()
createTempFile("backup", "txt", tmpDir)
git.add()
.addFilepattern(".")
.call()
git.commit()
.setAll(true)
.setMessage("Update backup")
.call()
git.remoteAdd()
.setName("origin")
.setUri(URIish("https://github.com/$repoUrl.git"))
.call()
git.push()
.setRemote("https://github.com/$repoUrl.git")
.setTimeout(30)
.setCredentialsProvider(
UsernamePasswordCredentialsProvider(githubToken, "")
)
.call();
tmpDir.deleteRecursively()
}
data class gistsElements (
@JsonProperty("git_pull_url") val gitUrl: String,
@JsonProperty("url") val gistUrl:String,
@ -91,7 +58,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
@JsonProperty("avatar_url") val userAvatar : String
)
data class File (
@JsonProperty("raw_url") val rawUrl: String
@JsonProperty("content") val dataRaw: String
)
private suspend fun initLogin(githubToken: String): Boolean{

View file

@ -336,10 +336,10 @@ object BackupUtils {
fun FragmentActivity.restorePromptGithub() =
ioSafe {
val gitUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
val jsondata = app.get(gitUrl).text
val dataurl = parseJson<GithubApi.gistsElements>(jsondata ?: "").files.values.first().rawUrl
val data = parseJson<BackupFile>(app.get(dataurl).text)
val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
val jsondata = app.get(gistUrl).text
val dataraw = parseJson<GithubApi.gistsElements>(jsondata ?: "").files.values.first().dataRaw
val data = parseJson<BackupFile>(dataraw)
this@restorePromptGithub.restore(
data,
restoreSettings = true,