mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
BackupGithub and restorePromptGithub in BackupUtils.kt
added GithubApi in SettingsAccount.kt
This commit is contained in:
parent
10f4d33c59
commit
2de76ddd34
7 changed files with 141 additions and 20 deletions
|
@ -199,6 +199,9 @@ dependencies {
|
|||
|
||||
// Library/extensions searching with Levenshtein distance
|
||||
implementation 'me.xdrop:fuzzywuzzy:1.4.0'
|
||||
|
||||
// Git
|
||||
implementation 'org.openl.jgit:org.eclipse.jgit:6.2.0.202206071550-openl'
|
||||
}
|
||||
|
||||
task androidSourcesJar(type: Jar) {
|
||||
|
|
|
@ -11,6 +11,7 @@ abstract class AccountManager(private val defIndex: Int) : AuthAPI {
|
|||
val malApi = MALApi(0)
|
||||
val aniListApi = AniListApi(0)
|
||||
val openSubtitlesApi = OpenSubtitlesApi(0)
|
||||
val githubApi = GithubApi(0)
|
||||
val indexSubtitlesApi = IndexSubtitleApi()
|
||||
|
||||
// used to login via app intent
|
||||
|
@ -22,7 +23,7 @@ abstract class AccountManager(private val defIndex: Int) : AuthAPI {
|
|||
// this needs init with context and can be accessed in settings
|
||||
val accountManagers
|
||||
get() = listOf(
|
||||
malApi, aniListApi, openSubtitlesApi, //nginxApi
|
||||
malApi, aniListApi, openSubtitlesApi, githubApi //nginxApi
|
||||
)
|
||||
|
||||
// used for active syncing
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.lagradost.cloudstream3.syncproviders.providers
|
||||
|
||||
import com.lagradost.cloudstream3.*
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||
import com.lagradost.cloudstream3.subtitles.AbstractSubApi
|
||||
import com.lagradost.cloudstream3.syncproviders.AuthAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager
|
||||
|
||||
|
||||
class GithubApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi {
|
||||
override val idPrefix = "Github"
|
||||
override val name = "Github"
|
||||
override val icon = R.drawable.ic_github_logo
|
||||
override val requiresPassword = true
|
||||
override val requiresUsername = true
|
||||
override val createAccountUrl = "https://github.com/settings/tokens/new"
|
||||
|
||||
data class GithubOAuthEntity(
|
||||
var repository: String,
|
||||
var access_token: String,
|
||||
)
|
||||
private fun getAuthKey(): GithubOAuthEntity? {
|
||||
return getKey(accountId, OpenSubtitlesApi.OPEN_SUBTITLES_USER_KEY)
|
||||
}
|
||||
override fun loginInfo(): AuthAPI.LoginInfo? {
|
||||
getAuthKey()?.let { user ->
|
||||
return AuthAPI.LoginInfo(
|
||||
profilePicture = null,
|
||||
name = user.repository,
|
||||
accountIndex = accountIndex
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
||||
val current = getAuthKey() ?: return null
|
||||
return InAppAuthAPI.LoginData(username = current.repository, current.access_token)
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager
|
|||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.openSubtitlesApi
|
||||
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.githubApi
|
||||
import com.lagradost.cloudstream3.syncproviders.AuthAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.OAuth2API
|
||||
|
@ -219,6 +220,8 @@ class SettingsAccount : PreferenceFragmentCompat() {
|
|||
R.string.mal_key to malApi,
|
||||
R.string.anilist_key to aniListApi,
|
||||
R.string.opensubtitles_key to openSubtitlesApi,
|
||||
R.string.github_key to githubApi
|
||||
|
||||
)
|
||||
|
||||
for ((key, api) in syncApis) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
|||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.apmap
|
||||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY
|
||||
import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL
|
||||
|
@ -28,6 +27,12 @@ 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_UNIXTIME_KEY
|
||||
import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_USER_KEY
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
||||
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.DataStore.getDefaultSharedPrefs
|
||||
import com.lagradost.cloudstream3.utils.DataStore.getSharedPrefs
|
||||
import com.lagradost.cloudstream3.utils.DataStore.mapper
|
||||
|
@ -36,6 +41,9 @@ import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
|
|||
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
|
||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
|
||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager.isDownloadDir
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.transport.URIish
|
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
|
||||
import java.io.IOException
|
||||
import java.io.PrintWriter
|
||||
import java.lang.System.currentTimeMillis
|
||||
|
@ -278,4 +286,65 @@ object BackupUtils {
|
|||
setKeyRaw(it.key, it.value, isEditingAppSettings)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun FragmentActivity.BackupGithub(){
|
||||
val backup = this.getBackup()
|
||||
ioSafe {
|
||||
val tmpDir = createTempDir()
|
||||
val git = Git.cloneRepository()
|
||||
.setURI("https://github.com/Github_USERNAME/Repo_NAME.git")
|
||||
.setDirectory(tmpDir)
|
||||
.setTimeout(30)
|
||||
.setCredentialsProvider(
|
||||
UsernamePasswordCredentialsProvider("HERE GOES GITHUB TOKEN", "")
|
||||
)
|
||||
.call()
|
||||
|
||||
tmpDir.listFiles()?.first { it.name != ".git" }?.writeText(backup.toJson())
|
||||
git.add()
|
||||
.addFilepattern(".")
|
||||
.call()
|
||||
git.commit()
|
||||
.setAll(true)
|
||||
.setMessage("Update results")
|
||||
.call()
|
||||
git.remoteAdd()
|
||||
.setName("origin")
|
||||
.setUri(URIish("https://github.com/Github_USERNAME/Repo_NAME.git"))
|
||||
.call()
|
||||
git.push()
|
||||
.setRemote("https://github.com/Github_USERNAME/Repo_NAME.git")
|
||||
.setTimeout(30)
|
||||
.setCredentialsProvider(
|
||||
UsernamePasswordCredentialsProvider("HERE GOES GITHUB TOKEN", "")
|
||||
)
|
||||
.call();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun FragmentActivity.restorePromptGithub(){
|
||||
ioSafe {
|
||||
val tmpDir = createTempDir()
|
||||
Git.cloneRepository()
|
||||
.setURI("https://github.com/Github_USERNAME/Repo_NAME.git")
|
||||
.setDirectory(tmpDir)
|
||||
.setTimeout(30)
|
||||
.setCredentialsProvider(
|
||||
UsernamePasswordCredentialsProvider("", "")
|
||||
)
|
||||
.call()
|
||||
val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readLines()
|
||||
?.joinToString()
|
||||
val data = parseJson<BackupFile>(jsondata?: "")
|
||||
this@restorePromptGithub.restore(
|
||||
data,
|
||||
restoreSettings = true,
|
||||
restoreDataStore = true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -459,6 +459,7 @@
|
|||
<string name="anilist_key" translatable="false">anilist_key</string>
|
||||
<string name="mal_key" translatable="false">mal_key</string>
|
||||
<string name="opensubtitles_key" translatable="false">opensubtitles_key</string>
|
||||
<string name="github_key" translatable="false">github_key</string>
|
||||
<string name="nginx_key" translatable="false">nginx_key</string>
|
||||
<string name="example_password">password123</string>
|
||||
<string name="example_username">MyCoolUsername</string>
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
<Preference
|
||||
android:key="@string/opensubtitles_key"
|
||||
android:icon="@drawable/open_subtitles_icon" />
|
||||
<Preference
|
||||
android:key="@string/github_key"
|
||||
android:icon="@drawable/ic_github_logo" />
|
||||
<!-- <Preference-->
|
||||
<!-- android:key="@string/nginx_key"-->
|
||||
<!-- android:icon="@drawable/nginx" />-->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue