mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-02 20:01:51 +08:00
- Add standalone edition (`Dockerfile.standalone`, `docker-compose.standalone.yml`) alongside sandbox edition and publish both in `.github/workflows/release.yml`. - Implement `scripts/deploy-lib.sh`, `install.sh`, `update.sh`, and `scripts/artex-sandbox-firewall.sh --cleanup` with edition detection, legacy standalone -> sandbox migration (symlink-safe workspace permissions), automatic snapshots with pinned `artex-rollback/*` images + PG dump, auto/manual cross-edition rollback, and post-rollback upstream unpinning. - Update `ensureWritableDir` in `internal/sandbox/manager.go` to safely migrate nested root-owned workspace files without following symlinks. - Expose `deploy_edition` in `/api/update/check` and update `UpdateCard` UI/i18n warnings for sandbox vs standalone in-app update/rollback. - Reconcile `artex-gateway` TUN policy routing (`priority 218`, `raw PREROUTING`, `nat POSTROUTING`, `DOCKER-USER`) every 15s to self-heal after host network rule flushes or bridge changes. - Add unit and shell tests (`scripts/deploy_test.sh`, `cmd/artex-gateway/tun_linux_test.go`, `internal/sandbox/sandbox_test.go`, `server/update_test.go`) and update `README.md` / `.env.example`.
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/Autumn-27/artex/selfupdate"
|
|
)
|
|
|
|
const updateSettingsKey = "update.network"
|
|
|
|
type updateSettings struct {
|
|
Proxy string `json:"proxy"`
|
|
}
|
|
|
|
func (cfg *updateSettings) validate() error {
|
|
cfg.Proxy = strings.TrimSpace(cfg.Proxy)
|
|
if _, err := selfupdate.ParseProxy(cfg.Proxy); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Server) loadUpdateSettings() (updateSettings, error) {
|
|
cfg := updateSettings{}
|
|
if s.m == nil || s.m.pg == nil {
|
|
return cfg, nil
|
|
}
|
|
raw, ok, err := s.m.pg.GetSetting(updateSettingsKey)
|
|
if err != nil {
|
|
return cfg, fmt.Errorf("读取更新网络设置失败: %w", err)
|
|
}
|
|
if ok {
|
|
if err := json.Unmarshal([]byte(raw), &cfg); err != nil {
|
|
return cfg, fmt.Errorf("更新网络设置格式无效")
|
|
}
|
|
}
|
|
if err := cfg.validate(); err != nil {
|
|
return cfg, err
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
func (s *Server) getUpdateSettings(w http.ResponseWriter, r *http.Request) {
|
|
cfg, err := s.loadUpdateSettings()
|
|
if err != nil {
|
|
writeErr(w, 500, err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, 200, cfg)
|
|
}
|
|
|
|
func (s *Server) putUpdateSettings(w http.ResponseWriter, r *http.Request) {
|
|
var cfg updateSettings
|
|
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 8192)).Decode(&cfg); err != nil {
|
|
writeErr(w, 400, "更新网络设置格式无效")
|
|
return
|
|
}
|
|
if err := cfg.validate(); err != nil {
|
|
writeErr(w, 400, err.Error())
|
|
return
|
|
}
|
|
raw, err := json.Marshal(cfg)
|
|
if err != nil {
|
|
writeErr(w, 500, err.Error())
|
|
return
|
|
}
|
|
if err := s.m.pg.SetSettingContext(r.Context(), updateSettingsKey, string(raw)); err != nil {
|
|
writeErr(w, 500, "保存更新网络设置失败")
|
|
return
|
|
}
|
|
writeJSON(w, 200, cfg)
|
|
}
|
|
|
|
// Capture one effective proxy for both release discovery and all asset downloads.
|
|
// A different proxy bypasses cached success/error results from the previous route.
|
|
func (s *Server) updateClient() (*http.Client, string, error) {
|
|
cfg, err := s.loadUpdateSettings()
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
client, err := selfupdate.NewClient(cfg.Proxy)
|
|
return client, cfg.Proxy, err
|
|
}
|