Browse Source

文件升级管理端

master
453530270@qq.com 2 years ago
parent
commit
728f6c2a84
  1. 9
      fssc/go.mod
  2. 21
      fssc/go.sum
  3. 4
      fssc/internal/discovery/discovery.go
  4. 13
      fssc/internal/handler/handler.go
  5. 3
      fssc/internal/transfer/send.go
  6. 11
      fssc/main.go
  7. 10
      fssc/web/embed.go
  8. 195
      fssc/web/list.tmpl
  9. 1
      fssc/web/static/css/bootstrap.css
  10. 36
      fssc/web/static/css/jquery.fileupload.css
  11. 97
      fssc/web/static/css/upload.css
  12. 54
      fssc/web/static/images/folder.svg
  13. 1
      fssc/web/static/images/php.svg
  14. 63
      fssc/web/static/images/txt.svg
  15. BIN
      fssc/web/static/images/zip.png
  16. 7
      fssc/web/static/js/bootstrap.min.js
  17. 4
      fssc/web/static/js/jquery-2.1.3.min.js
  18. 4
      fssc/web/static/js/jquery.min.js

9
fssc/go.mod

@ -2,10 +2,17 @@ module fssc
go 1.22.1
require github.com/urfave/cli/v2 v2.27.2
require (
github.com/schollz/progressbar/v3 v3.14.4
github.com/urfave/cli/v2 v2.27.2
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
)

21
fssc/go.sum

@ -1,8 +1,29 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.14.4 h1:W9ZrDSJk7eqmQhd3uxFNNcTr0QL+xuGNI9dEMrw0r74=
github.com/schollz/progressbar/v3 v3.14.4/go.mod h1:aT3UQ7yGm+2ZjeXPqsjTenwL3ddUiuZ0kfQ/2tHlyNI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=

4
fssc/internal/discovery/discovery.go

@ -5,8 +5,8 @@ import (
"net"
"strings"
"github.com/chyok/st/config"
"github.com/chyok/st/internal/transfer"
"fssc/config"
"fssc/internal/transfer"
)
const separator = "|"

13
fssc/internal/handler/handler.go

@ -16,10 +16,10 @@ import (
"os"
"path/filepath"
"github.com/chyok/st/config"
"github.com/chyok/st/internal/transfer"
"github.com/chyok/st/internal/util"
"github.com/chyok/st/web"
"fssc/config"
"fssc/internal/transfer"
"fssc/internal/util"
"fssc/web"
)
// rpc功能 压缩包的结构体
@ -347,11 +347,8 @@ func SendHandler(w http.ResponseWriter, r *http.Request) {
data.FileName = filepath.Base(realFilePath)
}
//
fmt.Print("fdata:%v", data)
// 文件列表模板
tmpl, err := template.New("download").Parse(web.DownloadPage)
tmpl, err := template.New("list").Parse(web.ListPage)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

3
fssc/internal/transfer/send.go

@ -11,7 +11,8 @@ import (
"path/filepath"
"strings"
"github.com/chyok/st/internal/util"
"fssc/internal/util"
"github.com/schollz/progressbar/v3"
)

11
fssc/main.go

