4 changed files with 153 additions and 1 deletions
@ -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) |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<head> |
|||
<title>FsNext</title> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|||
<link rel="stylesheet" href="/static/static/css/bootstrap.css"> |
|||
<link rel="icon" type="image/x-icon" href="/favicon.ico?v=2"> |
|||
<script type="text/javascript" src="/static/static/js/jquery.min.js"></script> |
|||
<script type="text/javascript" src="/static/static/js/bootstrap.min.js"></script> |
|||
</head> |
|||
<body> |
|||
|
|||
<div class="jumbotron"><div> |
|||
|
|||
<div class="container"> |
|||
|
|||
<form method="post" action="/sup"> |
|||
<div class="form-group"> |
|||
|
|||
<div class="input-group"> |
|||
<input type="hidden" class="form-control" name="bpath" value="{{.Bpath}}" /> |
|||
</div> |
|||
|
|||
<div class="input-group"> |
|||
<input type="hidden" class="form-control" name="bfile" value="{{.Bfile}}" /> |
|||
</div> |
|||
|
|||
<div class="input-group"> |
|||
<div class="input-group-addon">服务器ip</div> |
|||
<input type="text" class="form-control" name="sip" placeholder="eg:192.168.66.99"> |
|||
</div> |
|||
</div> |
|||
<button type="submit" class="btn btn-primary">Transfer</button> |
|||
</form> |
|||
</div> |
|||
|
|||
<div class="row mb-12"> |
|||
{{ range .Files }} |
|||
<li class="list-group-item"> |
|||
<input class="mfile" type="checkbox" name="zipfiles" value="{{.Name}}"> |
|||
{{ if .IsDir }} |
|||
<svg class="folder-icon" viewBox="0 0 24 24"> |
|||
<path fill="currentColor" d="M10 4H4C2.9 4 2 4.9 2 6V18C2 19.1 2.9 20 4 20H20C21.1 20 22 19.1 22 18V8C22 6.9 21.1 6 20 6H12L10 4Z" /> |
|||
</svg> |
|||
<a href="{{ $.UrlPath }}/{{ .Name }}">{{ .Name }}</a> |
|||
{{ else }} |
|||
<svg class="file-icon" viewBox="0 0 24 24"> |
|||
<path fill="currentColor" d="M14 2H6C4.9 2 4 2.9 4 4V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V8L14 2M13 9V3.5L18.5 9H13Z" /> |
|||
</svg> |
|||
<a href="/up?p={{b64en $.UrlPath}}&f={{b64en .Name}}" class="button" title="更新{{ .Name }}">{{ .Name }}</a> |
|||
<span style="display:none" class="badge">{{.Info.Size}}</span><span class="badge" > {{.Info.ModTime.Format "2006-01-02 15:04:05"}} </span> |
|||
{{ end }} |
|||
</li> |
|||
{{ end }} |
|||
</ul> |
|||
|
|||
<ul class="list-group"> |
|||
<li class="list-group-item"> |
|||
<span class="badge">14</span> |
|||
Cras justo odio |
|||
</li> |
|||
</ul> |
|||
</div> |
|||
|
|||
|
|||
|
|||
</body> |
|||
</html> |
|||
Loading…
Reference in new issue