From 7716b85d0f02c6d4d8760e9a1a824709ea53ca14 Mon Sep 17 00:00:00 2001 From: "453530270@qq.com" Date: Tue, 2 Jul 2024 17:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=A8=E6=80=81=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fssc/internal/handler/nfhandler.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fssc/internal/handler/nfhandler.go b/fssc/internal/handler/nfhandler.go index 80191cb..45be51f 100644 --- a/fssc/internal/handler/nfhandler.go +++ b/fssc/internal/handler/nfhandler.go @@ -2,17 +2,19 @@ package handler import ( "encoding/json" + "fmt" "fssc/config" "net/http" "os" "path/filepath" + "strings" ) // json 结构体 type Response struct { Status string `json:"status"` //状态 Data FilesListJson `json:"data"` //目录下的文件 - Scdir string // 扫描的目录 + Scdir string `json:"curdir"` // 扫描的目录 } // 文件输出的结构 @@ -27,8 +29,13 @@ type FilesListJson struct { // 遍历监视目录,发送到json中 func NfTest(w http.ResponseWriter, r *http.Request) { + // 监听的目录通过?p=的方式传入 + //urlpath := r.Header.Get("p") + urlpath := r.URL.Query().Get("p") + upath := strings.TrimSuffix(urlpath, "nf") + fmt.Printf("upath is %s\n", upath) // 监听的根目录 - realFilePath := filepath.Join(config.G.FilePath, ".") + realFilePath := filepath.Join(config.G.FilePath, upath) downloadPath := filepath.Join(filepath.Base(config.G.FilePath), r.URL.Path[1:]) // 时间目录的情况 fileInfo, err := os.Stat(realFilePath) @@ -73,7 +80,7 @@ func NfTest(w http.ResponseWriter, r *http.Request) { // respone file list response := Response{ Status: "success", - Scdir: realFilePath, + Scdir: upath, Data: flist, } //