@ -1,4 +1,4 @@
package fssc
package main
import (
"fmt"
@ -8,10 +8,16 @@ import (
"path/filepath"
"fssc/internal/discovery"
"fssc/internal/handler"
"fssc/web"
"github.com/urfave/cli/v2"
)
var (
port string
)
// 初始化配置
func initConfig(c *cli.Context) error {
return config.G.SetConf(port)
@ -71,6 +77,9 @@ func main() {
currentPath := filepath.ToSlash(c.Args().Get(0))
config.G.FilePath = currentPath
return sendClient()
} else {
fmt.Println("no input args")
return nil
}
//return receiveClient()
},

10
fssc/web/embed.go

@ -0,0 +1,10 @@
package web
import "embed"
//go:embed static
// var CssFs embed.FS
var StaticFs embed.FS
//go:embed list.tmpl
var ListPage string

195
fssc/web/list.tmpl

@ -0,0 +1,195 @@
<!DOCTYPE html>
<html>
<head>
<title>File Transfer</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
.container {
max-width: 1000px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.center {
text-align: center;
}
h1, h2 {
text-align: center;
color: #333;
font-size: 2rem;
}
ul {
list-style-type: none;
padding: 0;
}
li {
padding: 10px;
border-bottom: 1px solid #ddd;
display: flex;
align-items: center;
font-size: 1.2rem;
}
li:last-child {
border-bottom: none;
}
a {
text-decoration: none;
color: #333;
}
.btn {
display: inline-block;
padding: 8px 16px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
margin-left: auto;
}
.btn:hover {
background-color: #0056b3;
}
.tips{
display:block;
text-align:right;
color:#ddd;
line-height:1.8;
margin-left:32px;
font-size:14px;
}
.folder-icon {
width: 24px;
height: 24px;
margin-right: 10px;
color:#ce911e;
}
.file-icon {
width: 24px;
height: 24px;
margin-right: 10px;
color:#a29c8d;
}
@media (max-width: 600px) {
.container {
padding: 10px;
}
}
</style>
<link rel="stylesheet" href="/static/static/css/bootstrap.css">
<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="container">
<p>主机名:{{ .DeviceName }}</p>
<hr>
{{ if .IsDir }}
<h2>{{ .DownloadPath }}</h2>
<form action="/sendZip" method="post" class="form-inline">
<div class="row">
<p class="lead">运行目录:{{ .DownloadPath }}</p>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<input id="all" class="form-control" type="checkbox"> 全选
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label for="sip">服务器ip</label>
<input type="text" name="serverip" class="form-control" id="sip" placeholder="eg:192.168.66.100:9099">
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label>相对路径</label>
<input type="text" class="form-control" disabled="disabled" name="curpath" value="{{ .UrlPath }}"/>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<button class="btn btn-primary" type="submit">以压缩包模式发送文件</button>
<a class="btn btn-primary" type="buttton">单文件模式发送</a>
</div>
</div>
<div class="row">
<ul>
{{ range .Files }}
<li>
<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>
{{ .Name }} <span class="tips">{{.Info.Size}}</span><span class="tips"> {{.Info.ModTime.Format "2006-01-02 15:04:05"}} </span>
{{ end }}
</li>
{{ end }}
</ul>
{{ end }}
</form>
</div>
</div>
<script>
var chkall = true;
var chknum=0;
$(function () {
//全选按钮设置点击事件
$("#all").click(function () {
//1、循环设置其它多选框选中状态,跟标识用的变量一样
$(".mfile").prop("checked", chkall);
// down button toggle
if(chkall ||chknum>2){
$("#tropt").show()
chknum +=1
}else{
$("#tropt").hide()
chknum -=1
}
//2、标识的变量取反
chkall = !chkall;
})
})
</script>
</body>
</html>

1
fssc/web/static/css/bootstrap.css

File diff suppressed because one or more lines are too long

36
fssc/web/static/css/jquery.fileupload.css

@ -0,0 +1,36 @@
@charset "UTF-8";
/*
* jQuery File Upload Plugin CSS 1.3.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
.fileinput-button {
position: relative;
overflow: hidden;
}
.fileinput-button input {
position: absolute;
top: 0;
right: 0;
margin: 0;
opacity: 0;
-ms-filter: 'alpha(opacity=0)';
font-size: 200px;
direction: ltr;
cursor: pointer;
}
/* Fixes for IE < 8 */
@media screen\9 {
.fileinput-button input {
filter: alpha(opacity=0);
font-size: 100%;
height: 100%;
}
}

97
fssc/web/static/css/upload.css

@ -0,0 +1,97 @@
.row-file {
height: 40px;
}
.column-icon {
width: 40px;
text-align: center;
}
.column-name {
}
.column-size {
width: 100px;
text-align: right;
}
.column-move {
width: 40px;
text-align: center;
}
.column-delete {
width: 40px;
text-align: center;
}
.column-path {
}
.column-progress {
width: 200px;
}
.footer {
color: #999;
text-align: center;
font-size: 0.9em;
}
#reload {
float: right;
}
#create-input {
width: 50%;
height: 20px;
}
#move-input {
width: 80%;
height: 20px;
}
/* Bootstrap overrides */
.btn:focus {
outline: none;
}
.btn-toolbar {
margin-top: 30px;
margin-bottom: 20px;
}
.table .progress {
margin-top: 0px;
margin-bottom: 0px;
height: 16px;
}
.panel-default > .panel-heading {
color: #555;
}
.breadcrumb {
background-color: transparent;
border-radius: 0px;
margin-bottom: 0px;
padding: 0px;
}
.breadcrumb > .active {
color: #555;
}
.breadcrumb > li + li:before {
color: #999;
}
.table > tbody > tr > td {
vertical-align: middle;
}
.table > tbody > tr > td > p {
margin: 0px;
}

54
fssc/web/static/images/folder.svg

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="64px" height="60.001px" viewBox="0 0 64 60.001" style="enable-background:new 0 0 64 60.001;" xml:space="preserve">
<g id="Folder">
<g>
<path style="fill-rule:evenodd;clip-rule:evenodd;fill:#CCA352;" d="M60,4.001H24C24,1.792,22.209,0,20,0H4
C1.791,0,0,1.792,0,4.001V8v6.001v2c0,2.209,1.791,4,4,4h56c2.209,0,4-1.791,4-4V8C64,5.791,62.209,4.001,60,4.001z"/>
</g>
</g>
<g id="File_1_">
<g>
<path style="fill:#FFFFFF;" d="M56,8H8c-2.209,0-4,1.791-4,4.001v4c0,2.209,1.791,4,4,4h48c2.209,0,4-1.791,4-4v-4
C60,9.791,58.209,8,56,8z"/>
</g>
</g>
<g id="Folder_1_">
<g>
<path style="fill:#FFCC66;" d="M60,12.001H4c-2.209,0-4,1.791-4,4v40c0,2.209,1.791,4,4,4h56c2.209,0,4-1.791,4-4v-40
C64,13.792,62.209,12.001,60,12.001z"/>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

