chore: updateUI API return 501 when config incomplete
This commit is contained in:
@ -2,7 +2,6 @@ package executor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Dreamacro/clash/ntp"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
@ -12,6 +11,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Dreamacro/clash/ntp"
|
||||
|
||||
"github.com/Dreamacro/clash/adapter"
|
||||
"github.com/Dreamacro/clash/adapter/inbound"
|
||||
"github.com/Dreamacro/clash/adapter/outboundgroup"
|
||||
@ -142,6 +143,7 @@ func GetGeneral() *config.General {
|
||||
AllowLan: listener.AllowLan(),
|
||||
BindAddress: listener.BindAddress(),
|
||||
},
|
||||
Controller: config.Controller{},
|
||||
Mode: tunnel.Mode(),
|
||||
LogLevel: log.Level(),
|
||||
IPv6: !resolver.DisableIPv6,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -15,12 +16,12 @@ import (
|
||||
|
||||
func upgradeRouter() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Post("/", upgrade)
|
||||
r.Post("/", upgradeCore)
|
||||
r.Post("/ui", updateUI)
|
||||
return r
|
||||
}
|
||||
|
||||
func upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
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()
|
||||
@ -49,9 +50,15 @@ func upgrade(w http.ResponseWriter, r *http.Request) {
|
||||
func updateUI(w http.ResponseWriter, r *http.Request) {
|
||||
err := config.UpdateUI()
|
||||
if err != nil {
|
||||
log.Warnln("%s", err)
|
||||
render.Status(r, http.StatusInternalServerError)
|
||||
render.JSON(w, r, newError(fmt.Sprintf("%s", err)))
|
||||
if errors.Is(err, config.ErrImcompleteConf) {
|
||||
log.Warnln("%s", err)
|
||||
render.Status(r, http.StatusNotImplemented)
|
||||
render.JSON(w, r, newError(fmt.Sprintf("%s", err)))
|
||||
} else {
|
||||
log.Warnln("%s", err)
|
||||
render.Status(r, http.StatusInternalServerError)
|
||||
render.JSON(w, r, newError(fmt.Sprintf("%s", err)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user