Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
4e272b70
Commit
4e272b70
authored
Oct 07, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Download GitHub files through CDN
parent
8dc62a02
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
21 deletions
+58
-21
UpdateInfo.kt
...c/main/java/com/topjohnwu/magisk/core/model/UpdateInfo.kt
+10
-0
NetworkServices.kt
...java/com/topjohnwu/magisk/data/network/NetworkServices.kt
+21
-15
NetworkService.kt
...va/com/topjohnwu/magisk/data/repository/NetworkService.kt
+27
-6
No files found.
app/src/main/java/com/topjohnwu/magisk/core/model/UpdateInfo.kt
View file @
4e272b70
...
...
@@ -41,3 +41,13 @@ data class StubJson(
val
versionCode
:
Int
=
-
1
,
val
link
:
String
=
""
)
:
Parcelable
@JsonClass
(
generateAdapter
=
true
)
data class
CommitInfo
(
val
sha
:
String
)
@JsonClass
(
generateAdapter
=
true
)
data class
BranchInfo
(
val
commit
:
CommitInfo
)
app/src/main/java/com/topjohnwu/magisk/data/network/NetworkServices.kt
View file @
4e272b70
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.UpdateInfo
import
com.topjohnwu.magisk.core.tasks.GithubRepoInfo
import
okhttp3.ResponseBody
...
...
@@ -11,10 +12,12 @@ 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"
private
const
val
MAGISK_FILES
=
"topjohnwu/magisk_files"
private
const
val
MAGISK_MASTER
=
"topjohnwu/Magisk/master
"
private
const
val
MAGISK_MODULES
=
"Magi
s
k-Modules-Repo"
const
val
MAGISK_FILES
=
"topjohnwu/magisk_files"
const
val
MAGISK_MAIN
=
"topjohnwu/Magisk
"
private
const
val
MAGISK_MODULES
=
"Magi
c
k-Modules-Repo"
interface
GithubPageServices
{
...
...
@@ -34,27 +37,23 @@ interface JSDelivrServices {
@GET
(
"$MAGISK_FILES@{$REVISION}/bootctl"
)
@Streaming
suspend
fun
fetchBootctl
(
@Path
(
REVISION
)
revision
:
String
=
Const
.
BOOTCTL_REVISION
):
ResponseBody
@GET
(
"$MAGISK_FILES@{$REVISION}/canary.json"
)
suspend
fun
fetchCanaryUpdate
(
@Path
(
REVISION
)
revision
:
String
):
UpdateInfo
@GET
(
"$MAGISK_MAIN@{$REVISION}/scripts/module_installer.sh"
)
@Streaming
suspend
fun
fetchInstaller
(
@Path
(
REVISION
)
revision
:
String
):
ResponseBody
}
interface
GithubRawServices
{
@GET
(
"$MAGISK_FILES/canary/debug.json"
)
suspend
fun
fetchCanaryUpdate
():
UpdateInfo
@GET
suspend
fun
fetchCustomUpdate
(
@Url
url
:
String
):
UpdateInfo
@GET
(
"$MAGISK_MASTER/scripts/module_installer.sh"
)
@Streaming
suspend
fun
fetchInstaller
():
ResponseBody
@GET
(
"$MAGISK_MODULES/{$MODULE}/master/{$FILE}"
)
suspend
fun
fetchModuleFile
(
@Path
(
MODULE
)
id
:
String
,
@Path
(
FILE
)
file
:
String
):
String
/**
* This method shall be used exclusively for fetching files from urls from previous requests.
* Him, who uses it in a wrong way, shall die in an eternal flame.
* */
@GET
@Streaming
suspend
fun
fetchFile
(
@Url
url
:
String
):
ResponseBody
...
...
@@ -66,7 +65,7 @@ interface GithubRawServices {
interface
GithubApiServices
{
@GET
(
"users/$
{MAGISK_MODULES}
/repos"
)
@GET
(
"users/$
MAGISK_MODULES
/repos"
)
@Headers
(
"Accept: application/vnd.github.v3+json"
)
suspend
fun
fetchRepos
(
@Query
(
"page"
)
page
:
Int
,
...
...
@@ -74,5 +73,12 @@ interface GithubApiServices {
@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
(
@Path
(
REPO
,
encoded
=
true
)
repo
:
String
,
@Path
(
BRANCH
)
branch
:
String
):
BranchInfo
}
app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt
View file @
4e272b70
...
...
@@ -6,12 +6,12 @@ import com.topjohnwu.magisk.core.Config.Value.CANARY_CHANNEL
import
com.topjohnwu.magisk.core.Config.Value.CUSTOM_CHANNEL
import
com.topjohnwu.magisk.core.Config.Value.DEFAULT_CHANNEL
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.GithubApiServices
import
com.topjohnwu.magisk.data.network.GithubPageServices
import
com.topjohnwu.magisk.data.network.GithubRawServices
import
com.topjohnwu.magisk.data.network.JSDelivrServices
import
com.topjohnwu.magisk.data.network.*
import
okhttp3.ResponseBody
import
retrofit2.HttpException
import
timber.log.Timber
import
java.io.IOException
...
...
@@ -49,13 +49,32 @@ class NetworkService(
// UpdateInfo
suspend
fun
fetchStableUpdate
()
=
pages
.
fetchStableUpdate
()
suspend
fun
fetchBetaUpdate
()
=
pages
.
fetchBetaUpdate
()
suspend
fun
fetchCanaryUpdate
()
=
raw
.
fetchCanaryUpdate
()
suspend
fun
fetchCustomUpdate
(
url
:
String
)
=
raw
.
fetchCustomUpdate
(
url
)
suspend
fun
fetchCanaryUpdate
():
UpdateInfo
{
val
sha
=
fetchCanaryVersion
()
val
info
=
jsd
.
fetchCanaryUpdate
(
sha
)
fun
genCDNUrl
(
name
:
String
)
=
"${Const.Url.JS_DELIVR_URL}${MAGISK_FILES}@${sha}/${name}"
fun
ManagerJson
.
updateCopy
()
=
copy
(
link
=
genCDNUrl
(
link
),
note
=
genCDNUrl
(
note
))
fun
MagiskJson
.
updateCopy
()
=
copy
(
link
=
genCDNUrl
(
link
),
note
=
genCDNUrl
(
note
))
fun
StubJson
.
updateCopy
()
=
copy
(
link
=
genCDNUrl
(
link
))
fun
UninstallerJson
.
updateCopy
()
=
copy
(
link
=
genCDNUrl
(
link
))
return
info
.
copy
(
app
=
info
.
app
.
updateCopy
(),
magisk
=
info
.
magisk
.
updateCopy
(),
stub
=
info
.
stub
.
updateCopy
(),
uninstaller
=
info
.
uninstaller
.
updateCopy
()
)
}
// Byte streams
suspend
fun
fetchSafetynet
()
=
jsd
.
fetchSafetynet
()
suspend
fun
fetchBootctl
()
=
jsd
.
fetchBootctl
()
suspend
fun
fetchInstaller
()
=
raw
.
fetchInstaller
()
suspend
fun
fetchInstaller
():
ResponseBody
{
val
sha
=
fetchMainVersion
()
return
jsd
.
fetchInstaller
(
sha
)
}
suspend
fun
fetchFile
(
url
:
String
)
=
raw
.
fetchFile
(
url
)
// Strings
...
...
@@ -65,4 +84,6 @@ class NetworkService(
// 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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment