Browse Source

调整返回上级的逻辑

master
453530270@qq.com 2 years ago
parent
commit
65f31a07df
  1. BIN
      fssc/fssc
  2. 32
      fssc/internal/handler/webconsole.go
  3. 3
      fssc/main.go
  4. 71
      fssc/web/wbconsole.tmpl

BIN
fssc/fssc

Binary file not shown.

32
fssc/internal/handler/webconsole.go

@ -1,6 +1,7 @@
package handler
import (
"fmt"
"fssc/config"
"fssc/internal/util"
"fssc/web"
@ -8,17 +9,34 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
)
// web 控制台
func WebConsole(w http.ResponseWriter, r *http.Request) {
//file flag
isfile := r.URL.Query().Get("file")
// 路径
urlpath := r.URL.Query().Get("p")
upath := strings.TrimSuffix(urlpath, "console")
//文件名
fname := r.URL.Query().Get("f")
//转码
abupath := util.Base64dec(urlpath)
abfname := util.Base64dec(fname)
fmt.Printf("after base64: path: %s,file:%s\n", abupath, abfname)
// url
if isfile == "0" {
abupath = filepath.Join(abupath, abfname)
}
// upath := strings.TrimSuffix(abupath, "console")
// serve download page for send
realFilePath := filepath.Join(config.G.FilePath, upath)
downloadPath := filepath.Join(filepath.Base(config.G.FilePath), r.URL.Path[1:])
realFilePath := filepath.Join(config.G.FilePath, abupath)
downloadPath := filepath.Join(filepath.Base(config.G.FilePath), abupath)
// 相对路径
relpath := filepath.Join(abupath, "../")
//
fileInfo, err := os.Stat(realFilePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@ -32,6 +50,7 @@ func WebConsole(w http.ResponseWriter, r *http.Request) {
IsDir bool
FileName string
DownloadPath string
Relpath string //相对路径
UrlPath string
Files []os.DirEntry
}{
@ -39,8 +58,9 @@ func WebConsole(w http.ResponseWriter, r *http.Request) {
Loip: config.G.LocalIP,
Rundir: config.G.FilePath,
DownloadPath: downloadPath,
UrlPath: strings.TrimSuffix(r.URL.Path, "/"),
// UrlPath: r.URL.Path,
Relpath: relpath,
// UrlPath: strings.TrimSuffix(r.URL.Path, "/"),
UrlPath: abupath,
}
if fileInfo.IsDir() {

3
fssc/main.go

@ -33,8 +33,7 @@ func sendClient() error {
url := fmt.Sprintf("http://%s:%s", config.G.LocalIP, config.G.Port)
fmt.Printf("Server address: %s\n", url)
//http.HandleFunc("/", handler.SendHandler)
//http.Handle("/", http.FS()"/static/vfs")
http.HandleFunc("/", handler.SendHandler)
// ico
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/x-icon")

71
fssc/web/wbconsole.tmpl

@ -2,7 +2,7 @@
<html>
<head>
<title>send file to server</title>
<title>UPSYS console</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">
@ -82,8 +82,12 @@
<!-- Default panel contents -->
<div class="panel-heading">源站({{.Loip}})</div>
<div class="panel-body">
<p>监听目录:{{.DownloadPath}}</p>
<p>相对目录: {{.Rundir}} </p>
<p>监听目录:{{.Rundir}}</p>
<p>相对目录: {{.DownloadPath}}</p>
<p>
<a href="./console" class="btn btn-primary btn-sm">home</a>
<a href="?p={{b64en $.Relpath}}&f=&file=1" class="btn btn-success btn-sm">返回上层</a>
</p>
</div>
<!-- List group -->
@ -95,16 +99,18 @@
{{ if .IsDir }}
<span class="icon folder-icon"></span>
<a href="/up?p={{b64en $.UrlPath }}&f={{b64en .Name }}">{{ .Name }}</a>
<a href="?p={{b64en $.UrlPath}}&f={{b64en .Name }}&file=0">{{ .Name }}</a>
{{ else }}
<span class="icon file-icon"></span>
<a href="/up?p={{b64en $.UrlPath}}&f={{b64en .Name}}">{{ .Name }}</a>
<a href="?p={{b64en $.UrlPath}}&f={{b64en .Name}}&file=1">{{ .Name }}</a>
{{ end }}
</div>
<div class="col-md-4">
<a href="/up?p={{b64en $.UrlPath}}&f={{b64en .Name}}&s={{b64en $.Loip}}" title="更新{{ .Name }}" class="btn btn-primary btn-sm">同步</a>
{{ if .IsDir }} <!-- 空白 --> {{else}}
<a href="/up?p={{b64en $.UrlPath}}&f={{b64en .Name}}&s={{b64en $.Loip}}" title="更新{{ .Name }}" class="btn btn-primary btn-sm">同步</a>
{{end}}
</div>
</li>
{{ end }}
@ -116,25 +122,14 @@
<div class="col-md-6">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">目标站(220.44.660.44)</div>
<div class="panel-heading" id="mbip">目标站</div>
<div class="panel-body">
<p>监听目录:/www</p>
<p>相对目录: /app/common </p>
<p>监听目录:<span id="sc01"></span></p>
<p>相对目录: <span id="sc02"></span> </p>
</div>
<!-- List group -->
<ul class="list-group">
<li class="list-group-item optzone">
<div class="col-md-8">Cras justo odio</div>
<div class="col-md-4">
<a href="#" class="btn btn-primary btn-sm">同步</a>
<a href="#" class="btn btn-success btn-sm">复制</a></a>
</div>
</li>
<li class="list-group-item">Dapibus ac facilisis in</li>
<li class="list-group-item">Morbi leo risus</li>
<li class="list-group-item">Porta ac consectetur ac</li>
<li class="list-group-item">Vestibulum at eros</li>
<ul class="list-group" id="tgsc">
</ul>
</div>
</div>
@ -154,15 +149,47 @@
<script type="text/javascript">
$(function(){
// 获取ip
// click function
$("#entsip").on("click",function(){
//
var sip = $("#scip").val();
var html = "<li class=\"list-group-item\">输入目标服务器"+sip+"</li>";
// 目标站
$("#mbip").text("目标站("+sip+")");
// 获取信息
gescinfo(sip)
//
$("#rstatus").append(html)
})
// 获取目标服务器的信息
var gescinfo=function(scip){
var url="http://"+scip+":9099/sc?callback"
var html="";
$.getJSON(url,function(res){
// res.curdir
$.each(res.data.list,function(k,v){
html+="<li class=\"list-group-item optzone\"><div class=\"col-md-8\">";
if(v.dirflag){
html +="<span class=\"icon folder-icon\"></span>"+v.fname;
}else{
html +="<span class=\"icon file-icon\"></span>"+v.fname;
}
html+="</div><div class=\"col-md-4\"><a href=\"#\" class=\"btn btn-primary btn-sm\">同步</a></div></li>";
})
// append to html
$("#tgsc").html(html)
writelog(scip+"获取数据:"+res.data.list.length+"条数据" )
$("#sc01").text(res.curdir);
});
}
// write log
var writelog=function(html){
var hprex="<li class=\"list-group-item\">"+html+"</li>";
$("#rstatus").append(hprex)
}
});
</script>
</body>

Loading…
Cancel
Save