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
Show 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) {
...
@@ -52,7 +52,7 @@ func Update(postdata string) ([]byte, error) {
return
nil
,
nil
return
nil
,
nil
}
}
func
Mkdir
(
path
string
)
{
func
Mkdir
Remot
(
path
string
)
{
var
tmpStrs
=
strings
.
Split
(
path
,
nodetree
.
StrSrc
)
var
tmpStrs
=
strings
.
Split
(
path
,
nodetree
.
StrSrc
)
if
len
(
tmpStrs
)
<
2
{
if
len
(
tmpStrs
)
<
2
{
...
@@ -94,7 +94,8 @@ func Upload(node *nodetree.NodeLoc) {
...
@@ -94,7 +94,8 @@ func Upload(node *nodetree.NodeLoc) {
url
+=
host
url
+=
host
url
+=
":"
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
url
+=
strconv
.
Itoa
(
port
)
url
+=
"/front/data/upload?name=data"
url
+=
"/front/data/upload?name="
url
+=
nodetree
.
StrDst
url
+=
tmpStrs
[
1
]
url
+=
tmpStrs
[
1
]
log
.
Println
(
"httpcli.Upload() called, GET request:"
,
url
)
log
.
Println
(
"httpcli.Upload() called, GET request:"
,
url
)
...
@@ -151,3 +152,72 @@ func Upload(node *nodetree.NodeLoc) {
...
@@ -151,3 +152,72 @@ func Upload(node *nodetree.NodeLoc) {
log
.
Println
(
string
(
opBytes
))
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() {
...
@@ -59,6 +59,7 @@ func main() {
}
}
if
nodetree
.
StrOp
==
"upload"
{
if
nodetree
.
StrOp
==
"upload"
{
nodetree
.
StrDst
=
"data"
+
nodetree
.
StrDst
var
option_loc
nodetree
.
OptionLoc
var
option_loc
nodetree
.
OptionLoc
option_loc
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
option_loc
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
...
@@ -77,9 +78,10 @@ func main() {
...
@@ -77,9 +78,10 @@ func main() {
//out_loc.WriteTo(os.Stdout)
//out_loc.WriteTo(os.Stdout)
}
else
if
nodetree
.
StrOp
==
"download"
{
}
else
if
nodetree
.
StrOp
==
"download"
{
nodetree
.
StrSrc
=
"data"
+
nodetree
.
StrSrc
var
option_remot
nodetree
.
OptionRemot
var
option_remot
nodetree
.
OptionRemot
option_remot
.
RootPath
=
[]
string
{
"data/"
}
option_remot
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
resp_remot
,
_
:=
travremot
.
Explorer
(
option_remot
)
resp_remot
,
_
:=
travremot
.
Explorer
(
option_remot
)
b_remot
,
err
:=
json
.
Marshal
(
resp_remot
)
b_remot
,
err
:=
json
.
Marshal
(
resp_remot
)
...
...
src/nodetree/nodetree.go
View file @
e458297
...
@@ -71,6 +71,15 @@ type UploadFile struct {
...
@@ -71,6 +71,15 @@ type UploadFile struct {
Msg
string
`json:"msg"`
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
{
type
Task
struct
{
Id
string
`json:"id"`
Id
string
`json:"id"`
Progress
int
`json:"progress"`
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
...
@@ -65,7 +65,7 @@ func exploreRecursive(node *nodetree.NodeLoc, option *nodetree.OptionLoc, op str
if
f
.
IsDir
()
{
if
f
.
IsDir
()
{
// mkdir remot
// mkdir remot
httpcli
.
Mkdir
(
child
.
Path
)
httpcli
.
Mkdir
Remot
(
child
.
Path
)
if
option
.
SubFlag
{
if
option
.
SubFlag
{
if
!
IsInSlice
(
option
.
IgnorePath
,
f
.
Name
())
{
if
!
IsInSlice
(
option
.
IgnorePath
,
f
.
Name
())
{
...
...
src/travremot/travremot.go
View file @
e458297
...
@@ -2,9 +2,11 @@ package travremot
...
@@ -2,9 +2,11 @@ package travremot
import
(
import
(
"encoding/json"
"encoding/json"
_
"fmt"
"io/ioutil"
"io/ioutil"
"log"
"log"
"minsync/auth"
"minsync/auth"
"minsync/httpcli"
"minsync/nodetree"
"minsync/nodetree"
"net/http"
"net/http"
"os"
"os"
...
@@ -55,12 +57,12 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
...
@@ -55,12 +57,12 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
log
.
Printf
(
"travremot.exploreRecursive() node.Name: %s"
,
node
.
Name
)
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
:=
"http://"
url
+=
host
url
+=
host
url
+=
":"
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
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
url
+=
node
.
Name
log
.
Println
(
url
)
log
.
Println
(
url
)
...
@@ -79,20 +81,29 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
...
@@ -79,20 +81,29 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
json
.
Unmarshal
(
body
,
&
jsonRes
)
json
.
Unmarshal
(
body
,
&
jsonRes
)
for
_
,
f
:=
range
jsonRes
.
Data
.
List
{
for
_
,
f
:=
range
jsonRes
.
Data
.
List
{
tmp
:=
node
.
Name
+
f
.
Name
var
child
nodetree
.
NodeRemot
var
child
nodetree
.
NodeRemot
child
.
Name
=
tmp
child
.
Type
=
f
.
Type
child
.
Type
=
f
.
Type
child
.
UpdtDate
=
f
.
UpdtDate
child
.
UpdtDate
=
f
.
UpdtDate
child
.
Creator
=
f
.
Creator
child
.
Creator
=
f
.
Creator
child
.
Size
=
f
.
Size
child
.
Size
=
f
.
Size
tmp
:=
node
.
Name
+
f
.
Name
child
.
Name
=
tmp
if
f
.
Type
==
"folder"
{
if
f
.
Type
==
"folder"
{
child
.
Name
+=
"/"
child
.
Name
+=
"/"
// mkdir
httpcli
.
MkdirLoc
(
child
.
Name
)
node
.
Children
=
append
(
node
.
Children
,
&
child
)
node
.
Children
=
append
(
node
.
Children
,
&
child
)
exploreRecursive
(
&
child
,
option
)
exploreRecursive
(
&
child
,
option
)
}
else
if
f
.
Type
==
"file"
{
}
else
if
f
.
Type
==
"file"
{
// download
httpcli
.
Download
(
&
child
)
node
.
Children
=
append
(
node
.
Children
,
&
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