You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Switch to new repo format
This commit is contained in:
@@ -6,7 +6,7 @@ import com.topjohnwu.magisk.core.model.module.Repo
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Database(version = 6, entities = [Repo::class, RepoEtag::class], exportSchema = false)
|
||||
@Database(version = 7, entities = [Repo::class], exportSchema = false)
|
||||
abstract class RepoDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun repoDao() : RepoDao
|
||||
@@ -17,17 +17,11 @@ abstract class RepoDatabase : RoomDatabase() {
|
||||
@Dao
|
||||
abstract class RepoDao(private val db: RepoDatabase) {
|
||||
|
||||
val repoIDList get() = getRepoID().map { it.id }
|
||||
|
||||
val repos: List<Repo> get() = when (Config.repoOrder) {
|
||||
Config.Value.ORDER_NAME -> getReposNameOrder()
|
||||
else -> getReposDateOrder()
|
||||
}
|
||||
|
||||
var etagKey: String
|
||||
set(value) = addEtagRaw(RepoEtag(0, value))
|
||||
get() = etagRaw()?.key.orEmpty()
|
||||
|
||||
suspend fun clear() = withContext(Dispatchers.IO) { db.clearAllTables() }
|
||||
|
||||
@Query("SELECT * FROM repos ORDER BY last_update DESC")
|
||||
@@ -42,8 +36,8 @@ abstract class RepoDao(private val db: RepoDatabase) {
|
||||
@Query("SELECT * FROM repos WHERE id = :id")
|
||||
abstract fun getRepo(id: String): Repo?
|
||||
|
||||
@Query("SELECT id FROM repos")
|
||||
protected abstract fun getRepoID(): List<RepoID>
|
||||
@Query("SELECT id, last_update FROM repos")
|
||||
abstract fun getRepoStubs(): List<RepoStub>
|
||||
|
||||
@Delete
|
||||
abstract fun removeRepo(repo: Repo)
|
||||
@@ -53,21 +47,9 @@ abstract class RepoDao(private val db: RepoDatabase) {
|
||||
|
||||
@Query("DELETE FROM repos WHERE id IN (:idList)")
|
||||
abstract fun removeRepos(idList: Collection<String>)
|
||||
|
||||
@Query("SELECT * FROM etag")
|
||||
protected abstract fun etagRaw(): RepoEtag?
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
protected abstract fun addEtagRaw(etag: RepoEtag)
|
||||
}
|
||||
|
||||
data class RepoID(
|
||||
@PrimaryKey val id: String
|
||||
data class RepoStub(
|
||||
@PrimaryKey val id: String,
|
||||
val last_update: Long
|
||||
)
|
||||
|
||||
@Entity(tableName = "etag")
|
||||
data class RepoEtag(
|
||||
@PrimaryKey val id: Int,
|
||||
val key: String
|
||||
)
|
||||
|
||||
|
||||
@@ -2,22 +2,17 @@ package com.topjohnwu.magisk.data.network
|
||||
|
||||
import com.topjohnwu.magisk.core.Const
|
||||
import com.topjohnwu.magisk.core.model.BranchInfo
|
||||
import com.topjohnwu.magisk.core.model.RepoJson
|
||||
import com.topjohnwu.magisk.core.model.UpdateInfo
|
||||
import com.topjohnwu.magisk.core.tasks.GithubRepoInfo
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.Response
|
||||
import retrofit2.http.*
|
||||
|
||||
private const val REVISION = "revision"
|
||||
private const val MODULE = "module"
|
||||
private const val FILE = "file"
|
||||
private const val IF_NONE_MATCH = "If-None-Match"
|
||||
private const val BRANCH = "branch"
|
||||
private const val REPO = "repo"
|
||||
|
||||
const val MAGISK_FILES = "topjohnwu/magisk_files"
|
||||
const val MAGISK_MAIN = "topjohnwu/Magisk"
|
||||
private const val MAGISK_MODULES = "Magisk-Modules-Repo"
|
||||
|
||||
interface GithubPageServices {
|
||||
|
||||
@@ -46,13 +41,13 @@ interface JSDelivrServices {
|
||||
suspend fun fetchInstaller(@Path(REVISION) revision: String): ResponseBody
|
||||
}
|
||||
|
||||
interface GithubRawServices {
|
||||
interface RawServices {
|
||||
|
||||
@GET
|
||||
suspend fun fetchCustomUpdate(@Url url: String): UpdateInfo
|
||||
|
||||
@GET("$MAGISK_MODULES/{$MODULE}/master/{$FILE}")
|
||||
suspend fun fetchModuleFile(@Path(MODULE) id: String, @Path(FILE) file: String): String
|
||||
@GET
|
||||
suspend fun fetchRepoInfo(@Url url: String): RepoJson
|
||||
|
||||
@GET
|
||||
@Streaming
|
||||
@@ -65,15 +60,6 @@ interface GithubRawServices {
|
||||
|
||||
interface GithubApiServices {
|
||||
|
||||
@GET("users/$MAGISK_MODULES/repos")
|
||||
@Headers("Accept: application/vnd.github.v3+json")
|
||||
suspend fun fetchRepos(
|
||||
@Query("page") page: Int,
|
||||
@Header(IF_NONE_MATCH) etag: String,
|
||||
@Query("sort") sort: String = "pushed",
|
||||
@Query("per_page") count: Int = 100
|
||||
): Response<List<GithubRepoInfo>>
|
||||
|
||||
@GET("repos/{$REPO}/branches/{$BRANCH}")
|
||||
@Headers("Accept: application/vnd.github.v3+json")
|
||||
suspend fun fetchBranch(
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.topjohnwu.magisk.core.Config.Value.STABLE_CHANNEL
|
||||
import com.topjohnwu.magisk.core.Const
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.model.*
|
||||
import com.topjohnwu.magisk.core.model.module.Repo
|
||||
import com.topjohnwu.magisk.data.network.*
|
||||
import okhttp3.ResponseBody
|
||||
import retrofit2.HttpException
|
||||
@@ -18,7 +17,7 @@ import java.io.IOException
|
||||
|
||||
class NetworkService(
|
||||
private val pages: GithubPageServices,
|
||||
private val raw: GithubRawServices,
|
||||
private val raw: RawServices,
|
||||
private val jsd: JSDelivrServices,
|
||||
private val api: GithubApiServices
|
||||
) {
|
||||
@@ -68,7 +67,10 @@ class NetworkService(
|
||||
)
|
||||
}
|
||||
|
||||
// Byte streams
|
||||
// Modules related
|
||||
suspend fun fetchRepoInfo(url: String = Const.Url.OFFICIAL_REPO) = raw.fetchRepoInfo(url)
|
||||
|
||||
// Fetch files
|
||||
suspend fun fetchSafetynet() = jsd.fetchSafetynet()
|
||||
suspend fun fetchBootctl() = jsd.fetchBootctl()
|
||||
suspend fun fetchInstaller(): ResponseBody {
|
||||
@@ -76,14 +78,8 @@ class NetworkService(
|
||||
return jsd.fetchInstaller(sha)
|
||||
}
|
||||
suspend fun fetchFile(url: String) = raw.fetchFile(url)
|
||||
|
||||
// Strings
|
||||
suspend fun fetchMetadata(repo: Repo) = raw.fetchModuleFile(repo.id, "module.prop")
|
||||
suspend fun fetchReadme(repo: Repo) = raw.fetchModuleFile(repo.id, "README.md")
|
||||
suspend fun fetchString(url: String) = raw.fetchString(url)
|
||||
|
||||
// API calls
|
||||
suspend fun fetchRepos(page: Int, etag: String) = api.fetchRepos(page, etag)
|
||||
private suspend fun fetchCanaryVersion() = api.fetchBranch(MAGISK_FILES, "canary").commit.sha
|
||||
private suspend fun fetchMainVersion() = api.fetchBranch(MAGISK_MAIN, "master").commit.sha
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user