feat: download/upgrade XD to external-ui
This commit is contained in:
@ -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,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ var (
|
||||
workDir string
|
||||
|
||||
// mu protects all fields below.
|
||||
mu sync.RWMutex
|
||||
mu sync.Mutex
|
||||
|
||||
currentExeName string // 当前可执行文件
|
||||
updateDir string // 更新目录
|
||||
|
Reference in New Issue
Block a user