|
|
@ -2,17 +2,19 @@ package handler |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
|
|
|
"fmt" |
|
|
"fssc/config" |
|
|
"fssc/config" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"os" |
|
|
"os" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
|
|
|
"strings" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// json 结构体
|
|
|
// json 结构体
|
|
|
type Response struct { |
|
|
type Response struct { |
|
|
Status string `json:"status"` //状态
|
|
|
Status string `json:"status"` //状态
|
|
|
Data FilesListJson `json:"data"` //目录下的文件
|
|
|
Data FilesListJson `json:"data"` //目录下的文件
|
|
|
Scdir string // 扫描的目录
|
|
|
Scdir string `json:"curdir"` // 扫描的目录
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 文件输出的结构
|
|
|
// 文件输出的结构
|
|
|
@ -27,8 +29,13 @@ type FilesListJson struct { |
|
|
|
|
|
|
|
|
// 遍历监视目录,发送到json中
|
|
|
// 遍历监视目录,发送到json中
|
|
|
func NfTest(w http.ResponseWriter, r *http.Request) { |
|
|
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:]) |
|
|
downloadPath := filepath.Join(filepath.Base(config.G.FilePath), r.URL.Path[1:]) |
|
|
// 时间目录的情况
|
|
|
// 时间目录的情况
|
|
|
fileInfo, err := os.Stat(realFilePath) |
|
|
fileInfo, err := os.Stat(realFilePath) |
|
|
@ -73,7 +80,7 @@ func NfTest(w http.ResponseWriter, r *http.Request) { |
|
|
// respone file list
|
|
|
// respone file list
|
|
|
response := Response{ |
|
|
response := Response{ |
|
|
Status: "success", |
|
|
Status: "success", |
|
|
Scdir: realFilePath, |
|
|
Scdir: upath, |
|
|
Data: flist, |
|
|
Data: flist, |
|
|
} |
|
|
} |
|
|
//
|
|
|
//
|
|
|
|