mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	重置配置的同时也重置本地API节点的配置
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/apps"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/configs"
 | 
			
		||||
@@ -9,10 +10,13 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAdmin/internal/utils"
 | 
			
		||||
	_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
	_ "github.com/iwind/TeaGo/bootstrap"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"github.com/iwind/gosock/pkg/gosock"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -53,6 +57,20 @@ func main() {
 | 
			
		||||
			fmt.Println("[ERROR]reset failed: " + err.Error())
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// reset local api
 | 
			
		||||
		var apiNodeExe = Tea.Root + "/edge-api/bin/edge-api"
 | 
			
		||||
		_, err = os.Stat(apiNodeExe)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			var cmd = exec.Command(apiNodeExe, "reset")
 | 
			
		||||
			var stderr = &bytes.Buffer{}
 | 
			
		||||
			cmd.Stderr = stderr
 | 
			
		||||
			err = cmd.Run()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Println("reset api node failed: " + stderr.String())
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		fmt.Println("done")
 | 
			
		||||
	})
 | 
			
		||||
	app.On("recover", func() {
 | 
			
		||||
 
 | 
			
		||||
@@ -61,10 +61,11 @@ func LoadAPIConfig() (*APIConfig, error) {
 | 
			
		||||
 | 
			
		||||
// ResetAPIConfig 重置配置
 | 
			
		||||
func ResetAPIConfig() error {
 | 
			
		||||
	filename := "api.yaml"
 | 
			
		||||
	var filename = "api.yaml"
 | 
			
		||||
 | 
			
		||||
	// 重置 configs/api.yaml
 | 
			
		||||
	{
 | 
			
		||||
		configFile := Tea.ConfigFile(filename)
 | 
			
		||||
		var configFile = Tea.ConfigFile(filename)
 | 
			
		||||
		stat, err := os.Stat(configFile)
 | 
			
		||||
		if err == nil && !stat.IsDir() {
 | 
			
		||||
			err = os.Remove(configFile)
 | 
			
		||||
@@ -77,7 +78,7 @@ func ResetAPIConfig() error {
 | 
			
		||||
	// 重置 ~/.edge-admin/api.yaml
 | 
			
		||||
	homeDir, homeErr := os.UserHomeDir()
 | 
			
		||||
	if homeErr == nil {
 | 
			
		||||
		configFile := homeDir + "/." + teaconst.ProcessName + "/" + filename
 | 
			
		||||
		var configFile = homeDir + "/." + teaconst.ProcessName + "/" + filename
 | 
			
		||||
		stat, err := os.Stat(configFile)
 | 
			
		||||
		if err == nil && !stat.IsDir() {
 | 
			
		||||
			err = os.Remove(configFile)
 | 
			
		||||
@@ -89,7 +90,7 @@ func ResetAPIConfig() error {
 | 
			
		||||
 | 
			
		||||
	// 重置 /etc/edge-admin/api.yaml
 | 
			
		||||
	{
 | 
			
		||||
		configFile := "/etc/" + teaconst.ProcessName + "/" + filename
 | 
			
		||||
		var configFile = "/etc/" + teaconst.ProcessName + "/" + filename
 | 
			
		||||
		stat, err := os.Stat(configFile)
 | 
			
		||||
		if err == nil && !stat.IsDir() {
 | 
			
		||||
			err = os.Remove(configFile)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user