From 2de76ddd341b94eac594af95a332b18dd6a33d75 Mon Sep 17 00:00:00 2001 From: Antony Date: Sun, 21 Aug 2022 00:21:30 +0200 Subject: [PATCH 01/33] BackupGithub and restorePromptGithub in BackupUtils.kt added GithubApi in SettingsAccount.kt --- app/build.gradle | 3 + .../syncproviders/AccountManager.kt | 3 +- .../syncproviders/providers/GithubApi.kt | 41 +++++++++++ .../ui/settings/SettingsAccount.kt | 3 + .../cloudstream3/utils/BackupUtils.kt | 71 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/settings_account.xml | 39 +++++----- 7 files changed, 141 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt diff --git a/app/build.gradle b/app/build.gradle index 1aa62378..5fecb182 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt index 2bc39b54..daffa17d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/AccountManager.kt @@ -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 diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt new file mode 100644 index 00000000..b0b8b070 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -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) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt index 7d809187..b56ce338 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsAccount.kt @@ -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) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 48d96bb5..cbbe9231 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -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(jsondata?: "") + this@restorePromptGithub.restore( + data, + restoreSettings = true, + restoreDataStore = true + ) + } + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 873de287..9ee4189d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -459,6 +459,7 @@ anilist_key mal_key opensubtitles_key + github_key nginx_key password123 MyCoolUsername diff --git a/app/src/main/res/xml/settings_account.xml b/app/src/main/res/xml/settings_account.xml index d4bae8c4..754f895c 100644 --- a/app/src/main/res/xml/settings_account.xml +++ b/app/src/main/res/xml/settings_account.xml @@ -1,27 +1,30 @@ + xmlns:app="http://schemas.android.com/apk/res-auto"> + android:key="@string/mal_key" + android:icon="@drawable/mal_logo" /> + android:key="@string/anilist_key" + android:icon="@drawable/ic_anilist_icon" /> - - - + android:key="@string/opensubtitles_key" + android:icon="@drawable/open_subtitles_icon" /> + + + + - - - - - - - - + + + + + + + + \ No newline at end of file From 798ff9a436e5b12722a86f20ad415b06b074c1ef Mon Sep 17 00:00:00 2001 From: Antony Date: Sun, 21 Aug 2022 00:38:34 +0200 Subject: [PATCH 02/33] remove AbstractSubApi from GithubApi.kt --- .../lagradost/cloudstream3/syncproviders/providers/GithubApi.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index b0b8b070..cfdbd24f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -8,7 +8,7 @@ import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager -class GithubApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi { +class GithubApi(index: Int) : InAppAuthAPIManager(index){ override val idPrefix = "Github" override val name = "Github" override val icon = R.drawable.ic_github_logo From 9c6465c26e4f10a3f5d8ba100742de02b3ce66b4 Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 22 Aug 2022 00:22:54 +0200 Subject: [PATCH 03/33] GithubApi.kt fixes --- .../syncproviders/providers/GithubApi.kt | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index cfdbd24f..08b3fdc2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -2,7 +2,8 @@ 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.AcraApplication.Companion.setKey +import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.syncproviders.AuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager @@ -17,25 +18,54 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override val createAccountUrl = "https://github.com/settings/tokens/new" data class GithubOAuthEntity( - var repository: String, - var access_token: String, + var user: String, + var pass: String ) - private fun getAuthKey(): GithubOAuthEntity? { - return getKey(accountId, OpenSubtitlesApi.OPEN_SUBTITLES_USER_KEY) + companion object { + const val GITHUB_USER_KEY: String = "github_user" // user data like profile + var currentSession: GithubOAuthEntity? = null } + private fun getAuthKey(): GithubOAuthEntity? { + return getKey(accountId, GITHUB_USER_KEY) + } + override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { + switchToNewAccount() + val username = data.username ?: throw ErrorLoadingException("Requires Username") + val password = data.password ?: throw ErrorLoadingException("Requires Password") + try { + setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(username, password)) + registerAccount() + return true + } catch (e: Exception) { + logError(e) + switchToOldAccount() + } + switchToOldAccount() + return false + } + + override fun getLatestLoginData(): InAppAuthAPI.LoginData? { + val current = getAuthKey() ?: return null + return InAppAuthAPI.LoginData(username = current.user, current.pass) + } + override suspend fun initialize() { + currentSession = getAuthKey() ?: return // just in case the following fails + setKey(currentSession!!.user, currentSession!!.pass) + } + override fun logOut() { + AcraApplication.removeKey(accountId, GITHUB_USER_KEY) + removeAccountKeys() + currentSession = getAuthKey() + } + override fun loginInfo(): AuthAPI.LoginInfo? { getAuthKey()?.let { user -> return AuthAPI.LoginInfo( profilePicture = null, - name = user.repository, + name = user.user, accountIndex = accountIndex ) } return null } - override fun getLatestLoginData(): InAppAuthAPI.LoginData? { - val current = getAuthKey() ?: return null - return InAppAuthAPI.LoginData(username = current.repository, current.access_token) - } - } \ No newline at end of file From 24009c5caa2173a998eab111288dec152f19ff89 Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 22 Aug 2022 00:33:39 +0200 Subject: [PATCH 04/33] IllegalArgumentException --- .../cloudstream3/syncproviders/providers/GithubApi.kt | 4 ++-- .../syncproviders/providers/OpenSubtitlesApi.kt | 4 ++-- .../java/com/lagradost/cloudstream3/utils/BackupUtils.kt | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 08b3fdc2..9666dc34 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -30,8 +30,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { switchToNewAccount() - val username = data.username ?: throw ErrorLoadingException("Requires Username") - val password = data.password ?: throw ErrorLoadingException("Requires Password") + val username = data.username ?: throw IllegalArgumentException ("Requires Username") + val password = data.password ?: throw IllegalArgumentException ("Requires Password") try { setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(username, password)) registerAccount() diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index bfa65f62..e764f240 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -124,8 +124,8 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { - val username = data.username ?: throw ErrorLoadingException("Requires Username") - val password = data.password ?: throw ErrorLoadingException("Requires Password") + val username = data.username ?: throw IllegalArgumentException ("Requires Username") + val password = data.password ?: throw IllegalArgumentException ("Requires Password") switchToNewAccount() try { if (initLogin(username, password)) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index cbbe9231..57ca32b4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -27,6 +27,8 @@ 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.syncproviders.providers.OpenSubtitlesApi +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.toJson import com.lagradost.cloudstream3.utils.BackupUtils.restore @@ -71,7 +73,11 @@ object BackupUtils { // The plugins themselves are not backed up PLUGINS_KEY, - PLUGINS_KEY_LOCAL + PLUGINS_KEY_LOCAL, + + OPEN_SUBTITLES_USER_KEY, + "nginx_user", // Nginx user key + ) /** false if blacklisted key */ From 2e5e5020df3c4d22ecba23721ba758410ec7447c Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 22 Aug 2022 02:24:42 +0200 Subject: [PATCH 05/33] BackupGithub fix --- .../syncproviders/providers/GithubApi.kt | 12 +++++------ .../ui/settings/SettingsUpdates.kt | 3 ++- .../cloudstream3/utils/BackupUtils.kt | 20 ++++++++++++------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 9666dc34..c7c7e10b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -19,7 +19,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ data class GithubOAuthEntity( var user: String, - var pass: String + var token: String ) companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile @@ -30,10 +30,10 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { switchToNewAccount() - val username = data.username ?: throw IllegalArgumentException ("Requires Username") + val repoUrl = data.username ?: throw IllegalArgumentException ("Requires Username") val password = data.password ?: throw IllegalArgumentException ("Requires Password") try { - setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(username, password)) + setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(repoUrl, password)) registerAccount() return true } catch (e: Exception) { @@ -46,11 +46,11 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun getLatestLoginData(): InAppAuthAPI.LoginData? { val current = getAuthKey() ?: return null - return InAppAuthAPI.LoginData(username = current.user, current.pass) + return InAppAuthAPI.LoginData(username = current.user, password = current.token) } override suspend fun initialize() { currentSession = getAuthKey() ?: return // just in case the following fails - setKey(currentSession!!.user, currentSession!!.pass) + setKey(currentSession!!.user, currentSession!!.token) } override fun logOut() { AcraApplication.removeKey(accountId, GITHUB_USER_KEY) @@ -63,7 +63,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ return AuthAPI.LoginInfo( profilePicture = null, name = user.user, - accountIndex = accountIndex + accountIndex = accountIndex, ) } return null diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 6b19042a..9cabd473 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar +import com.lagradost.cloudstream3.utils.BackupUtils.BackupGithub import com.lagradost.cloudstream3.utils.BackupUtils.backup import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt import com.lagradost.cloudstream3.utils.Coroutines.ioSafe @@ -41,7 +42,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { //val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext()) getPref(R.string.backup_key)?.setOnPreferenceClickListener { - activity?.backup() + activity?.BackupGithub() return@setOnPreferenceClickListener true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 57ca32b4..7257da58 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -16,11 +16,13 @@ import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.plugins.PLUGINS_KEY import com.lagradost.cloudstream3.plugins.PLUGINS_KEY_LOCAL +import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.githubApi import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_CACHED_LIST import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_SHOULD_UPDATE_LIST import com.lagradost.cloudstream3.syncproviders.providers.AniListApi.Companion.ANILIST_TOKEN_KEY 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.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 @@ -298,12 +300,14 @@ object BackupUtils { val backup = this.getBackup() ioSafe { val tmpDir = createTempDir() + val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username") + val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") val git = Git.cloneRepository() - .setURI("https://github.com/Github_USERNAME/Repo_NAME.git") + .setURI("$repoUrl.git") .setDirectory(tmpDir) .setTimeout(30) .setCredentialsProvider( - UsernamePasswordCredentialsProvider("HERE GOES GITHUB TOKEN", "") + UsernamePasswordCredentialsProvider(token, "") ) .call() @@ -317,13 +321,13 @@ object BackupUtils { .call() git.remoteAdd() .setName("origin") - .setUri(URIish("https://github.com/Github_USERNAME/Repo_NAME.git")) + .setUri(URIish("$repoUrl.git")) .call() git.push() - .setRemote("https://github.com/Github_USERNAME/Repo_NAME.git") + .setRemote("$repoUrl.git") .setTimeout(30) .setCredentialsProvider( - UsernamePasswordCredentialsProvider("HERE GOES GITHUB TOKEN", "") + UsernamePasswordCredentialsProvider(token, "") ) .call(); } @@ -335,12 +339,14 @@ object BackupUtils { fun FragmentActivity.restorePromptGithub(){ ioSafe { val tmpDir = createTempDir() + val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username") + val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") Git.cloneRepository() - .setURI("https://github.com/Github_USERNAME/Repo_NAME.git") + .setURI("$repoUrl.git") .setDirectory(tmpDir) .setTimeout(30) .setCredentialsProvider( - UsernamePasswordCredentialsProvider("", "") + UsernamePasswordCredentialsProvider("$token", "") ) .call() val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readLines() From e12efc13ffe85299700d1be8980682cb48f8ac01 Mon Sep 17 00:00:00 2001 From: Antony Date: Tue, 23 Aug 2022 18:54:22 +0200 Subject: [PATCH 06/33] Create new repo --- .../syncproviders/providers/GithubApi.kt | 89 ++++++++++++++++--- .../ui/settings/SettingsUpdates.kt | 2 +- .../cloudstream3/utils/BackupUtils.kt | 11 ++- 3 files changed, 85 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index c7c7e10b..316bd927 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -1,5 +1,6 @@ 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.setKey @@ -7,6 +8,19 @@ import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.syncproviders.AuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager +import com.lagradost.cloudstream3.utils.AppUtils.parseJson +import com.lagradost.cloudstream3.utils.AppUtils.toJson +import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import com.lagradost.cloudstream3.utils.Coroutines.ioSafe +import com.lagradost.nicehttp.RequestBodyTypes +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody.Companion.toRequestBody +import org.eclipse.jgit.api.Git +import org.eclipse.jgit.transport.URIish +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.attribute.FileAttribute class GithubApi(index: Int) : InAppAuthAPIManager(index){ @@ -14,11 +28,10 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ 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 user: String, + var repoUrl: String, var token: String ) companion object { @@ -28,14 +41,70 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ private fun getAuthKey(): GithubOAuthEntity? { return getKey(accountId, GITHUB_USER_KEY) } + private class repodata ( + @JsonProperty("full_name") val repoUrl: String + ) + + + 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(response.text).let { + setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoUrl?: run { + return false + })) + it.repoUrl + } + 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(); + return true + } + return false + } + override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { switchToNewAccount() - val repoUrl = data.username ?: throw IllegalArgumentException ("Requires Username") - val password = data.password ?: throw IllegalArgumentException ("Requires Password") + val githubToken = data.password ?: throw IllegalArgumentException ("Requires Password") try { - setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(repoUrl, password)) - registerAccount() - return true + if (initLogin(githubToken)) { + registerAccount() + return true + } } catch (e: Exception) { logError(e) switchToOldAccount() @@ -46,11 +115,11 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun getLatestLoginData(): InAppAuthAPI.LoginData? { val current = getAuthKey() ?: return null - return InAppAuthAPI.LoginData(username = current.user, password = current.token) + return InAppAuthAPI.LoginData(username = current.repoUrl, password = current.token) } override suspend fun initialize() { currentSession = getAuthKey() ?: return // just in case the following fails - setKey(currentSession!!.user, currentSession!!.token) + setKey(currentSession!!.repoUrl, currentSession!!.token) } override fun logOut() { AcraApplication.removeKey(accountId, GITHUB_USER_KEY) @@ -62,7 +131,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ getAuthKey()?.let { user -> return AuthAPI.LoginInfo( profilePicture = null, - name = user.user, + name = user.repoUrl, accountIndex = accountIndex, ) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 9cabd473..9700961b 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -42,7 +42,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { //val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext()) getPref(R.string.backup_key)?.setOnPreferenceClickListener { - activity?.BackupGithub() + activity?.backup() return@setOnPreferenceClickListener true } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 7257da58..5fcd5cf0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -303,28 +303,27 @@ object BackupUtils { val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") val git = Git.cloneRepository() - .setURI("$repoUrl.git") + .setURI("https://github.com/$repoUrl.git") .setDirectory(tmpDir) .setTimeout(30) .setCredentialsProvider( UsernamePasswordCredentialsProvider(token, "") ) .call() - tmpDir.listFiles()?.first { it.name != ".git" }?.writeText(backup.toJson()) git.add() .addFilepattern(".") .call() git.commit() .setAll(true) - .setMessage("Update results") + .setMessage("Update backup") .call() git.remoteAdd() .setName("origin") - .setUri(URIish("$repoUrl.git")) + .setUri(URIish("https://github.com/$repoUrl.git")) .call() git.push() - .setRemote("$repoUrl.git") + .setRemote("https://github.com/$repoUrl.git") .setTimeout(30) .setCredentialsProvider( UsernamePasswordCredentialsProvider(token, "") @@ -342,7 +341,7 @@ object BackupUtils { val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") Git.cloneRepository() - .setURI("$repoUrl.git") + .setURI("https://github.com/$repoUrl.git") .setDirectory(tmpDir) .setTimeout(30) .setCredentialsProvider( From 6ab90504f4a1a1ef7ec987fdd10a11ecc5d291e3 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Aug 2022 02:38:49 +0200 Subject: [PATCH 07/33] fixes --- .../syncproviders/providers/GithubApi.kt | 102 ++++++++++-------- .../cloudstream3/utils/BackupUtils.kt | 11 +- 2 files changed, 60 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 316bd927..86148a27 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -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,55 +47,61 @@ 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.delete() + } +private class repos{ + +} 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"), + "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) { - val repoUrl = tryParseJson(response.text).let { - setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( - token = githubToken, - repoUrl = it?.repoUrl?: run { - return false - })) - it.repoUrl - } - 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(); - return true + if (!response.isSuccessful) {return false} + + val repoUrl = tryParseJson(response.text).let { + setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoUrl?: run { + return false + })) + it.repoUrl } - return false + 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 } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 5fcd5cf0..363ca804 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -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(jsondata?: "") this@restorePromptGithub.restore( data, @@ -357,5 +357,4 @@ object BackupUtils { restoreDataStore = true ) } - } -} \ No newline at end of file +} From df54745294fc9539224174e9b32fe23da851ae45 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Aug 2022 02:42:41 +0200 Subject: [PATCH 08/33] fixes --- .../syncproviders/providers/GithubApi.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 86148a27..bea24033 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -78,10 +78,18 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ .call(); tmpDir.delete() } -private class repos{ + private class repos ( + @JsonProperty("full_name") var repoName: String + ) -} private suspend fun initLogin(githubToken: String): Boolean{ + val repoResponse = app.post("https://api.github.com/user/repos", + headers= mapOf( + "Accept" to "application/vnd.github+json", + "Authorization" to "token $githubToken" + ) + ) + val val response = app.post("https://api.github.com/user/repos", headers= mapOf( "Accept" to "application/vnd.github+json", From d9824b5b8ac91d1086efe9be251f92484cf4705e Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Aug 2022 02:48:13 +0200 Subject: [PATCH 09/33] fixes --- .../syncproviders/providers/GithubApi.kt | 62 +++++++++++++------ 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index bea24033..2189f6b8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -78,7 +78,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ .call(); tmpDir.delete() } - private class repos ( + private class reposElements ( @JsonProperty("full_name") var repoName: String ) @@ -89,27 +89,49 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ "Authorization" to "token $githubToken" ) ) - val - 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 (repoResponse.isSuccessful) { + val repo = tryParseJson>(repoResponse.text)?.filter { + it.repoName == "sync-data-for-Cloudstream" + } + if (repo?.isEmpty() == true) { + 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(response.text).let { - setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( - token = githubToken, - repoUrl = it?.repoUrl?: run { + if (!response.isSuccessful) { return false - })) - it.repoUrl - } - commitFile(repoUrl, githubToken) - return true + } + + val repoUrl = tryParseJson(response.text).let { + setKey( + accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoUrl ?: run { + return false + }) + ) + it.repoUrl + } + commitFile(repoUrl, githubToken) + return true + } + else{ + repo.first().let { { + setKey( + accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoName ?: run { + return false + }) + ) + } } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { From 98c85d7eb262f60248228b4cc4c67be1ad44a060 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Aug 2022 03:00:21 +0200 Subject: [PATCH 10/33] added check to previously made backups --- .../syncproviders/providers/GithubApi.kt | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 2189f6b8..bf66c86e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -79,59 +79,63 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ tmpDir.delete() } private class reposElements ( - @JsonProperty("full_name") var repoName: String + @JsonProperty("full_name") var repoName: String, + @JsonProperty("name") var shortRepoName: String + ) private suspend fun initLogin(githubToken: String): Boolean{ - val repoResponse = app.post("https://api.github.com/user/repos", + val repoResponse = app.get("https://api.github.com/user/repos", headers= mapOf( "Accept" to "application/vnd.github+json", "Authorization" to "token $githubToken" ) ) - if (repoResponse.isSuccessful) { - val repo = tryParseJson>(repoResponse.text)?.filter { - it.repoName == "sync-data-for-Cloudstream" - } - if (repo?.isEmpty() == true) { - 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 (!repoResponse.isSuccessful) { + return false + } + val repo = tryParseJson>(repoResponse.text)?.filter { + it.shortRepoName == "sync-data-for-Cloudstream" + } + if (repo?.isEmpty() == true) { + 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 - } + if (!response.isSuccessful) { + return false + } - val repoUrl = tryParseJson(response.text).let { - setKey( - accountId, GITHUB_USER_KEY, GithubOAuthEntity( - token = githubToken, - repoUrl = it?.repoUrl ?: run { - return false - }) - ) - it.repoUrl - } - commitFile(repoUrl, githubToken) + val repoUrl = tryParseJson(response.text).let { + setKey( + accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoUrl ?: run { + return false + }) + ) + it.repoUrl + } + commitFile(repoUrl, githubToken) + return true + } + else{ + repo?.first().let { + setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.repoName?: run { + return false + })) return true } - else{ - repo.first().let { { - setKey( - accountId, GITHUB_USER_KEY, GithubOAuthEntity( - token = githubToken, - repoUrl = it?.repoName ?: run { - return false - }) - ) - } + } } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { From c99c620e9803af513a4c7ab04796c2d6738feff9 Mon Sep 17 00:00:00 2001 From: antonydp <38143733+antonydp@users.noreply.github.com> Date: Wed, 24 Aug 2022 13:14:25 +0200 Subject: [PATCH 11/33] Update GithubApi.kt --- .../cloudstream3/syncproviders/providers/GithubApi.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index bf66c86e..12dc3bae 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -148,7 +148,6 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ } } catch (e: Exception) { logError(e) - switchToOldAccount() } switchToOldAccount() return false @@ -179,4 +178,4 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ ) } } -} \ No newline at end of file +} From bdb6d78f97e966802e0330a16ab484204700dad7 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 24 Aug 2022 22:49:08 +0200 Subject: [PATCH 12/33] added tmpDir.deleteRecursively() --- .../lagradost/cloudstream3/syncproviders/providers/GithubApi.kt | 2 +- .../main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index bf66c86e..73160db4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -76,7 +76,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ UsernamePasswordCredentialsProvider(githubToken, "") ) .call(); - tmpDir.delete() + tmpDir.deleteRecursively() } private class reposElements ( @JsonProperty("full_name") var repoName: String, diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 363ca804..01a807bf 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -330,6 +330,7 @@ object BackupUtils { UsernamePasswordCredentialsProvider(token, "") ) .call(); + tmpDir.deleteRecursively() } @@ -351,6 +352,7 @@ object BackupUtils { .call() val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readText().toString() val data = parseJson(jsondata?: "") + tmpDir.deleteRecursively() this@restorePromptGithub.restore( data, restoreSettings = true, From 409f8f743d2fa17b2e78f1d5808fc61432dd6d97 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 13:32:26 +0200 Subject: [PATCH 13/33] switch on gist.github --- .../syncproviders/providers/GithubApi.kt | 96 ++++++++++--------- .../cloudstream3/utils/BackupUtils.kt | 14 +-- 2 files changed, 57 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index bbce21e9..72701cdd 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -33,7 +33,9 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ data class GithubOAuthEntity( var repoUrl: String, - var token: String + var token: String, + var userName: String, + var userAvatar: String ) companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile @@ -42,9 +44,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ private fun getAuthKey(): GithubOAuthEntity? { return getKey(accountId, GITHUB_USER_KEY) } - private class repodata ( - @JsonProperty("full_name") val repoUrl: String - ) + private fun commitFile(repoUrl: String, githubToken: String){ @@ -78,66 +78,70 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ .call(); tmpDir.deleteRecursively() } - private class reposElements ( - @JsonProperty("full_name") var repoName: String, - @JsonProperty("name") var shortRepoName: String + private data class gistsElements ( + @JsonProperty("git_pull_url") val gitUrl: String, + @JsonProperty("files") val files: Map, + @JsonProperty("owner") val owner: OwnerData + ) + private data class OwnerData( + @JsonProperty("login") val userName: String, + @JsonProperty("avatar_url") val userAvatar : String + ) + data class File ( + @JsonProperty("filename") val filename: String ) private suspend fun initLogin(githubToken: String): Boolean{ - val repoResponse = app.get("https://api.github.com/user/repos", + val response = app.get("https://api.github.com/gists", headers= mapOf( - "Accept" to "application/vnd.github+json", - "Authorization" to "token $githubToken" + Pair("Accept" , "application/vnd.github+json"), + Pair("Authorization", "token $githubToken"), ) ) - if (!repoResponse.isSuccessful) { - return false + + if (!response.isSuccessful) { return false } + + val repo = tryParseJson>(response.text)?.filter { + it.files.keys.first() == "Cloudstream_Backup_data.txt" } - val repo = tryParseJson>(repoResponse.text)?.filter { - it.shortRepoName == "sync-data-for-Cloudstream" - } - if (repo?.isEmpty() == true) { - val response = app.post( - "https://api.github.com/user/repos", - headers = mapOf( - "Accept" to "application/vnd.github+json", - "Authorization" to "token $githubToken" + + if (repo?.isEmpty() == true){ + val gitresponse = app.post("https://api.github.com/gists", + 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) { - return false + requestBody = """{"description":"Cloudstream private backup gist","public":false,"files":{"Cloudstream_Backup_data.txt":{"content":"initialization"}}}""".toRequestBody( + RequestBodyTypes.JSON.toMediaTypeOrNull())) + if (!gitresponse.isSuccessful) {return false} + tryParseJson(gitresponse.text).let { + setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( + token = githubToken, + repoUrl = it?.gitUrl?: run { + return false + }, + userName = it.owner.userName, + userAvatar = it.owner.userAvatar + )) } - - val repoUrl = tryParseJson(response.text).let { - setKey( - accountId, GITHUB_USER_KEY, GithubOAuthEntity( - token = githubToken, - repoUrl = it?.repoUrl ?: run { - return false - }) - ) - it.repoUrl - } - commitFile(repoUrl, githubToken) return true } else{ repo?.first().let { setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( token = githubToken, - repoUrl = it?.repoName?: run { + repoUrl = it?.gitUrl?: run { return false - })) + }, + userName = it.owner.userName, + userAvatar = it.owner.userAvatar + )) return true } } - } + } override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { switchToNewAccount() val githubToken = data.password ?: throw IllegalArgumentException ("Requires Password") @@ -155,7 +159,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun getLatestLoginData(): InAppAuthAPI.LoginData? { val current = getAuthKey() ?: return null - return InAppAuthAPI.LoginData(username = current.repoUrl, password = current.token) + return InAppAuthAPI.LoginData(email = current.repoUrl, password = current.token, username = current.userName) } override suspend fun initialize() { currentSession = getAuthKey() @@ -172,8 +176,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun loginInfo(): AuthAPI.LoginInfo? { return getAuthKey()?.let { user -> AuthAPI.LoginInfo( - profilePicture = null, - name = user.repoUrl, + profilePicture = user.userAvatar, + name = user.userName, accountIndex = accountIndex, ) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 01a807bf..63ff071a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -301,10 +301,10 @@ object BackupUtils { val backup = this.getBackup() ioSafe { val tmpDir = createTempDir() - val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username") + val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") val git = Git.cloneRepository() - .setURI("https://github.com/$repoUrl.git") + .setURI(gitUrl) .setDirectory(tmpDir) .setTimeout(30) .setCredentialsProvider( @@ -321,10 +321,10 @@ object BackupUtils { .call() git.remoteAdd() .setName("origin") - .setUri(URIish("https://github.com/$repoUrl.git")) + .setUri(URIish(gitUrl)) .call() git.push() - .setRemote("https://github.com/$repoUrl.git") + .setRemote(gitUrl) .setTimeout(30) .setCredentialsProvider( UsernamePasswordCredentialsProvider(token, "") @@ -340,14 +340,14 @@ object BackupUtils { fun FragmentActivity.restorePromptGithub() = ioSafe { val tmpDir = createTempDir() - val repoUrl = githubApi.getLatestLoginData()?.username ?: throw IllegalArgumentException ("Requires Username") + val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") Git.cloneRepository() - .setURI("https://github.com/$repoUrl.git") + .setURI(gitUrl) .setDirectory(tmpDir) .setTimeout(30) .setCredentialsProvider( - UsernamePasswordCredentialsProvider("$token", "") + UsernamePasswordCredentialsProvider(token, "") ) .call() val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readText().toString() From 801d608beba30dc2ba3937deeb0f300a71e510dd Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 14:04:15 +0200 Subject: [PATCH 14/33] switch on gist.github --- .../syncproviders/providers/GithubApi.kt | 18 ++++++++----- .../cloudstream3/utils/BackupUtils.kt | 26 +++++-------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 72701cdd..dad84266 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -35,7 +35,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ var repoUrl: String, var token: String, var userName: String, - var userAvatar: String + var userAvatar: String, + var gistUrl: String ) companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile @@ -79,17 +80,18 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ tmpDir.deleteRecursively() } - private data class gistsElements ( + data class gistsElements ( @JsonProperty("git_pull_url") val gitUrl: String, + @JsonProperty("url") val gistUrl:String, @JsonProperty("files") val files: Map, @JsonProperty("owner") val owner: OwnerData ) - private data class OwnerData( + data class OwnerData( @JsonProperty("login") val userName: String, @JsonProperty("avatar_url") val userAvatar : String ) data class File ( - @JsonProperty("filename") val filename: String + @JsonProperty("raw_url") val rawUrl: String ) private suspend fun initLogin(githubToken: String): Boolean{ @@ -122,7 +124,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ return false }, userName = it.owner.userName, - userAvatar = it.owner.userAvatar + userAvatar = it.owner.userAvatar, + gistUrl = it.gistUrl )) } return true @@ -135,7 +138,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ return false }, userName = it.owner.userName, - userAvatar = it.owner.userAvatar + userAvatar = it.owner.userAvatar, + gistUrl = it.gistUrl )) return true } @@ -159,7 +163,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun getLatestLoginData(): InAppAuthAPI.LoginData? { 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() { currentSession = getAuthKey() diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 63ff071a..9ef6bde1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -13,6 +13,7 @@ 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.app import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.plugins.PLUGINS_KEY 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_UNIXTIME_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.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 @@ -54,7 +52,6 @@ import java.io.PrintWriter import java.lang.System.currentTimeMillis import java.text.SimpleDateFormat import java.util.* - object BackupUtils { /** @@ -297,7 +294,7 @@ object BackupUtils { } - fun FragmentActivity.BackupGithub(){ + fun FragmentActivity.backupGithub(){ val backup = this.getBackup() ioSafe { val tmpDir = createTempDir() @@ -339,20 +336,10 @@ object BackupUtils { fun FragmentActivity.restorePromptGithub() = ioSafe { - val tmpDir = createTempDir() - val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") - val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") - Git.cloneRepository() - .setURI(gitUrl) - .setDirectory(tmpDir) - .setTimeout(30) - .setCredentialsProvider( - UsernamePasswordCredentialsProvider(token, "") - ) - .call() - val jsondata = tmpDir.listFiles()?.first { it.name != ".git" }?.readText().toString() - val data = parseJson(jsondata?: "") - tmpDir.deleteRecursively() + val gitUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() + val jsondata = app.get(gitUrl).text + val dataurl = parseJson(jsondata ?: "").files.values.first().rawUrl + val data = parseJson(app.get(dataurl).text) this@restorePromptGithub.restore( data, restoreSettings = true, @@ -360,3 +347,4 @@ object BackupUtils { ) } } + From 8e5198753f367a027e8b6b239614edb18a89bbc1 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 14:15:26 +0200 Subject: [PATCH 15/33] switch on gist.github --- .../syncproviders/providers/GithubApi.kt | 35 +------------------ .../cloudstream3/utils/BackupUtils.kt | 8 ++--- 2 files changed, 5 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index dad84266..5acd8563 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -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{ diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 9ef6bde1..1e4686ad 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -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(jsondata ?: "").files.values.first().rawUrl - val data = parseJson(app.get(dataurl).text) + val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() + val jsondata = app.get(gistUrl).text + val dataraw = parseJson(jsondata ?: "").files.values.first().dataRaw + val data = parseJson(dataraw) this@restorePromptGithub.restore( data, restoreSettings = true, From 0e029cadef689f20e16e3a6887fad0506e7a50c4 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 14:17:29 +0200 Subject: [PATCH 16/33] switch on gist.github --- .../com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 9700961b..6b19042a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -15,7 +15,6 @@ import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar -import com.lagradost.cloudstream3.utils.BackupUtils.BackupGithub import com.lagradost.cloudstream3.utils.BackupUtils.backup import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt import com.lagradost.cloudstream3.utils.Coroutines.ioSafe From ff05ad897df3c1563e1df38add9daa3d0f8a329b Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 14:30:03 +0200 Subject: [PATCH 17/33] switch on gist.github --- .../lagradost/cloudstream3/syncproviders/providers/GithubApi.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 5acd8563..bcb892a3 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -58,7 +58,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ @JsonProperty("avatar_url") val userAvatar : String ) data class File ( - @JsonProperty("content") val dataRaw: String + @JsonProperty("content") val dataRaw: String? ) private suspend fun initLogin(githubToken: String): Boolean{ From be3f00d12665a87b50cb410129678761d5dd0430 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 14:32:03 +0200 Subject: [PATCH 18/33] switch on gist.github --- .../main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 1e4686ad..50466403 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -338,7 +338,7 @@ object BackupUtils { ioSafe { val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() val jsondata = app.get(gistUrl).text - val dataraw = parseJson(jsondata ?: "").files.values.first().dataRaw + val dataraw = parseJson(jsondata ?: "").files.values.first().dataRaw?: throw IllegalAccessException() val data = parseJson(dataraw) this@restorePromptGithub.restore( data, From 79833fafcbec8df5a951dc72311c7cb7569259f0 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 15:02:49 +0200 Subject: [PATCH 19/33] switch on gist.github --- .../java/com/lagradost/cloudstream3/utils/BackupUtils.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 50466403..a7770fef 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -329,9 +329,11 @@ object BackupUtils { .call(); tmpDir.deleteRecursively() } - - - + showToast( + this, + R.string.backup_success, + Toast.LENGTH_LONG + ) } fun FragmentActivity.restorePromptGithub() = From e15aba2d63d1bdd6b43d6233c766798b8ef4b663 Mon Sep 17 00:00:00 2001 From: Antony Date: Thu, 25 Aug 2022 15:45:08 +0200 Subject: [PATCH 20/33] createAccountUrl fix --- .../lagradost/cloudstream3/syncproviders/providers/GithubApi.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index bcb892a3..53669aca 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -29,7 +29,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override val name = "Github" override val icon = R.drawable.ic_github_logo override val requiresPassword = true - override val createAccountUrl = "https://github.com/settings/tokens/new" + override val createAccountUrl = "https://github.com/settings/tokens/new?description=Cloudstream+Backup&scopes=gist" data class GithubOAuthEntity( var repoUrl: String, From 100ff87b436798218de34d29d173f5e4275371dd Mon Sep 17 00:00:00 2001 From: Antony Date: Fri, 30 Sep 2022 21:31:52 +0200 Subject: [PATCH 21/33] createAccountUrl fix --- .../com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 6b19042a..3e9a5a57 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -28,6 +28,7 @@ import java.io.BufferedReader import java.io.InputStreamReader import java.io.OutputStream + class SettingsUpdates : PreferenceFragmentCompat() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) From 7ef9b18e00a698789cf2919e951ff277bad12192 Mon Sep 17 00:00:00 2001 From: Antony Date: Sat, 1 Oct 2022 18:37:16 +0200 Subject: [PATCH 22/33] onCreate, onDestroy --- .../java/com/lagradost/cloudstream3/MainActivity.kt | 13 +++++++++++++ .../syncproviders/providers/GithubApi.kt | 8 ++++++++ .../cloudstream3/ui/settings/SettingsUpdates.kt | 3 ++- app/src/main/res/values/strings.xml | 5 +++++ app/src/main/res/xml/settings_updates.xml | 8 ++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index cd320060..face4fae 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -50,6 +50,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.OAuth2A import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appString import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo +import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.githubApi import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.inAppAuths import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO @@ -64,6 +65,8 @@ import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable import com.lagradost.cloudstream3.utils.AppUtils.loadCache import com.lagradost.cloudstream3.utils.AppUtils.loadRepository import com.lagradost.cloudstream3.utils.AppUtils.loadResult +import com.lagradost.cloudstream3.utils.BackupUtils.backupGithub +import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getKey @@ -399,8 +402,14 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { override fun onDestroy() { val broadcastIntent = Intent() + val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) broadcastIntent.action = "restart_service" broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java) + + if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)) { + this@MainActivity.backupGithub() + } + this.sendBroadcast(broadcastIntent) afterPluginsLoadedEvent -= ::onAllPluginsLoaded super.onDestroy() @@ -585,6 +594,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { initAll() // No duplicates (which can happen by registerMainAPI) apis = allProviders.distinctBy { it } + + if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){ + this@MainActivity.restorePromptGithub() + } } // val navView: BottomNavigationView = findViewById(R.id.nav_view) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 53669aca..f03804cc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.syncproviders.providers +import androidx.fragment.app.FragmentActivity import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AcraApplication.Companion.getKey @@ -12,7 +13,9 @@ import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.Coroutines.ioSafe +import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread import com.lagradost.nicehttp.RequestBodyTypes import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody @@ -108,6 +111,11 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ userAvatar = it.owner.userAvatar, gistUrl = it.gistUrl )) + runOnMainThread { + FragmentActivity().restorePromptGithub() + } + + return true } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index 3e9a5a57..e95d7117 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -17,6 +17,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPadd import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar import com.lagradost.cloudstream3.utils.BackupUtils.backup import com.lagradost.cloudstream3.utils.BackupUtils.restorePrompt +import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.InAppUpdater.Companion.runAutoUpdate import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe @@ -52,7 +53,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { } getPref(R.string.restore_key)?.setOnPreferenceClickListener { - activity?.restorePrompt() + activity?.restorePromptGithub() return@setOnPreferenceClickListener true } getPref(R.string.show_logcat_key)?.setOnPreferenceClickListener { pref -> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f1f23f3..511ab7ee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -56,6 +56,7 @@ filter_sub_lang_key pref_filter_search_quality_key enable_nsfw_on_providers_key + automatic_cloud_backups %d %s | %s @@ -244,6 +245,10 @@ Automatically sync your current episode progress Restore data from backup + Automatic backup from Github + + Cloud Backup deactivated + Cloud Backup enabled Backup data Loaded backup file diff --git a/app/src/main/res/xml/settings_updates.xml b/app/src/main/res/xml/settings_updates.xml index eaceb785..f24cc7ca 100644 --- a/app/src/main/res/xml/settings_updates.xml +++ b/app/src/main/res/xml/settings_updates.xml @@ -17,6 +17,14 @@ android:key="@string/restore_key" android:title="@string/restore_settings" /> + + Date: Sat, 1 Oct 2022 18:57:48 +0200 Subject: [PATCH 23/33] onCreate, onDestroy fix --- .../lagradost/cloudstream3/MainActivity.kt | 3 ++- .../syncproviders/providers/GithubApi.kt | 5 ++-- .../cloudstream3/utils/BackupUtils.kt | 26 +++++++++---------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index face4fae..e6345f81 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -35,6 +35,7 @@ import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings import com.lagradost.cloudstream3.APIHolder.initAll import com.lagradost.cloudstream3.APIHolder.updateHasTrailers +import com.lagradost.cloudstream3.AcraApplication.Companion.context import com.lagradost.cloudstream3.CommonActivity.loadThemes import com.lagradost.cloudstream3.CommonActivity.onColorSelectedEvent import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent @@ -596,7 +597,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { apis = allProviders.distinctBy { it } if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)){ - this@MainActivity.restorePromptGithub() + context?.restorePromptGithub() } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index f03804cc..cda57f62 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.syncproviders.providers import androidx.fragment.app.FragmentActivity import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.AcraApplication.Companion.context import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey @@ -111,8 +112,8 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ userAvatar = it.owner.userAvatar, gistUrl = it.gistUrl )) - runOnMainThread { - FragmentActivity().restorePromptGithub() + ioSafe { + context?.restorePromptGithub() } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index a7770fef..04e32ad5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -335,18 +335,18 @@ object BackupUtils { Toast.LENGTH_LONG ) } - - fun FragmentActivity.restorePromptGithub() = - ioSafe { - val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() - val jsondata = app.get(gistUrl).text - val dataraw = parseJson(jsondata ?: "").files.values.first().dataRaw?: throw IllegalAccessException() - val data = parseJson(dataraw) - this@restorePromptGithub.restore( - data, - restoreSettings = true, - restoreDataStore = true - ) - } + suspend fun Context.restorePromptGithub() { + val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() + val jsondata = app.get(gistUrl).text + val dataraw = + parseJson(jsondata ?: "").files.values.first().dataRaw + ?: throw IllegalAccessException() + val data = parseJson(dataraw) + restore( + data, + restoreSettings = true, + restoreDataStore = true + ) + } } From fb99e929e7ce8db056bc53ad09067e6cffe61874 Mon Sep 17 00:00:00 2001 From: Antony Date: Sat, 1 Oct 2022 19:49:41 +0200 Subject: [PATCH 24/33] set back activity?.restorePrompt() in SettingsUpdates.kt --- .../com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt index e95d7117..824568d5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsUpdates.kt @@ -53,7 +53,7 @@ class SettingsUpdates : PreferenceFragmentCompat() { } getPref(R.string.restore_key)?.setOnPreferenceClickListener { - activity?.restorePromptGithub() + activity?.restorePrompt() return@setOnPreferenceClickListener true } getPref(R.string.show_logcat_key)?.setOnPreferenceClickListener { pref -> From 5be6422ced580cc5e3e0f29edf0ad3b58b705e8d Mon Sep 17 00:00:00 2001 From: Antony Date: Tue, 11 Oct 2022 18:16:48 +0200 Subject: [PATCH 25/33] use gist api to push backup informations --- app/build.gradle | 2 - .../syncproviders/providers/GithubApi.kt | 53 ++++++++++--------- .../cloudstream3/utils/BackupUtils.kt | 31 ++++++++--- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 32f417b2..9d869e48 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -200,8 +200,6 @@ 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) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index cda57f62..964f0e2e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -1,6 +1,5 @@ package com.lagradost.cloudstream3.syncproviders.providers -import androidx.fragment.app.FragmentActivity import com.fasterxml.jackson.annotation.JsonProperty import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AcraApplication.Companion.context @@ -11,21 +10,14 @@ import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.syncproviders.AuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager -import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson +import com.lagradost.cloudstream3.utils.BackupUtils.getBackup import com.lagradost.cloudstream3.utils.BackupUtils.restorePromptGithub import com.lagradost.cloudstream3.utils.Coroutines.ioSafe -import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread import com.lagradost.nicehttp.RequestBodyTypes import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody.Companion.toRequestBody -import org.eclipse.jgit.api.Git -import org.eclipse.jgit.transport.URIish -import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.attribute.FileAttribute class GithubApi(index: Int) : InAppAuthAPIManager(index){ @@ -36,11 +28,10 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override val createAccountUrl = "https://github.com/settings/tokens/new?description=Cloudstream+Backup&scopes=gist" data class GithubOAuthEntity( - var repoUrl: String, + var gistId: String, var token: String, var userName: String, var userAvatar: String, - var gistUrl: String ) companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile @@ -52,8 +43,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ data class gistsElements ( - @JsonProperty("git_pull_url") val gitUrl: String, - @JsonProperty("url") val gistUrl:String, + @JsonProperty("id") val gistId:String, @JsonProperty("files") val files: Map, @JsonProperty("owner") val owner: OwnerData ) @@ -64,6 +54,17 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ data class File ( @JsonProperty("content") val dataRaw: String? ) + data class GistRequestBody( + @JsonProperty("description") val description: String, + @JsonProperty("public") val public : Boolean, + @JsonProperty("files") val files: FilesGist? + ) + data class FilesGist( + @JsonProperty("Cloudstream_Backup_data.txt") val description: ContentFilesGist?, + ) + data class ContentFilesGist( + @JsonProperty("content") val description: String?, + ) private suspend fun initLogin(githubToken: String): Boolean{ val response = app.get("https://api.github.com/gists", @@ -80,23 +81,28 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ } if (repo?.isEmpty() == true){ + val backupData = context?.getBackup() val gitresponse = app.post("https://api.github.com/gists", headers= mapOf( Pair("Accept" , "application/vnd.github+json"), Pair("Authorization", "token $githubToken"), ), - requestBody = """{"description":"Cloudstream private backup gist","public":false,"files":{"Cloudstream_Backup_data.txt":{"content":"initialization"}}}""".toRequestBody( + requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody( RequestBodyTypes.JSON.toMediaTypeOrNull())) + /* + """{"description":"Cloudstream private backup gist","public":false,"files":{"Cloudstream_Backup_data.txt":{"content":"initialization"}}}""".toRequestBody( + RequestBodyTypes.JSON.toMediaTypeOrNull())) + + */ if (!gitresponse.isSuccessful) {return false} tryParseJson(gitresponse.text).let { setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( token = githubToken, - repoUrl = it?.gitUrl?: run { + gistId = it?.gistId?: run { return false }, userName = it.owner.userName, - userAvatar = it.owner.userAvatar, - gistUrl = it.gistUrl + userAvatar = it.owner.userAvatar )) } return true @@ -105,18 +111,15 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ repo?.first().let { setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( token = githubToken, - repoUrl = it?.gitUrl?: run { + gistId = it?.gistId?: run { return false }, userName = it.owner.userName, - userAvatar = it.owner.userAvatar, - gistUrl = it.gistUrl + userAvatar = it.owner.userAvatar )) ioSafe { context?.restorePromptGithub() } - - return true } } @@ -139,13 +142,13 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ override fun getLatestLoginData(): InAppAuthAPI.LoginData? { val current = getAuthKey() ?: return null - return InAppAuthAPI.LoginData(email = current.repoUrl, password = current.token, username = current.userName, server = current.gistUrl) + return InAppAuthAPI.LoginData(server = current.gistId, password = current.token, username = current.userName) } override suspend fun initialize() { currentSession = getAuthKey() - val repoUrl = currentSession?.repoUrl ?: return + val gistId = currentSession?.gistId ?: return val token = currentSession?.token ?: return - setKey(repoUrl, token) + setKey(gistId, token) } override fun logOut() { removeKey(accountId, GITHUB_USER_KEY) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 04e32ad5..bf3a45ee 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -34,6 +34,7 @@ import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_U 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.toJson +import com.lagradost.cloudstream3.utils.BackupUtils.getBackup import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs @@ -44,9 +45,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 com.lagradost.nicehttp.RequestBodyTypes +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.RequestBody.Companion.toRequestBody import java.io.IOException import java.io.PrintWriter import java.lang.System.currentTimeMillis @@ -296,7 +297,10 @@ object BackupUtils { fun FragmentActivity.backupGithub(){ val backup = this.getBackup() - ioSafe { + + val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username") + val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") + /* ioSafe { val tmpDir = createTempDir() val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") @@ -328,6 +332,21 @@ object BackupUtils { ) .call(); tmpDir.deleteRecursively() + } + */ + ioSafe { + app.patch("https://api.github.com/gists/$gistId", + headers= mapOf( + Pair("Accept" , "application/vnd.github+json"), + Pair("Authorization", "token $token"), + ), + requestBody = GithubApi.GistRequestBody( + "Cloudstream private backup gist", + false, + GithubApi.FilesGist(GithubApi.ContentFilesGist(backup.toJson()))) + .toJson() + .toRequestBody(RequestBodyTypes.JSON.toMediaTypeOrNull()) + ) } showToast( this, @@ -336,8 +355,8 @@ object BackupUtils { ) } suspend fun Context.restorePromptGithub() { - val gistUrl = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() - val jsondata = app.get(gistUrl).text + val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() + val jsondata = app.get(" https://api.github.com/gists/$gistId").text val dataraw = parseJson(jsondata ?: "").files.values.first().dataRaw ?: throw IllegalAccessException() From 22a04bafd26224fc025d3e2ed20068d7bd1315a7 Mon Sep 17 00:00:00 2001 From: Antony Date: Tue, 11 Oct 2022 18:23:13 +0200 Subject: [PATCH 26/33] removed unnecessary comments --- app/build.gradle | 1 - .../syncproviders/providers/GithubApi.kt | 14 +++---- .../cloudstream3/utils/BackupUtils.kt | 38 +------------------ 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9d869e48..291e71ff 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -199,7 +199,6 @@ dependencies { // Library/extensions searching with Levenshtein distance implementation 'me.xdrop:fuzzywuzzy:1.4.0' - } task androidSourcesJar(type: Jar) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt index 964f0e2e..42bf2b02 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/GithubApi.kt @@ -33,16 +33,17 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ var userName: String, var userAvatar: String, ) + companion object { const val GITHUB_USER_KEY: String = "github_user" // user data like profile var currentSession: GithubOAuthEntity? = null } + private fun getAuthKey(): GithubOAuthEntity? { return getKey(accountId, GITHUB_USER_KEY) } - - data class gistsElements ( + data class GistsElements ( @JsonProperty("id") val gistId:String, @JsonProperty("files") val files: Map, @JsonProperty("owner") val owner: OwnerData @@ -54,6 +55,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ data class File ( @JsonProperty("content") val dataRaw: String? ) + data class GistRequestBody( @JsonProperty("description") val description: String, @JsonProperty("public") val public : Boolean, @@ -76,7 +78,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ if (!response.isSuccessful) { return false } - val repo = tryParseJson>(response.text)?.filter { + val repo = tryParseJson>(response.text)?.filter { it.files.keys.first() == "Cloudstream_Backup_data.txt" } @@ -89,13 +91,9 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){ ), requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody( RequestBodyTypes.JSON.toMediaTypeOrNull())) - /* - """{"description":"Cloudstream private backup gist","public":false,"files":{"Cloudstream_Backup_data.txt":{"content":"initialization"}}}""".toRequestBody( - RequestBodyTypes.JSON.toMediaTypeOrNull())) - */ if (!gitresponse.isSuccessful) {return false} - tryParseJson(gitresponse.text).let { + tryParseJson(gitresponse.text).let { setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( token = githubToken, gistId = it?.gistId?: run { diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index bf3a45ee..a8ff94f6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -34,7 +34,6 @@ import com.lagradost.cloudstream3.syncproviders.providers.MALApi.Companion.MAL_U 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.toJson -import com.lagradost.cloudstream3.utils.BackupUtils.getBackup import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs @@ -300,40 +299,7 @@ object BackupUtils { val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") - /* ioSafe { - val tmpDir = createTempDir() - val gitUrl = githubApi.getLatestLoginData()?.email ?: throw IllegalArgumentException ("Requires Username") - val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") - val git = Git.cloneRepository() - .setURI(gitUrl) - .setDirectory(tmpDir) - .setTimeout(30) - .setCredentialsProvider( - UsernamePasswordCredentialsProvider(token, "") - ) - .call() - tmpDir.listFiles()?.first { it.name != ".git" }?.writeText(backup.toJson()) - git.add() - .addFilepattern(".") - .call() - git.commit() - .setAll(true) - .setMessage("Update backup") - .call() - git.remoteAdd() - .setName("origin") - .setUri(URIish(gitUrl)) - .call() - git.push() - .setRemote(gitUrl) - .setTimeout(30) - .setCredentialsProvider( - UsernamePasswordCredentialsProvider(token, "") - ) - .call(); - tmpDir.deleteRecursively() - } - */ + ioSafe { app.patch("https://api.github.com/gists/$gistId", headers= mapOf( @@ -358,7 +324,7 @@ object BackupUtils { val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() val jsondata = app.get(" https://api.github.com/gists/$gistId").text val dataraw = - parseJson(jsondata ?: "").files.values.first().dataRaw + parseJson(jsondata ?: "").files.values.first().dataRaw ?: throw IllegalAccessException() val data = parseJson(dataraw) restore( From 28307ed9fc1f8abcfeac22fb8685784a50d9be55 Mon Sep 17 00:00:00 2001 From: Antony Date: Tue, 11 Oct 2022 19:04:42 +0200 Subject: [PATCH 27/33] placed backupGithub on onPause --- .../java/com/lagradost/cloudstream3/MainActivity.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index b1763966..a281b0a4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -384,6 +384,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { } catch (e: Exception) { logError(e) } + val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) + if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)) { + this@MainActivity.backupGithub() + } } @@ -425,14 +429,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { override fun onDestroy() { val broadcastIntent = Intent() - val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) broadcastIntent.action = "restart_service" broadcastIntent.setClass(this, VideoDownloadRestartReceiver::class.java) - - if (githubApi.getLatestLoginData() != null && settingsManager.getBoolean(getString(R.string.automatic_cloud_backups), false)) { - this@MainActivity.backupGithub() - } - this.sendBroadcast(broadcastIntent) afterPluginsLoadedEvent -= ::onAllPluginsLoaded super.onDestroy() From 9d733eed40c4731e96ef39595f55dc8783be5395 Mon Sep 17 00:00:00 2001 From: antonydp <38143733+antonydp@users.noreply.github.com> Date: Mon, 31 Oct 2022 09:27:27 +0100 Subject: [PATCH 28/33] update --- .github/workflows/issue_action.yml | 4 +- .github/workflows/prerelease.yml | 4 +- .github/workflows/pull_request.yml | 4 +- .idea/jarRepositories.xml | 5 + README.md | 1 + app/build.gradle | 233 ----- app/build.gradle.kts | 250 +++++ app/proguard-rules.pro | 2 +- .../cloudstream3/ExampleInstrumentedTest.kt | 4 +- app/src/main/AndroidManifest.xml | 5 +- .../com/lagradost/cloudstream3/MainAPI.kt | 2 +- .../lagradost/cloudstream3/MainActivity.kt | 2 +- .../lagradost/cloudstream3/ParCollections.kt | 24 +- .../cloudstream3/extractors/Fastream.kt | 6 +- .../cloudstream3/extractors/Gdriveplayer.kt | 55 +- .../cloudstream3/extractors/Moviehab.kt | 40 + .../cloudstream3/extractors/Pelisplus.kt | 10 +- .../cloudstream3/extractors/SpeedoStream.kt | 6 +- .../cloudstream3/extractors/StreamSB.kt | 20 +- .../extractors/VidSrcExtractor.kt | 14 +- .../cloudstream3/extractors/Vidstream.kt | 10 +- .../cloudstream3/extractors/XStreamCdn.kt | 64 +- .../cloudstream3/extractors/Zplayer.kt | 4 +- .../extractors/helper/AsianEmbedHelper.kt | 4 +- .../metaproviders/CrossTmdbProvider.kt | 6 +- .../metaproviders/MultiAnimeProvider.kt | 2 +- .../cloudstream3/network/WebViewResolver.kt | 37 +- .../cloudstream3/plugins/PluginManager.kt | 21 +- .../cloudstream3/plugins/RepositoryManager.kt | 4 +- .../cloudstream3/ui/APIRepository.kt | 36 +- .../lagradost/cloudstream3/ui/WatchType.kt | 13 +- .../cloudstream3/ui/home/HomeFragment.kt | 302 ++++--- .../cloudstream3/ui/home/HomeScrollAdapter.kt | 60 ++ .../ui/home/HomeScrollTransformer.kt | 13 + .../cloudstream3/ui/home/HomeViewModel.kt | 80 +- .../cloudstream3/ui/player/CS3IPlayer.kt | 16 +- .../cloudstream3/ui/player/GeneratorPlayer.kt | 2 +- .../cloudstream3/ui/player/LinkGenerator.kt | 4 +- .../cloudstream3/ui/result/ResultFragment.kt | 35 +- .../ui/result/ResultFragmentPhone.kt | 18 +- .../ui/result/ResultViewModel2.kt | 49 +- .../cloudstream3/ui/result/SyncViewModel.kt | 4 +- .../cloudstream3/ui/search/SearchFragment.kt | 275 +++--- .../cloudstream3/ui/search/SearchViewModel.kt | 6 +- .../ui/settings/SettingsGeneral.kt | 1 + .../extensions/ExtensionsViewModel.kt | 4 +- .../ui/settings/extensions/PluginsFragment.kt | 59 +- .../settings/extensions/PluginsViewModel.kt | 4 +- .../cloudstream3/utils/BackupUtils.kt | 4 +- .../cloudstream3/utils/ExtractorApi.kt | 6 + app/src/main/res/color/chip_color.xml | 5 + app/src/main/res/color/chip_color_text.xml | 5 + app/src/main/res/drawable/home_alt.xml | 9 + .../main/res/drawable/ic_baseline_add_24.xml | 13 +- .../drawable/ic_baseline_arrow_back_24.xml | 13 +- .../drawable/ic_baseline_arrow_forward_24.xml | 13 +- .../res/drawable/ic_baseline_bookmark_24.xml | 11 +- .../ic_baseline_delete_outline_24.xml | 16 +- .../drawable/ic_baseline_filter_list_24.xml | 13 +- .../ic_baseline_keyboard_arrow_down_24.xml | 13 +- .../main/res/drawable/ic_baseline_tune_24.xml | 11 +- app/src/main/res/drawable/search_icon.xml | 30 +- app/src/main/res/drawable/settings_alt.xml | 9 + .../main/res/drawable/storage_bar_left.xml | 7 + .../res/drawable/storage_bar_left_box.xml | 5 + app/src/main/res/drawable/storage_bar_mid.xml | 4 + .../main/res/drawable/storage_bar_mid_box.xml | 5 + .../main/res/drawable/storage_bar_right.xml | 7 + .../res/drawable/storage_bar_right_box.xml | 5 + app/src/main/res/layout/activity_main.xml | 118 +-- .../main/res/layout/fragment_downloads.xml | 257 +++--- .../main/res/layout/fragment_extensions.xml | 116 +-- app/src/main/res/layout/fragment_home.xml | 852 ++++++++++-------- app/src/main/res/layout/fragment_home_tv.xml | 80 +- app/src/main/res/layout/fragment_plugins.xml | 103 +-- app/src/main/res/layout/fragment_result.xml | 9 +- .../main/res/layout/fragment_result_tv.xml | 2 +- app/src/main/res/layout/fragment_search.xml | 81 +- .../main/res/layout/home_select_mainpage.xml | 156 +--- app/src/main/res/layout/tvtypes_chips.xml | 68 ++ .../main/res/layout/tvtypes_chips_scroll.xml | 10 + app/src/main/res/menu/bottom_nav_menu.xml | 4 +- app/src/main/res/values-bg/strings.xml | 533 +++++++++++ app/src/main/res/values/colors.xml | 3 + app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/styles.xml | 43 +- .../lagradost/cloudstream3/ProviderTests.kt | 4 +- build.gradle | 27 - build.gradle.kts | 26 + gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 - settings.gradle.kts | 3 + 92 files changed, 2715 insertions(+), 1815 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts create mode 100644 app/src/main/java/com/lagradost/cloudstream3/extractors/Moviehab.kt create mode 100644 app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeScrollAdapter.kt create mode 100644 app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeScrollTransformer.kt create mode 100644 app/src/main/res/color/chip_color.xml create mode 100644 app/src/main/res/color/chip_color_text.xml create mode 100644 app/src/main/res/drawable/home_alt.xml create mode 100644 app/src/main/res/drawable/settings_alt.xml create mode 100644 app/src/main/res/drawable/storage_bar_left.xml create mode 100644 app/src/main/res/drawable/storage_bar_left_box.xml create mode 100644 app/src/main/res/drawable/storage_bar_mid.xml create mode 100644 app/src/main/res/drawable/storage_bar_mid_box.xml create mode 100644 app/src/main/res/drawable/storage_bar_right.xml create mode 100644 app/src/main/res/drawable/storage_bar_right_box.xml create mode 100644 app/src/main/res/layout/tvtypes_chips.xml create mode 100644 app/src/main/res/layout/tvtypes_chips_scroll.xml create mode 100644 app/src/main/res/values-bg/strings.xml delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts diff --git a/.github/workflows/issue_action.yml b/.github/workflows/issue_action.yml index 79e7766c..28b737b3 100644 --- a/.github/workflows/issue_action.yml +++ b/.github/workflows/issue_action.yml @@ -18,7 +18,7 @@ jobs: uses: actions-cool/issues-similarity-analysis@v1 with: token: ${{ steps.generate_token.outputs.token }} - filter-threshold: 0.5 + filter-threshold: 0.60 title-excludes: '' comment-title: | ### Your issue looks similar to these issues: @@ -41,7 +41,7 @@ jobs: wget --output-document check_issue.py "https://raw.githubusercontent.com/recloudstream/.github/master/.github/check_issue.py" pip3 install httpx RES="$(python3 ./check_issue.py)" - echo "::set-output name=name::${RES}" + echo "name=${RES}" >> $GITHUB_OUTPUT - name: Comment if issue mentions a provider if: steps.provider_check.outputs.name != 'none' uses: actions-cool/issues-helper@v3 diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 37161d6b..4ce7dba1 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -40,7 +40,7 @@ jobs: curl -H "Authorization: token ${{ steps.generate_token.outputs.token }}" -o "keystore_password.txt" "https://raw.githubusercontent.com/recloudstream/secrets/master/keystore_password.txt" KEY_PWD="$(cat keystore_password.txt)" echo "::add-mask::${KEY_PWD}" - echo "::set-output name=key_pwd::$KEY_PWD" + echo "key_pwd=$KEY_PWD" >> $GITHUB_OUTPUT - name: Run Gradle run: | ./gradlew assemblePrerelease makeJar androidSourcesJar @@ -56,6 +56,6 @@ jobs: prerelease: true title: "Pre-release Build" files: | - app/build/outputs/apk/prerelease/*.apk + app/build/outputs/apk/prerelease/release/*.apk app/build/libs/app-sources.jar app/build/classes.jar diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 1a4db134..36199cd6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -15,9 +15,9 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Run Gradle - run: ./gradlew assembleDebug + run: ./gradlew assemblePrereleaseDebug - name: Upload Artifact uses: actions/upload-artifact@v2 with: name: pull-request-build - path: "app/build/outputs/apk/debug/*.apk" + path: "app/build/outputs/apk/prerelease/debug/*.apk" diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index 652d9f3f..333d4937 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -31,5 +31,10 @@