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 76bb4781
authored
Jan 05, 2022
by
shenyizhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* support pages
1 parent
78a96136
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
9 deletions
src/httpcli/httpcli.go
src/main.go
src/travremot/travremot.go
src/httpcli/httpcli.go
View file @
76bb478
...
...
@@ -154,16 +154,32 @@ func Upload(node *nodetree.NodeLoc) {
}
}
func
PathExists
(
path
string
)
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
path
)
if
err
==
nil
{
return
true
,
nil
}
if
os
.
IsNotExist
(
err
)
{
return
false
,
nil
}
return
false
,
err
}
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
)
exist
,
err
:=
PathExists
(
strDir
)
if
!
exist
{
err
=
os
.
Mkdir
(
strDir
,
0775
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
}
}
}
func
Download
(
node
*
nodetree
.
NodeRemot
)
{
...
...
src/main.go
View file @
76bb478
...
...
@@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
_
"io/ioutil"
"io/ioutil"
"log"
_
"minsync/auth"
_
"minsync/download"
...
...
@@ -25,7 +25,7 @@ func printUsage() {
func
main
()
{
fmt
.
Println
(
"minsync v0.0.1
"
)
fmt
.
Println
(
"minsync v0.0.2
"
)
// minsync --token ef0c26da821c upload /home/syz/tmp/abc /part1/box2
if
len
(
os
.
Args
)
<
6
{
...
...
@@ -51,11 +51,31 @@ func main() {
}
fmt
.
Printf
(
"%v %v %v %v
\n
"
,
nodetree
.
StrToken
,
nodetree
.
StrOp
,
nodetree
.
StrSrc
,
nodetree
.
StrDst
)
// check dst format
if
nodetree
.
StrDst
[
len
(
nodetree
.
StrDst
)
-
1
:
]
!=
"/"
{
fmt
.
Printf
(
"target path [%v] format error, need end with /
\n
"
,
nodetree
.
StrDst
)
return
}
if
nodetree
.
StrSrc
[
len
(
nodetree
.
StrSrc
)
-
1
:
]
!=
"/"
{
fmt
.
Printf
(
"source path [%v] format error, need end with /
\n
"
,
nodetree
.
StrSrc
)
return
}
_
,
err
:=
os
.
Lstat
(
nodetree
.
StrToken
)
if
!
os
.
IsNotExist
(
err
)
{
data
,
err
:=
ioutil
.
ReadFile
(
nodetree
.
StrToken
)
if
err
!=
nil
{
return
}
nodetree
.
StrToken
=
string
(
data
)
}
file
,
_
:=
os
.
Open
(
"./config.json"
)
defer
file
.
Close
()
decoder
:=
json
.
NewDecoder
(
file
)
conf
:=
nodetree
.
Configuration
{}
err
:
=
decoder
.
Decode
(
&
conf
)
err
=
decoder
.
Decode
(
&
conf
)
if
err
!=
nil
{
log
.
Println
(
"Error:"
,
err
)
}
...
...
@@ -63,6 +83,8 @@ func main() {
if
nodetree
.
StrOp
==
"upload"
{
nodetree
.
StrDst
=
"data"
+
nodetree
.
StrDst
// TODO, check if nodetree.StrDst is FILE or DIR
var
option_loc
nodetree
.
OptionLoc
option_loc
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
option_loc
.
SubFlag
=
true
...
...
@@ -82,6 +104,8 @@ func main() {
}
else
if
nodetree
.
StrOp
==
"download"
{
nodetree
.
StrSrc
=
"data"
+
nodetree
.
StrSrc
// TODO, check if nodetree.StrDst is FILE or DIR
var
option_remot
nodetree
.
OptionRemot
option_remot
.
RootPath
=
[]
string
{
nodetree
.
StrSrc
}
resp_remot
,
_
:=
travremot
.
Explorer
(
option_remot
)
...
...
src/travremot/travremot.go
View file @
76bb478
...
...
@@ -58,13 +58,13 @@ 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=200&prefix="
url
:=
"http://"
url
+=
host
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
url
+=
"/front/data/query_list?pages=1&pagesize=
200
&prefix="
url
+=
"/front/data/query_list?pages=1&pagesize=
1
&prefix="
url
+=
node
.
Name
log
.
Println
(
url
)
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
...
...
@@ -74,13 +74,39 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
if
err
!=
nil
{
log
.
Println
(
err
)
}
defer
resp
.
Body
.
Close
()
body
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
jsonRes
nodetree
.
DataRemot
json
.
Unmarshal
(
body
,
&
jsonRes
)
for
_
,
f
:=
range
jsonRes
.
Data
.
List
{
url
=
"http://"
url
+=
host
url
+=
":"
url
+=
strconv
.
Itoa
(
port
)
url
+=
"/front/data/query_list?pages=1&pagesize="
url
+=
strconv
.
Itoa
(
jsonRes
.
Data
.
Total
)
url
+=
"&prefix="
url
+=
node
.
Name
log
.
Println
(
url
)
req
,
_
=
http
.
NewRequest
(
"GET"
,
url
,
nil
)
req
.
Header
.
Add
(
"token"
,
auth
.
GetToken
())
var
respAll
*
http
.
Response
respAll
,
err
=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
defer
respAll
.
Body
.
Close
()
bodyAll
,
_
:=
ioutil
.
ReadAll
(
respAll
.
Body
)
var
jsonResAll
nodetree
.
DataRemot
json
.
Unmarshal
(
bodyAll
,
&
jsonResAll
)
for
_
,
f
:=
range
jsonResAll
.
Data
.
List
{
var
child
nodetree
.
NodeRemot
child
.
Type
=
f
.
Type
...
...
@@ -108,6 +134,4 @@ func exploreRecursive(node *nodetree.NodeRemot, option *nodetree.OptionRemot) {
}
}
defer
resp
.
Body
.
Close
()
}
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