1
fssc/web/static/images/php.svg

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.5 KiB

63
fssc/web/static/images/txt.svg

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 56 56" style="enable-background:new 0 0 56 56;" xml:space="preserve">
<g>
<path style="fill:#E9E9E0;" d="M36.985,0H7.963C7.155,0,6.5,0.655,6.5,1.926V55c0,0.345,0.655,1,1.463,1h40.074
c0.808,0,1.463-0.655,1.463-1V12.978c0-0.696-0.093-0.92-0.257-1.085L37.607,0.257C37.442,0.093,37.218,0,36.985,0z"/>
<polygon style="fill:#D9D7CA;" points="37.5,0.151 37.5,12 49.349,12 "/>
<path style="fill:#95A5A5;" d="M48.037,56H7.963C7.155,56,6.5,55.345,6.5,54.537V39h43v15.537C49.5,55.345,48.845,56,48.037,56z"/>
<g>
<path style="fill:#FFFFFF;" d="M21.867,42.924v1.121h-3.008V53h-1.654v-8.955h-3.008v-1.121H21.867z"/>
<path style="fill:#FFFFFF;" d="M28.443,48.105L31,53h-1.9l-1.6-3.801h-0.137L25.641,53h-1.9l2.557-4.895l-2.721-5.182h1.873
l1.777,4.102h0.137l1.928-4.102h1.873L28.443,48.105z"/>
<path style="fill:#FFFFFF;" d="M40.529,42.924v1.121h-3.008V53h-1.654v-8.955h-3.008v-1.121H40.529z"/>
</g>
<path style="fill:#C8BDB8;" d="M18.5,13h-6c-0.553,0-1-0.448-1-1s0.447-1,1-1h6c0.553,0,1,0.448,1,1S19.053,13,18.5,13z"/>
<path style="fill:#C8BDB8;" d="M21.5,18h-9c-0.553,0-1-0.448-1-1s0.447-1,1-1h9c0.553,0,1,0.448,1,1S22.053,18,21.5,18z"/>
<path style="fill:#C8BDB8;" d="M25.5,18c-0.26,0-0.521-0.11-0.71-0.29c-0.181-0.19-0.29-0.44-0.29-0.71s0.109-0.52,0.3-0.71
c0.36-0.37,1.04-0.37,1.41,0c0.18,0.19,0.29,0.45,0.29,0.71c0,0.26-0.11,0.52-0.29,0.71C26.02,17.89,25.76,18,25.5,18z"/>
<path style="fill:#C8BDB8;" d="M37.5,18h-8c-0.553,0-1-0.448-1-1s0.447-1,1-1h8c0.553,0,1,0.448,1,1S38.053,18,37.5,18z"/>
<path style="fill:#C8BDB8;" d="M12.5,33c-0.26,0-0.521-0.11-0.71-0.29c-0.181-0.19-0.29-0.45-0.29-0.71
c0-0.26,0.109-0.52,0.29-0.71c0.37-0.37,1.05-0.37,1.42,0.01c0.18,0.18,0.29,0.44,0.29,0.7c0,0.26-0.11,0.52-0.29,0.71
C13.02,32.89,12.76,33,12.5,33z"/>
<path style="fill:#C8BDB8;" d="M24.5,33h-8c-0.553,0-1-0.448-1-1s0.447-1,1-1h8c0.553,0,1,0.448,1,1S25.053,33,24.5,33z"/>
<path style="fill:#C8BDB8;" d="M43.5,18h-2c-0.553,0-1-0.448-1-1s0.447-1,1-1h2c0.553,0,1,0.448,1,1S44.053,18,43.5,18z"/>
<path style="fill:#C8BDB8;" d="M34.5,23h-22c-0.553,0-1-0.448-1-1s0.447-1,1-1h22c0.553,0,1,0.448,1,1S35.053,23,34.5,23z"/>
<path style="fill:#C8BDB8;" d="M43.5,23h-6c-0.553,0-1-0.448-1-1s0.447-1,1-1h6c0.553,0,1,0.448,1,1S44.053,23,43.5,23z"/>
<path style="fill:#C8BDB8;" d="M16.5,28h-4c-0.553,0-1-0.448-1-1s0.447-1,1-1h4c0.553,0,1,0.448,1,1S17.053,28,16.5,28z"/>
<path style="fill:#C8BDB8;" d="M30.5,28h-10c-0.553,0-1-0.448-1-1s0.447-1,1-1h10c0.553,0,1,0.448,1,1S31.053,28,30.5,28z"/>
<path style="fill:#C8BDB8;" d="M43.5,28h-9c-0.553,0-1-0.448-1-1s0.447-1,1-1h9c0.553,0,1,0.448,1,1S44.053,28,43.5,28z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
fssc/web/static/images/zip.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

7
fssc/web/static/js/bootstrap.min.js

File diff suppressed because one or more lines are too long

4
fssc/web/static/js/jquery-2.1.3.min.js

File diff suppressed because one or more lines are too long

4
fssc/web/static/js/jquery.min.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save