|  | @@ -1,43 +1,29 @@
 | 
	
		
			
				|  |  |  package eu.kanade.tachiyomi.extension.api
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import android.content.Context
 | 
	
		
			
				|  |  | -import com.github.salomonbrys.kotson.fromJson
 | 
	
		
			
				|  |  |  import com.github.salomonbrys.kotson.get
 | 
	
		
			
				|  |  |  import com.github.salomonbrys.kotson.int
 | 
	
		
			
				|  |  |  import com.github.salomonbrys.kotson.string
 | 
	
		
			
				|  |  | -import com.google.gson.Gson
 | 
	
		
			
				|  |  |  import com.google.gson.JsonArray
 | 
	
		
			
				|  |  |  import eu.kanade.tachiyomi.data.preference.PreferencesHelper
 | 
	
		
			
				|  |  |  import eu.kanade.tachiyomi.extension.model.Extension
 | 
	
		
			
				|  |  |  import eu.kanade.tachiyomi.extension.model.LoadResult
 | 
	
		
			
				|  |  |  import eu.kanade.tachiyomi.extension.util.ExtensionLoader
 | 
	
		
			
				|  |  | -import eu.kanade.tachiyomi.network.GET
 | 
	
		
			
				|  |  | -import eu.kanade.tachiyomi.network.NetworkHelper
 | 
	
		
			
				|  |  | -import eu.kanade.tachiyomi.network.await
 | 
	
		
			
				|  |  |  import java.util.Date
 | 
	
		
			
				|  |  |  import kotlinx.coroutines.Dispatchers
 | 
	
		
			
				|  |  |  import kotlinx.coroutines.withContext
 | 
	
		
			
				|  |  | -import okhttp3.Response
 | 
	
		
			
				|  |  |  import uy.kohesive.injekt.injectLazy
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  internal class ExtensionGithubApi {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private val network: NetworkHelper by injectLazy()
 | 
	
		
			
				|  |  |      private val preferences: PreferencesHelper by injectLazy()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private val gson: Gson by injectLazy()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      suspend fun findExtensions(): List<Extension.Available> {
 | 
	
		
			
				|  |  | -        val call = GET(EXT_URL)
 | 
	
		
			
				|  |  | +        val service: ExtensionGithubService = ExtensionGithubService.create()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return withContext(Dispatchers.IO) {
 | 
	
		
			
				|  |  | -            val response = network.client.newCall(call).await()
 | 
	
		
			
				|  |  | -            if (response.isSuccessful) {
 | 
	
		
			
				|  |  | -                parseResponse(response)
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                response.close()
 | 
	
		
			
				|  |  | -                throw Exception("Failed to get extensions")
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            val response = service.getRepo()
 | 
	
		
			
				|  |  | +            parseResponse(response)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -64,11 +50,7 @@ internal class ExtensionGithubApi {
 | 
	
		
			
				|  |  |          return extensionsWithUpdate
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private fun parseResponse(response: Response): List<Extension.Available> {
 | 
	
		
			
				|  |  | -        val text = response.body?.use { it.string() } ?: return emptyList()
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        val json = gson.fromJson<JsonArray>(text)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    private fun parseResponse(json: JsonArray): List<Extension.Available> {
 | 
	
		
			
				|  |  |          return json
 | 
	
		
			
				|  |  |              .filter { element ->
 | 
	
		
			
				|  |  |                  val versionName = element["version"].string
 | 
	
	
		
			
				|  | @@ -82,18 +64,18 @@ internal class ExtensionGithubApi {
 | 
	
		
			
				|  |  |                  val versionName = element["version"].string
 | 
	
		
			
				|  |  |                  val versionCode = element["code"].int
 | 
	
		
			
				|  |  |                  val lang = element["lang"].string
 | 
	
		
			
				|  |  | -                val icon = "$REPO_URL/icon/${apkName.replace(".apk", ".png")}"
 | 
	
		
			
				|  |  | +                val icon = "$REPO_URL_PREFIX/icon/${apkName.replace(".apk", ".png")}"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  Extension.Available(name, pkgName, versionName, versionCode, lang, apkName, icon)
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      fun getApkUrl(extension: Extension.Available): String {
 | 
	
		
			
				|  |  | -        return "$REPO_URL/apk/${extension.apkName}"
 | 
	
		
			
				|  |  | +        return "$REPO_URL_PREFIX/apk/${extension.apkName}"
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      companion object {
 | 
	
		
			
				|  |  | -        private const val REPO_URL = "https://raw.githubusercontent.com/inorichi/tachiyomi-extensions/repo"
 | 
	
		
			
				|  |  | -        private const val EXT_URL = "$REPO_URL/index.json"
 | 
	
		
			
				|  |  | +        const val BASE_URL = "https://raw.githubusercontent.com/"
 | 
	
		
			
				|  |  | +        private const val REPO_URL_PREFIX = "${BASE_URL}inorichi/tachiyomi-extensions/repo/"
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |