Browse Source

移除下载代码

master
453530270@qq.com 2 years ago
parent
commit
bc563df654
  1. 79
      fssc/internal/handler/handler.go

79
fssc/internal/handler/handler.go

@ -12,7 +12,6 @@ import (
"time"
"net/http"
"net/rpc"
"os"
"path/filepath"
@ -228,84 +227,6 @@ func SendZip(w http.ResponseWriter, r *http.Request) {
}
// 下载zip
func Downzip(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
// 选择文件,并生成zip包
// 文件
zipfarr := r.Form["zipfiles"]
// 服务器ip地址
serip := r.Form["serverip"]
if serip[0] == "" {
http.Error(w, "remote server ip is blank!", http.StatusInternalServerError)
return
}
// fmt.Println(r.Form)
// 选中的路径
wtculpath := r.Form["curpath"]
// 实际路径
realFilePath := filepath.Join(config.G.FilePath, wtculpath[0])
// zip 文件名
zpFileName := "BIU_" + time.Now().Format("20060102_150405") + ".zip"
// 创建zip
err := util.CompressToZip(zpFileName, realFilePath, zipfarr)
if err != nil {
fmt.Println("create zip error", err)
}
// 停止下,检查zip是否创建成功
time.Sleep(1200)
_, err = os.Stat(realFilePath + "/" + zpFileName)
if err != nil {
// 调用httpd rpc
fmt.Println("RPC Server IP:", serip[0])
rpcServer := serip[0] + ":9080"
client, err := rpc.DialHTTP("tcp", rpcServer)
if err != nil {
fmt.Println("Http rpc error :", err)
}
// 组装url 静态文件
// url := "http://" + config.G.LocalIP + ":" + config.G.Port + "/files/" + zpFileName
// 动态
url := "http://" + config.G.LocalIP + ":" + config.G.Port + "/files?zp=" + zpFileName
args := Args{url, zpFileName}
var reply int
err = client.Call("Rbup.DecompressZip", args, &reply)
if err != nil {
fmt.Println("rpc call error :", err)
// 输出执行结果
fmt.Fprintln(w, "rpc call error:", err)
} else {
// 输出下载链接
fmt.Fprintf(w, "<a href='%s'>%s</a><br/>\n", url, url)
fmt.Fprintf(w, "RPC execute result :%d<br/>\n", reply)
}
} else {
fmt.Fprintf(w, "archive is created faild")
}
}
// 文件下载
func Dfiles(w http.ResponseWriter, r *http.Request) {
// url中获取参数
query := r.URL.Query()
zpfile := query.Get("zp")
// 实际路径
zpFileName := filepath.Join(config.G.FilePath, "/files/", zpfile)
// fileInfo, err := os.Stat(zpFileName)
// if err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
// return
// }
// fmt.Println(fileInfo)
http.ServeFile(w, r, zpFileName)
}
// 发送拦截
func SendHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {

Loading…
Cancel
Save