Browse Source

调整新的同步模式

master
453530270@qq.com 2 years ago
parent
commit
1e4348a8aa
  1. 7
      fssc/README.md
  2. 75
      fssc/internal/handler/nfhandler.go
  3. 2
      fssc/main.go
  4. 68
      fssc/web/nf.tmpl

7
fssc/README.md

@ -6,3 +6,10 @@
需要更新的文件,上传到更新服务器后,按日期生成更新包
注意最后需要 加上 / 要不然会导致创建的zip文件 包含本地文件名,造成不必要的麻烦
# 07 todolist
1、检测相对目录下的同步情况。
2、客户端向管理终端发送检测结果(手动/自动)
3、执行文件同步操作

75
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)
}

2
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...")

68
fssc/web/nf.tmpl

@ -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…
Cancel
Save