Compare commits

...

2 Commits

  1. 1
      aufs/.gitignore
  2. 118
      aufs/core/sendzip.go
  3. 4
      vue/afvue/src/views/Sfilecompare.vue

1
aufs/.gitignore

@ -2,3 +2,4 @@ ups.db
aufs aufs
go.sum go.sum
go.mod go.mod
logs/

118
aufs/core/sendzip.go

@ -1,15 +1,11 @@
package core package core
import ( import (
"aufs/config"
"aufs/util"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net"
"net/http" "net/http"
"net/rpc/jsonrpc" "net/rpc/jsonrpc"
"path" "os"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@ -70,6 +66,8 @@ func SendZip(w http.ResponseWriter, r *http.Request) {
RemoteAddr: remoteaddr[0], RemoteAddr: remoteaddr[0],
RemotePath: remotepath[0], RemotePath: remotepath[0],
} }
// 记录日志
afsLog(zipblock)
// 从serip 切割出ip 和端口 // 从serip 切割出ip 和端口
splitip := strings.Split(serip[0], ":") splitip := strings.Split(serip[0], ":")
@ -111,93 +109,31 @@ func SendZip(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(resp) json.NewEncoder(w).Encode(resp)
} }
// 将文件打包成压缩包 // 自动升级的日志
func SendZip00(w http.ResponseWriter, r *http.Request) { func afsLog(zipblock ZipBlock) {
r.ParseForm() // 年月日格式文件夹
// 选择文件,并生成zip包 year, month, day := time.Now().Date()
// 文件 logdir := fmt.Sprintf("%v/%v/%v", year, month, day)
zipfarr := r.Form["sfiles"] // 日志文件
logfile := fmt.Sprintf("%v/aufs.log", logdir)
// 服务器ip地址 // 检查目录是否存在
serip := r.Form["serverip"] if _, err := os.Stat(logdir); os.IsNotExist(err) {
if serip[0] == "" { // 不存在就创建
http.Error(w, "remote server ip is blank!", http.StatusInternalServerError) os.MkdirAll(logdir, 0755)
return }
} // 检查日志文件是否存在
if _, err := os.Stat(logfile); os.IsNotExist(err) {
tpath := "" // 不存在就创建
// 选中的路径,可以为空 os.Create(logfile)
wtculpath := r.Form["curpath"] }
if wtculpath != nil { // 打开日志文件
tpath = util.Base64dec(wtculpath[0]) f, err := os.OpenFile(logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
}
// 实际路径
realFilePath := filepath.Join(config.G.FilePath, tpath)
// zip 文件名
zpFileName := "BIU_" + time.Now().Format("20060102_150405") + ".zip"
// 创建zip 异步?
taskId := make(chan string)
go func() {
util.CompressToZip(zpFileName, realFilePath, zipfarr)
taskId <- "arcok"
// fmt.Fprintln(w, "create archive:", err)
}()
// go util.CompressToZip(zpFileName, realFilePath, zipfarr)
fmt.Println("archive is createding...")
// 当前运行的目录
// ZIP 文件的实际路径
ziprl := path.Join("./sync_zips/", zpFileName)
// zip 创建成功后
rest := <-taskId
// 有压缩包 才可以操作
if strings.EqualFold(strings.ToLower(rest), "arcok") {
fmt.Println("archive is sending...")
// 创建udp 渠道发送数据
message := fmt.Sprintf("%s%s%s", config.G.DeviceName, "|", "sender")
UdpSendFile(serip[0], ziprl, zpFileName, message, w)
} else {
fmt.Println("archive is not exist!!!")
}
// 执行完 跳转到 首页
// http.Redirect(w, r, "/", http.StatusFound)
}
// udp 模式发送文件
/*
* serip 服务器ip,
* absfilepath 发送文件的实际路径,
* fname 文件名
* message 携带部分信息的消息
* http.ResponseWriter
*/
func UdpSendFile(serip string, absfilepath string, fname string, message string, w http.ResponseWriter) {
// 1、获取udp addr
remoteAddr, err := net.ResolveUDPAddr("udp", serip+":9099")
if err != nil { if err != nil {
return fmt.Printf("open log file faild %v", err)
} }
// 2、 监听端口 defer f.Close()
conn, err := net.DialUDP("udp", nil, remoteAddr) // 写入日志
if err != nil { logfmt := fmt.Sprintf("%v %v %v %v %v\n", time.Now().Format("2006-01-02 15:04:05"), zipblock.Basepath, zipblock.Curpath, zipblock.SelFile, zipblock.RemoteAddr, zipblock.RemotePath)
return f.WriteString(logfmt)
}
defer conn.Close()
// 3、在端口发送数据
// message := fmt.Sprintf("%s%s%s", config.G.DeviceName, "|", "sender")
// 向链接通道发送数据 数据包头
conn.Write([]byte(message))
// 发送文件
go func() {
err := util.SendFiles(absfilepath, fmt.Sprintf("http://%s/rc", remoteAddr))
if err != nil {
fmt.Printf("Send file to %s error: %s\n", remoteAddr, err)
}
}()
} }

4
vue/afvue/src/views/Sfilecompare.vue

@ -353,9 +353,11 @@ export default {
setTimeout(() => { setTimeout(() => {
this.dialogShow = false this.dialogShow = false
}, 3000); }, 3000);
}
// //
this.getSflist() this.getSflist()
}
// alert(res.data.reply) // alert(res.data.reply)
// //
this.selectedFiles = [] this.selectedFiles = []

Loading…
Cancel
Save