diff --git a/fssc/README.md b/fssc/README.md index 77614ef..5b8f648 100644 --- a/fssc/README.md +++ b/fssc/README.md @@ -5,4 +5,11 @@ 更新服务器 需要更新的文件,上传到更新服务器后,按日期生成更新包 -注意最后需要 加上 / 要不然会导致创建的zip文件 包含本地文件名,造成不必要的麻烦 \ No newline at end of file +注意最后需要 加上 / 要不然会导致创建的zip文件 包含本地文件名,造成不必要的麻烦 + + +# 07 todolist + +1、检测相对目录下的同步情况。 +2、客户端向管理终端发送检测结果(手动/自动) +3、执行文件同步操作 \ No newline at end of file diff --git a/fssc/internal/handler/nfhandler.go b/fssc/internal/handler/nfhandler.go new file mode 100644 index 0000000..fafa9ec --- /dev/null +++ b/fssc/internal/handler/nfhandler.go @@ -0,0 +1,75 @@ +package handler + +import ( + "encoding/json" + "fmt" + "fssc/config" + "net/http" + "os" + "path/filepath" +) + +// json 结构体 +type Response struct { + Status string `json:"status"` + Message string `json:"message"` +} + +// 遍历监视目录,发送到json中 +func NfTest(w http.ResponseWriter, r *http.Request) { + // 监听的根目录 + realFilePath := filepath.Join(config.G.FilePath, ".") + downloadPath := filepath.Join(filepath.Base(config.G.FilePath), r.URL.Path[1:]) + fileInfo, err := os.Stat(realFilePath) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + data := struct { + DeviceName string + Loip string + Rundir string + IsDir bool + FileName string + DownloadPath string + Files []os.DirEntry + }{ + DeviceName: config.G.DeviceName, + Loip: config.G.LocalIP, + Rundir: config.G.FilePath, + DownloadPath: downloadPath, + } + + if fileInfo.IsDir() { + data.IsDir = true + // 遍历目录 + files, err := os.ReadDir(realFilePath) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + data.Files = files + } else { + data.FileName = filepath.Base(realFilePath) + } + + // for _,enty:= range data { + + // } + + //结果生成json + ss, err := json.Marshal(data) + if err != nil { + fmt.Printf("json encode erorr:%s", err) + } + + // respone file list + response := Response{ + Status: "success", + Message: string(ss), + } + // + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(response) +} diff --git a/fssc/main.go b/fssc/main.go index e6e8103..c4df9d5 100644 --- a/fssc/main.go +++ b/fssc/main.go @@ -48,6 +48,8 @@ func sendClient() error { http.HandleFunc("/sup", handler.Supfile) // udp 传送文件 http.HandleFunc("/sendZip", handler.SendZip) + // 监视目标的fs json + http.HandleFunc("/nf", handler.NfTest) fmt.Println("send file to server...") diff --git a/fssc/web/nf.tmpl b/fssc/web/nf.tmpl new file mode 100644 index 0000000..8f37c76 --- /dev/null +++ b/fssc/web/nf.tmpl @@ -0,0 +1,68 @@ + + + + FsNext + + + + + + + + +
+ +
+ +
+
+ +
+ +
+ +
+ +
+ +
+
服务器ip
+ +
+
+ +
+
+ +
+ {{ range .Files }} +
  • + + {{ if .IsDir }} + + + + {{ .Name }} + {{ else }} + + + + {{ .Name }} + {{.Info.ModTime.Format "2006-01-02 15:04:05"}} + {{ end }} +
  • + {{ end }} + + +
      +
    • + 14 + Cras justo odio +
    • +
    +
    + + + + + \ No newline at end of file