rename variables and String.isTransferable fix

This commit is contained in:
antonydp 2022-10-31 10:38:52 +01:00
parent dc073b9ded
commit 6012ffb509
3 changed files with 12 additions and 11 deletions

View file

@ -84,7 +84,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
if (repo?.isEmpty() == true){ if (repo?.isEmpty() == true){
val backupData = context?.getBackup() val backupData = context?.getBackup()
val gitresponse = app.post("https://api.github.com/gists", val gitResponse = app.post("https://api.github.com/gists",
headers= mapOf( headers= mapOf(
Pair("Accept" , "application/vnd.github+json"), Pair("Accept" , "application/vnd.github+json"),
Pair("Authorization", "token $githubToken"), Pair("Authorization", "token $githubToken"),
@ -92,8 +92,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody( requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody(
RequestBodyTypes.JSON.toMediaTypeOrNull())) RequestBodyTypes.JSON.toMediaTypeOrNull()))
if (!gitresponse.isSuccessful) {return false} if (!gitResponse.isSuccessful) {return false}
tryParseJson<GistsElements>(gitresponse.text).let { tryParseJson<GistsElements>(gitResponse.text).let {
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
token = githubToken, token = githubToken,
gistId = it?.gistId?: run { gistId = it?.gistId?: run {

View file

@ -82,7 +82,7 @@ object BackupUtils {
/** false if blacklisted key */ /** false if blacklisted key */
private fun String.isTransferable(): Boolean { private fun String.isTransferable(): Boolean {
return !nonTransferableKeys.contains(this) return !nonTransferableKeys.contains(this) and !nonTransferableKeys.any { this.endsWith(it) }
} }
var restoreFileSelector: ActivityResultLauncher<Array<String>>? = null var restoreFileSelector: ActivityResultLauncher<Array<String>>? = null
@ -295,7 +295,7 @@ object BackupUtils {
fun FragmentActivity.backupGithub(){ fun FragmentActivity.backupGithub(){
val backup = this.getBackup() val backup = this.getBackup().toJson()
val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username") val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username")
val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username")
@ -309,7 +309,7 @@ object BackupUtils {
requestBody = GithubApi.GistRequestBody( requestBody = GithubApi.GistRequestBody(
"Cloudstream private backup gist", "Cloudstream private backup gist",
false, false,
GithubApi.FilesGist(GithubApi.ContentFilesGist(backup.toJson()))) GithubApi.FilesGist(GithubApi.ContentFilesGist(backup)))
.toJson() .toJson()
.toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull()) .toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull())
) )
@ -322,11 +322,11 @@ object BackupUtils {
} }
suspend fun Context.restorePromptGithub() { suspend fun Context.restorePromptGithub() {
val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
val jsondata = app.get(" https://api.github.com/gists/$gistId").text val jsonData = app.get("https://api.github.com/gists/$gistId").text
val dataraw = val dataRaw =
parseJson<GithubApi.GistsElements>(jsondata ?: "").files.values.first().dataRaw parseJson<GithubApi.GistsElements>(jsonData ?: "").files.values.first().dataRaw
?: throw IllegalAccessException() ?: throw IllegalAccessException()
val data = parseJson<BackupFile>(dataraw) val data = parseJson<BackupFile>(dataRaw)
restore( restore(
data, data,
restoreSettings = true, restoreSettings = true,

View file

@ -165,6 +165,7 @@
<string name="episode_sync_settings_des">Sincronizza automaticamente gli episodi guardati</string> <string name="episode_sync_settings_des">Sincronizza automaticamente gli episodi guardati</string>
<string name="restore_settings">Ripristinare i dati da backup</string> <string name="restore_settings">Ripristinare i dati da backup</string>
<string name="automatic_restore_settings">Backup automatico su Github</string>
<string name="backup_settings">Backup data</string> <string name="backup_settings">Backup data</string>
<string name="restore_success">File di backup caricato</string> <string name="restore_success">File di backup caricato</string>