Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
shenyizhong
/
minsync
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e4582977
authored
Dec 24, 2021
by
shenyizhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* download files
1 parent
c664042b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
8 deletions
src/httpcli/httpcli.go
src/main.go
src/nodetree/nodetree.go
src/travloc/travloc.go
src/travremot/travremot.go
src/httpcli/httpcli.go
View file @
e458297
...
...
@@ -52,7 +52,7 @@ func Update(postdata string) ([]byte, error) {
return
nil
,
nil
}
func
Mkdir
(
path
string
)
{
func
Mkdir
Remot
(
path
string
)
{
var
tmpStrs
=
strings
.
Split
(
path
,
nodetree
.
StrSrc
)
if
len
(
tmpStrs
)
<
2
{
...
...
@@ -94,7 +94,8 @@ func Upload(node *nodetree.NodeLoc) {
url
+=
host
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
url
+=
"/front/data/upload?name=data"
url
+=
"/front/data/upload?name="
url
+=
nodetree
.
StrDst
url
+=
tmpStrs
[
1
]
log
.
Println
(
"httpcli.Upload() called, GET request:"
,
url
)
...
...
@@ -151,3 +152,72 @@ func Upload(node *nodetree.NodeLoc) {
log
.
Println
(
string
(
opBytes
))
}
}
func
MkdirLoc
(
path
string
)
{
tmpStrs
:=
strings
.
Split
(
path
,
nodetree
.
StrSrc
)
if
len
(
tmpStrs
)
>
1
{
strDir
:=
nodetree
.
StrDst
+
"/"
strDir
+=
tmpStrs
[
1
]
err
:=
os
.
Mkdir
(
strDir
,
0775
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
}
}
func
Download
(
node
*
nodetree
.
NodeRemot
)
{
tmpStrs
:=
strings
.
Split
(
node
.
Name
,
nodetree
.
StrSrc
)
if
len
(
tmpStrs
)
<
2
{
return
}
// "/front/data/download?name=data/folder3/ddd.txt"
url
:=
"http://"
url
+=
host
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
url
+=
"/front/data/download?name="
url
+=
nodetree
.
StrSrc
url
+=
tmpStrs
[
1
]
log
.
Println
(
"httpcli.Download() called, GET request:"
,
url
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
var
resp
*
http
.
Response
resp
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
jsonRes
nodetree
.
DownloadFile
json
.
Unmarshal
(
body
,
&
jsonRes
)
strDstFile
:=
nodetree
.
StrDst
+
"/"
strDstFile
+=
tmpStrs
[
1
]
strCmd01
:=
strDstFile
strCmd02
:=
"
\"
"
+
jsonRes
.
Data
.
Url
+
"
\"
"
cmd
:=
exec
.
Command
(
"wget"
,
"-O"
,
strCmd01
,
strCmd02
)
stdout
,
err
:=
cmd
.
StdoutPipe
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
stdout
.
Close
()
if
err
:=
cmd
.
Start
();
err
!=
nil
{
log
.
Fatal
(
err
)
}
if
opBytes
,
err
:=
ioutil
.
ReadAll
(
stdout
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
else
{
fmt
.
Printf
(
"File download successful : [%v] -> [%v]
\n
"
,
node
.
Name
,
strDstFile
)
log
.
Println
(
string
(
opBytes
))
}
}
src/main.go
View file @
e458297
...
...
@@ -59,6 +59,7 @@ func main() {
}
if
nodetree
.
StrOp
==
"upload"
{
nodetree
.
StrDst
=
"data"
+
nodetree
.
StrDst
var
option_loc
nodetree
.
OptionLoc
option_loc
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
...
...
@@ -77,9 +78,10 @@ func main() {
//out_loc.WriteTo(os.Stdout)
}
else
if
nodetree
.
StrOp
==
"download"
{
nodetree
.
StrSrc
=
"data"
+
nodetree
.
StrSrc
var
option_remot
nodetree
.
OptionRemot
option_remot
.
RootPath
=
[]
string
{
"data/"
}
option_remot
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
resp_remot
,
_
:=
travremot
.
Explorer
(
option_remot
)
b_remot
,
err
:=
json
.
Marshal
(
resp_remot
)
...
...
src/nodetree/nodetree.go
View file @
e458297
...
...
@@ -71,6 +71,15 @@ type UploadFile struct {
Msg
string
`json:"msg"`
}
type
DownloadFileData
struct
{
Url
string
`json:"url"`
}
type
DownloadFile
struct
{
Data
DownloadFileData
`json:"data"`
Msg
string
`json:"msg"`
}
type
Task
struct
{
Id
string
`json:"id"`
Progress
int
`json:"progress"`
...
...
src/travloc/travloc.go
View file @
e458297
...
...
@@ -65,7 +65,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str
if
f
.
IsDir
()
{
// mkdir remot
httpcli
.
Mkdir
(
child
.
Path
)
httpcli
.
Mkdir
Remot
(
child
.
Path
)
if
option
.
SubFlag
{
if
!
IsInSlice
(
option
.
IgnorePath
,
f
.
Name
())
{
...
...
src/travremot/travremot.go
View file @
e458297
...
...
@@ -2,9 +2,11 @@ package travremot
import
(
"encoding/json"
_
"fmt"
"io/ioutil"
"log"
"minsync/auth"
"minsync/httpcli"
"minsync/nodetree"
"net/http"
"os"
...
...
@@ -55,12 +57,12 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
log
.
Printf
(
"travremot.exploreRecursive() node.Name: %s"
,
node
.
Name
)
// "http://122.112.207.59:8989/front/data/query_list?pages=1&pagesize=20&prefix="
// "http://122.112.207.59:8989/front/data/query_list?pages=1&pagesize=20
0
&prefix="
url
:=
"http://"
url
+=
host
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
url
+=
"/front/data/query_list?pages=1&pagesize=20&prefix="
url
+=
"/front/data/query_list?pages=1&pagesize=20
0
&prefix="
url
+=
node
.
Name
log
.
Println
(
url
)
...
...
@@ -79,20 +81,29 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
json
.
Unmarshal
(
body
,
&
jsonRes
)
for
_
,
f
:=
range
jsonRes
.
Data
.
List
{
tmp
:=
node
.
Name
+
f
.
Name
var
child
nodetree
.
NodeRemot
child
.
Name
=
tmp
child
.
Type
=
f
.
Type
child
.
UpdtDate
=
f
.
UpdtDate
child
.
Creator
=
f
.
Creator
child
.
Size
=
f
.
Size
tmp
:=
node
.
Name
+
f
.
Name
child
.
Name
=
tmp
if
f
.
Type
==
"folder"
{
child
.
Name
+=
"/"
// mkdir
httpcli
.
MkdirLoc
(
child
.
Name
)
node
.
Children
=
append
(
node
.
Children
,
&
child
)
exploreRecursive
(
&
child
,
option
)
}
else
if
f
.
Type
==
"file"
{
// download
httpcli
.
Download
(
&
child
)
node
.
Children
=
append
(
node
.
Children
,
&
child
)
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment