mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 16:30:07 +08:00
Some checks are pending
Test / test (1.20, macos-13) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-13) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-13) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-13) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-13) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
Leaving `channel` blank will automatically determine the channel. Other valid values are `alpha`/`release`. Setting `force` to `true` will bypass the version check and force the update.
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package route
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/metacubex/mihomo/component/updater"
|
|
"github.com/metacubex/mihomo/log"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/render"
|
|
)
|
|
|
|
func upgradeRouter() http.Handler {
|
|
r := chi.NewRouter()
|
|
r.Post("/ui", updateUI)
|
|
if !embedMode { // disallow upgrade core/geo in embed mode
|
|
r.Post("/", upgradeCore)
|
|
r.Post("/geo", updateGeoDatabases)
|
|
}
|
|
return r
|
|
}
|
|
|
|
func upgradeCore(w http.ResponseWriter, r *http.Request) {
|
|
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/home/controlupdate.go#L108
|
|
log.Infoln("start update")
|
|
execPath, err := os.Executable()
|
|
if err != nil {
|
|
render.Status(r, http.StatusInternalServerError)
|
|
render.JSON(w, r, newError(fmt.Sprintf("getting path: %s", err)))
|
|
return
|
|
}
|
|
|
|
query := r.URL.Query()
|
|
channel := query.Get("channel")
|
|
force := query.Get("force") == "true"
|
|
|
|
err = updater.DefaultCoreUpdater.Update(execPath, channel, force)
|
|
if err != nil {
|
|
log.Warnln("%s", err)
|
|
render.Status(r, http.StatusInternalServerError)
|
|
render.JSON(w, r, newError(fmt.Sprintf("%s", err)))
|
|
return
|
|
}
|
|
|
|
render.JSON(w, r, render.M{"status": "ok"})
|
|
if f, ok := w.(http.Flusher); ok {
|
|
f.Flush()
|
|
}
|
|
|
|
go restartExecutable(execPath)
|
|
}
|
|
|
|
func updateUI(w http.ResponseWriter, r *http.Request) {
|
|
err := updater.DefaultUiUpdater.DownloadUI()
|
|
if err != nil {
|
|
log.Warnln("%s", err)
|
|
render.Status(r, http.StatusInternalServerError)
|
|
render.JSON(w, r, newError(fmt.Sprintf("%s", err)))
|
|
return
|
|
}
|
|
|
|
render.JSON(w, r, render.M{"status": "ok"})
|
|
if f, ok := w.(http.Flusher); ok {
|
|
f.Flush()
|
|
}
|
|
}
|