removed unnecessary comments

This commit is contained in:
Antony 2022-10-11 18:23:13 +02:00
parent e4ed0d4fcb
commit 22a04bafd2
3 changed files with 8 additions and 45 deletions

View file

@ -199,7 +199,6 @@ dependencies {
// Library/extensions searching with Levenshtein distance // Library/extensions searching with Levenshtein distance
implementation 'me.xdrop:fuzzywuzzy:1.4.0' implementation 'me.xdrop:fuzzywuzzy:1.4.0'
} }
task androidSourcesJar(type: Jar) { task androidSourcesJar(type: Jar) {

View file

@ -33,16 +33,17 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
var userName: String, var userName: String,
var userAvatar: String, var userAvatar: String,
) )
companion object { companion object {
const val GITHUB_USER_KEY: String = "github_user" // user data like profile const val GITHUB_USER_KEY: String = "github_user" // user data like profile
var currentSession: GithubOAuthEntity? = null var currentSession: GithubOAuthEntity? = null
} }
private fun getAuthKey(): GithubOAuthEntity? { private fun getAuthKey(): GithubOAuthEntity? {
return getKey(accountId, GITHUB_USER_KEY) return getKey(accountId, GITHUB_USER_KEY)
} }
data class GistsElements (
data class gistsElements (
@JsonProperty("id") val gistId:String, @JsonProperty("id") val gistId:String,
@JsonProperty("files") val files: Map<String, File>, @JsonProperty("files") val files: Map<String, File>,
@JsonProperty("owner") val owner: OwnerData @JsonProperty("owner") val owner: OwnerData
@ -54,6 +55,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
data class File ( data class File (
@JsonProperty("content") val dataRaw: String? @JsonProperty("content") val dataRaw: String?
) )
data class GistRequestBody( data class GistRequestBody(
@JsonProperty("description") val description: String, @JsonProperty("description") val description: String,
@JsonProperty("public") val public : Boolean, @JsonProperty("public") val public : Boolean,
@ -76,7 +78,7 @@ class GithubApi(index: Int) : InAppAuthAPIManager(index){
if (!response.isSuccessful) { return false } if (!response.isSuccessful) { return false }
val repo = tryParseJson<List<gistsElements>>(response.text)?.filter { val repo = tryParseJson<List<GistsElements>>(response.text)?.filter {
it.files.keys.first() == "Cloudstream_Backup_data.txt" 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( requestBody = GistRequestBody("Cloudstream private backup gist", false, FilesGist(ContentFilesGist(backupData?.toJson()))).toJson().toRequestBody(
RequestBodyTypes.JSON.toMediaTypeOrNull())) 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} if (!gitresponse.isSuccessful) {return false}
tryParseJson<gistsElements>(gitresponse.text).let { tryParseJson<GistsElements>(gitresponse.text).let {
setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity( setKey(accountId, GITHUB_USER_KEY, GithubOAuthEntity(
token = githubToken, token = githubToken,
gistId = it?.gistId?: run { gistId = it?.gistId?: run {

View file

@ -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.syncproviders.providers.OpenSubtitlesApi.Companion.OPEN_SUBTITLES_USER_KEY
import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.parseJson
import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.BackupUtils.getBackup
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs import com.lagradost.cloudstream3.utils.DataStore.getDefaultSharedPrefs
@ -300,40 +299,7 @@ object BackupUtils {
val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username") val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalArgumentException ("Requires Username")
val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username") val token = githubApi.getLatestLoginData()?.password ?: throw IllegalArgumentException ("Requires Username")
/* 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 { ioSafe {
app.patch("https://api.github.com/gists/$gistId", app.patch("https://api.github.com/gists/$gistId",
headers= mapOf( headers= mapOf(
@ -358,7 +324,7 @@ object BackupUtils {
val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException() val gistId = githubApi.getLatestLoginData()?.server ?: throw IllegalAccessException()
val jsondata = app.get(" https://api.github.com/gists/$gistId").text val jsondata = app.get(" https://api.github.com/gists/$gistId").text
val dataraw = val dataraw =
parseJson<GithubApi.gistsElements>(jsondata ?: "").files.values.first().dataRaw parseJson<GithubApi.GistsElements>(jsondata ?: "").files.values.first().dataRaw
?: throw IllegalAccessException() ?: throw IllegalAccessException()
val data = parseJson<BackupFile>(dataraw) val data = parseJson<BackupFile>(dataraw)
restore( restore(