mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fixes
This commit is contained in:
parent
d5f6f38ca8
commit
6ab90504f4
2 changed files with 60 additions and 53 deletions
|
@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.syncproviders.providers
|
|||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.lagradost.cloudstream3.*
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
||||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.syncproviders.AuthAPI
|
||||
|
@ -46,24 +47,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
|||
)
|
||||
|
||||
|
||||
private suspend fun initLogin(githubToken: String): Boolean{
|
||||
val response = app.post("https://api.github.com/user/repos",
|
||||
headers= mapOf(
|
||||
Pair("Accept" , "application/vnd.github+json"),
|
||||
Pair("Authorization", "token $githubToken"),
|
||||
),
|
||||
requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody(
|
||||
RequestBodyTypes.JSON.toMediaTypeOrNull()))
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val repoUrl = tryParseJson<repodata>(response.text).let {
|
||||
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
|
||||
token = githubToken,
|
||||
repoUrl = it?.repoUrl?: run {
|
||||
return false
|
||||
}))
|
||||
it.repoUrl
|
||||
}
|
||||
private fun commitFile(repoUrl: String, githubToken: String){
|
||||
val tmpDir = createTempDir()
|
||||
val git = Git.cloneRepository()
|
||||
.setURI("https://github.com/$repoUrl.git")
|
||||
|
@ -92,9 +76,32 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
|||
UsernamePasswordCredentialsProvider(githubToken, "")
|
||||
)
|
||||
.call();
|
||||
return true
|
||||
tmpDir.delete()
|
||||
}
|
||||
private class repos{
|
||||
|
||||
}
|
||||
private suspend fun initLogin(githubToken: String): Boolean{
|
||||
val response = app.post("https://api.github.com/user/repos",
|
||||
headers= mapOf(
|
||||
"Accept" to "application/vnd.github+json",
|
||||
"Authorization" to "token $githubToken"
|
||||
),
|
||||
requestBody = """{"name":"sync data for Cloudstream", "description": "Private repo for cloudstream Account", "private": true}""".toRequestBody(
|
||||
RequestBodyTypes.JSON.toMediaTypeOrNull()))
|
||||
|
||||
if (!response.isSuccessful) {return false}
|
||||
|
||||
val repoUrl = tryParseJson<repodata>(response.text).let {
|
||||
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
|
||||
token = githubToken,
|
||||
repoUrl = it?.repoUrl?: run {
|
||||
return false
|
||||
}))
|
||||
it.repoUrl
|
||||
}
|
||||
commitFile(repoUrl, githubToken)
|
||||
return true
|
||||
}
|
||||
|
||||
override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {
|
||||
|
@ -118,23 +125,24 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
|
|||
return InAppAuthAPI.LoginData(username = current.repoUrl, password = current.token)
|
||||
}
|
||||
override suspend fun initialize() {
|
||||
currentSession = getAuthKey() ?: return // just in case the following fails
|
||||
setKey(currentSession!!.repoUrl, currentSession!!.token)
|
||||
currentSession = getAuthKey()
|
||||
val repoUrl = currentSession?.repoUrl ?: return
|
||||
val token = currentSession?.token ?: return
|
||||
setKey(repoUrl, token)
|
||||
}
|
||||
override fun logOut() {
|
||||
AcraApplication.removeKey(accountId, GITHUB_USER_KEY)
|
||||
removeKey(accountId, GITHUB_USER_KEY)
|
||||
removeAccountKeys()
|
||||
currentSession = getAuthKey()
|
||||
}
|
||||
|
||||
override fun loginInfo(): AuthAPI.LoginInfo? {
|
||||
getAuthKey()?.let { user ->
|
||||
return AuthAPI.LoginInfo(
|
||||
return getAuthKey()?.let { user ->
|
||||
AuthAPI.LoginInfo(
|
||||
profilePicture = null,
|
||||
name = user.repoUrl,
|
||||
accountIndex = accountIndex,
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.A
|
|||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_UNIXTIME_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_USER_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.GithubApi
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.GithubApi.Companion.GITHUB_USER_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_CACHED_LIST
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_REFRESH_TOKEN_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_SHOULD_UPDATE_LIST
|
||||
|
@ -76,7 +77,7 @@ object BackupUtils {
|
|||
// The plugins themselves are not backed up
|
||||
PLUGINS_KEY,
|
||||
PLUGINS_KEY_LOCAL,
|
||||
|
||||
GITHUB_USER_KEY,
|
||||
OPEN_SUBTITLES_USER_KEY,
|
||||
"nginx_user", // Nginx user key
|
||||
|
||||
|
@ -335,7 +336,7 @@ object BackupUtils {
|
|||
|
||||
}
|
||||
|
||||
fun FragmentActivity.restorePromptGithub(){
|
||||
fun FragmentActivity.restorePromptGithub() =
|
||||
ioSafe {
|
||||
val tmpDir = createTempDir()
|
||||
val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username")
|
||||
|
@ -348,8 +349,7 @@ object BackupUtils {
|
|||
UsernamePasswordCredentialsProvider("$token", "")
|
||||
)
|
||||
.call()
|
||||
val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readLines()
|
||||
?.joinToString()
|
||||
val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readText().toString()
|
||||
val data = parseJson<BackupFile>(jsondata?: "")
|
||||
this@restorePromptGithub.restore(
|
||||
data,
|
||||
|
@ -357,5 +357,4 @@ object BackupUtils {
|
|||
restoreDataStore = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue