2023-03-23 20:42:01 +08:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/Dreamacro/clash/hub/updater"
|
|
|
|
"github.com/Dreamacro/clash/log"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
func upgradeRouter() http.Handler {
|
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Post("/", upgrade)
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func upgrade(w http.ResponseWriter, r *http.Request) {
|
|
|
|
// modify from https://github.com/AdguardTeam/AdGuardHome/blob/595484e0b3fb4c457f9bb727a6b94faa78a66c5f/internal/home/controlupdate.go#L108
|
|
|
|
log.Infoln("start update")
|
|
|
|
err := updater.Update()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln("err:%s", err)
|
2023-03-27 00:49:32 +08:00
|
|
|
return
|
2023-03-23 20:42:01 +08:00
|
|
|
}
|
|
|
|
|
2023-03-29 16:19:26 +08:00
|
|
|
restart(w, r)
|
2023-03-23 20:42:01 +08:00
|
|
|
}
|