mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
switch on gist.github
This commit is contained in:
parent
409f8f743d
commit
801d608beb
2 changed files with 18 additions and 26 deletions
|
@ -35,7 +35,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
var repoUrl: String,
|
var repoUrl: String,
|
||||||
var token: String,
|
var token: String,
|
||||||
var userName: String,
|
var userName: String,
|
||||||
var userAvatar: String
|
var userAvatar: String,
|
||||||
|
var gistUrl: String
|
||||||
)
|
)
|
||||||
companion object {
|
companion object {
|
||||||
const val GITHUB_USER_KEY: String = "github_user" // user data like profile
|
const val GITHUB_USER_KEY: String = "github_user" // user data like profile
|
||||||
|
@ -79,17 +80,18 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
tmpDir.deleteRecursively()
|
tmpDir.deleteRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class gistsElements (
|
data class gistsElements (
|
||||||
@JsonProperty("git_pull_url") val gitUrl: String,
|
@JsonProperty("git_pull_url") val gitUrl: String,
|
||||||
|
@JsonProperty("url") val gistUrl:String,
|
||||||
@JsonProperty("files") val files: Map<String, File>,
|
@JsonProperty("files") val files: Map<String, File>,
|
||||||
@JsonProperty("owner") val owner: OwnerData
|
@JsonProperty("owner") val owner: OwnerData
|
||||||
)
|
)
|
||||||
private data class OwnerData(
|
data class OwnerData(
|
||||||
@JsonProperty("login") val userName: String,
|
@JsonProperty("login") val userName: String,
|
||||||
@JsonProperty("avatar_url") val userAvatar : String
|
@JsonProperty("avatar_url") val userAvatar : String
|
||||||
)
|
)
|
||||||
data class File (
|
data class File (
|
||||||
@JsonProperty("filename") val filename: String
|
@JsonProperty("raw_url") val rawUrl: String
|
||||||
)
|
)
|
||||||
|
|
||||||
private suspend fun initLogin(githubToken: String): Boolean{
|
private suspend fun initLogin(githubToken: String): Boolean{
|
||||||
|
@ -122,7 +124,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
userName = it.owner.userName,
|
userName = it.owner.userName,
|
||||||
userAvatar = it.owner.userAvatar
|
userAvatar = it.owner.userAvatar,
|
||||||
|
gistUrl = it.gistUrl
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -135,7 +138,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
userName = it.owner.userName,
|
userName = it.owner.userName,
|
||||||
userAvatar = it.owner.userAvatar
|
userAvatar = it.owner.userAvatar,
|
||||||
|
gistUrl = it.gistUrl
|
||||||
))
|
))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -159,7 +163,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
||||||
|
|
||||||
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
||||||
val current = getAuthKey() ?: return null
|
val current = getAuthKey() ?: return null
|
||||||
return InAppAuthAPI.LoginData(email = current.repoUrl, password = current.token, username = current.userName)
|
return InAppAuthAPI.LoginData(email = current.repoUrl, password = current.token, username = current.userName, server = current.gistUrl)
|
||||||
}
|
}
|
||||||
override suspend fun initialize() {
|
override suspend fun initialize() {
|
||||||
currentSession = getAuthKey()
|
currentSession = getAuthKey()
|
||||||
|
|
|
@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.app
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY
|
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY
|
||||||
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL
|
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL
|
||||||
|
@ -30,12 +31,9 @@ import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_S
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_TOKEN_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_TOKEN_KEY
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_UNIXTIME_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_UNIXTIME_KEY
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_USER_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_USER_KEY
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.OpenSubtitlesApi
|
|
||||||
import com.lagradost.cloudstream3.syncproviders.providers.OpenSubtitlesApi.Companion.OPEN_SUBTITLES_USER_KEY
|
import com.lagradost.cloudstream3.syncproviders.providers.OpenSubtitlesApi.Companion.OPEN_SUBTITLES_USER_KEY
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||||
import com.lagradost.cloudstream3.utils.BackupUtils.restore
|
|
||||||
import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub
|
|
||||||
|
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs
|
import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs
|
||||||
|
@ -54,7 +52,6 @@ import java.io.PrintWriter
|
||||||
import java.lang.System.currentTimeMillis
|
import java.lang.System.currentTimeMillis
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object BackupUtils {
|
object BackupUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -297,7 +294,7 @@ object BackupUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun FragmentActivity.BackupGithub(){
|
fun FragmentActivity.backupGithub(){
|
||||||
val backup = this.getBackup()
|
val backup = this.getBackup()
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val tmpDir = createTempDir()
|
val tmpDir = createTempDir()
|
||||||
|
@ -339,20 +336,10 @@ object BackupUtils {
|
||||||
|
|
||||||
fun FragmentActivity.restorePromptGithub() =
|
fun FragmentActivity.restorePromptGithub() =
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val tmpDir = createTempDir()
|
val gitUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
|
||||||
val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username")
|
val jsondata = app.get(gitUrl).text
|
||||||
val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username")
|
val dataurl = parseJson<GithubApi.gistsElements>(jsondata ?: "").files.values.first().rawUrl
|
||||||
Git.cloneRepository()
|
val data = parseJson<BackupFile>(app.get(dataurl).text)
|
||||||
.setURI(gitUrl)
|
|
||||||
.setDirectory(tmpDir)
|
|
||||||
.setTimeout(30)
|
|
||||||
.setCredentialsProvider(
|
|
||||||
UsernamePasswordCredentialsProvider(token, "")
|
|
||||||
)
|
|
||||||
.call()
|
|
||||||
val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readText().toString()
|
|
||||||
val data = parseJson<BackupFile>(jsondata?: "")
|
|
||||||
tmpDir.deleteRecursively()
|
|
||||||
this@restorePromptGithub.restore(
|
this@restorePromptGithub.restore(
|
||||||
data,
|
data,
|
||||||
restoreSettings = true,
|
restoreSettings = true,
|
||||||
|
@ -360,3 +347,4 @@ object BackupUtils {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue