feat: download/upgrade XD to external-ui

This commit is contained in:
Larvan2
2023-09-15 23:25:56 +08:00
committed by Larvan2
parent af99b52527
commit c3d72f6883
7 changed files with 165 additions and 23 deletions

View File

@ -49,6 +49,7 @@ type Memory struct {
func SetUIPath(path string) {
uiPath = C.Path.Resolve(path)
C.UIPath = uiPath
}
func Start(addr string, tlsAddr string, secret string,

View File

@ -5,6 +5,7 @@ import (
"net/http"
"os"
"github.com/Dreamacro/clash/config"
"github.com/Dreamacro/clash/hub/updater"
"github.com/Dreamacro/clash/log"
@ -15,6 +16,7 @@ import (
func upgradeRouter() http.Handler {
r := chi.NewRouter()
r.Post("/", upgrade)
r.Post("/xd", updateXD)
return r
}
@ -43,3 +45,18 @@ func upgrade(w http.ResponseWriter, r *http.Request) {
go restartExecutable(execPath)
}
func updateXD(w http.ResponseWriter, r *http.Request) {
err := config.UpdateXD()
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()
}
}

View File

@ -32,7 +32,7 @@ var (
workDir string
// mu protects all fields below.
mu sync.RWMutex
mu sync.Mutex
currentExeName string // 当前可执行文件
updateDir string // 更新目录