Browse Source

完善动态获取的方法

master
453530270@qq.com 2 years ago
parent
commit
7716b85d0f
  1. 13
      fssc/internal/handler/nfhandler.go

13
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,
}
//

Loading…
Cancel
Save