Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
a5ed1103
Commit
a5ed1103
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
some cleanup
parent
0e12d396
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/v1/api_uploads.go
+64
-40
64 additions, 40 deletions
api/v1/api_uploads.go
with
64 additions
and
40 deletions
api/v1/api_uploads.go
+
64
−
40
View file @
a5ed1103
...
@@ -246,6 +246,15 @@ func getOrNewFlowJSFile(job *importer.Job, flowId string, chunk, totalChunks, to
...
@@ -246,6 +246,15 @@ func getOrNewFlowJSFile(job *importer.Job, flowId string, chunk, totalChunks, to
//***
//***
const
(
FlowJSParamID
string
=
"flowIdentifier"
FlowJSParamChunk
string
=
"flowChunkNumber"
FlowJSParamTotalChunks
string
=
"flowTotalChunks"
FlowJSParamCurrentChunkSize
string
=
"flowCurrentChunkSize"
FlowJSParamTotalSize
string
=
"flowTotalSize"
FlowJSParamFile
string
=
"file"
)
func
getFlowJSParameterFromMultipart
(
r
*
http
.
Request
)
(
id
string
,
chunk
,
totalChunks
,
chunkSize
,
totalSize
uint64
,
data
io
.
Reader
,
err
error
)
{
func
getFlowJSParameterFromMultipart
(
r
*
http
.
Request
)
(
id
string
,
chunk
,
totalChunks
,
chunkSize
,
totalSize
uint64
,
data
io
.
Reader
,
err
error
)
{
var
mr
*
multipart
.
Reader
var
mr
*
multipart
.
Reader
if
mr
,
err
=
r
.
MultipartReader
();
err
!=
nil
{
if
mr
,
err
=
r
.
MultipartReader
();
err
!=
nil
{
...
@@ -263,7 +272,7 @@ func getFlowJSParameterFromMultipart(r *http.Request) (id string, chunk, totalCh
...
@@ -263,7 +272,7 @@ func getFlowJSParameterFromMultipart(r *http.Request) (id string, chunk, totalCh
}
}
pn
:=
p
.
FormName
()
pn
:=
p
.
FormName
()
if
pn
==
"f
ile
"
{
if
pn
==
FlowJSParamF
ile
{
data
=
p
data
=
p
break
break
}
}
...
@@ -272,51 +281,89 @@ func getFlowJSParameterFromMultipart(r *http.Request) (id string, chunk, totalCh
...
@@ -272,51 +281,89 @@ func getFlowJSParameterFromMultipart(r *http.Request) (id string, chunk, totalCh
return
return
}
}
switch
pn
{
switch
pn
{
case
"f
low
Identifier"
:
case
F
low
JSParamID
:
id
=
string
(
pd
)
id
=
string
(
pd
)
case
"f
low
ChunkNumber"
:
case
F
low
JSParamChunk
:
if
chunk
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
if
chunk
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid parameter '
flowChunkNumber': "
+
err
.
Error
())
err
=
fmt
.
Errorf
(
"invalid parameter '
%s': %v"
,
FlowJSParamChunk
,
err
.
Error
())
return
return
}
}
case
"f
lowTotalChunks
"
:
case
F
low
JSParam
TotalChunks
:
if
totalChunks
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
if
totalChunks
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid parameter '
flow
TotalChunk
': "
+
err
.
Error
())
err
=
fmt
.
Errorf
(
"invalid parameter '
%s': %v"
,
FlowJSParam
TotalChunk
s
,
err
.
Error
())
return
return
}
}
case
"f
lowCurrentChunkSize
"
:
case
F
low
JSParam
CurrentChunkSize
:
if
chunkSize
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
if
chunkSize
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid parameter '
flow
CurrentChunkSize
': "
+
err
.
Error
())
err
=
fmt
.
Errorf
(
"invalid parameter '
%s': %v"
,
FlowJSParam
CurrentChunkSize
,
err
.
Error
())
return
return
}
}
case
"f
lowTotalSize
"
:
case
F
low
JSParam
TotalSize
:
if
totalSize
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
if
totalSize
,
err
=
strconv
.
ParseUint
(
string
(
pd
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid parameter '
flow
TotalSize
': "
+
err
.
Error
())
err
=
fmt
.
Errorf
(
"invalid parameter '
%s': %v"
,
FlowJSParam
TotalSize
,
err
.
Error
())
return
return
}
}
}
}
}
}
var
missing
[]
string
var
missing
[]
string
if
id
==
""
{
if
id
==
""
{
missing
=
append
(
missing
,
"f
low
Identifier"
)
missing
=
append
(
missing
,
F
low
JSParamID
)
}
}
if
chunk
==
0
{
if
chunk
==
0
{
missing
=
append
(
missing
,
"f
low
ChunkNumber"
)
missing
=
append
(
missing
,
F
low
JSParamChunk
)
}
}
if
totalChunks
==
0
{
if
totalChunks
==
0
{
missing
=
append
(
missing
,
"f
lowTotalChunks
"
)
missing
=
append
(
missing
,
F
low
JSParam
TotalChunks
)
}
}
if
chunkSize
==
0
{
if
chunkSize
==
0
{
missing
=
append
(
missing
,
"f
lowCurrentChunkSize
"
)
missing
=
append
(
missing
,
F
low
JSParam
CurrentChunkSize
)
}
}
if
totalSize
==
0
{
if
totalSize
==
0
{
missing
=
append
(
missing
,
"f
lowTotalSize
"
)
missing
=
append
(
missing
,
F
low
JSParam
TotalSize
)
}
}
if
data
==
nil
{
if
data
==
nil
{
missing
=
append
(
missing
,
"file"
)
missing
=
append
(
missing
,
FlowJSParamFile
)
}
if
len
(
missing
)
>
0
{
err
=
errors
.
New
(
"missing/invalid mandatory parameter: "
+
strings
.
Join
(
missing
,
", "
))
}
return
}
//***
func
getFlowJSParameterFromQuery
(
r
*
http
.
Request
)
(
id
string
,
chunk
,
totalChunks
,
totalSize
uint64
,
err
error
)
{
q
:=
r
.
URL
.
Query
()
id
=
q
.
Get
(
FlowJSParamID
)
if
chunk
,
err
=
strconv
.
ParseUint
(
q
.
Get
(
FlowJSParamChunk
),
10
,
64
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"invalid parameter '%s': %v"
,
FlowJSParamChunk
,
err
.
Error
())
return
}
if
totalChunks
,
err
=
strconv
.
ParseUint
(
q
.
Get
(
FlowJSParamTotalChunks
),
10
,
64
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"invalid parameter '%s': %v"
,
FlowJSParamTotalChunks
,
err
.
Error
())
return
}
if
totalSize
,
err
=
strconv
.
ParseUint
(
q
.
Get
(
FlowJSParamTotalSize
),
10
,
64
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"invalid parameter '%s': %v"
,
FlowJSParamTotalSize
,
err
.
Error
())
return
}
var
missing
[]
string
if
id
==
""
{
missing
=
append
(
missing
,
FlowJSParamID
)
}
if
chunk
==
0
{
missing
=
append
(
missing
,
FlowJSParamChunk
)
}
if
totalChunks
==
0
{
missing
=
append
(
missing
,
FlowJSParamTotalChunks
)
}
if
totalSize
==
0
{
missing
=
append
(
missing
,
FlowJSParamTotalSize
)
}
}
if
len
(
missing
)
>
0
{
if
len
(
missing
)
>
0
{
err
=
errors
.
New
(
"missing mandatory parameter: "
+
strings
.
Join
(
missing
,
", "
))
err
=
errors
.
New
(
"missing
/invalid
mandatory parameter: "
+
strings
.
Join
(
missing
,
", "
))
}
}
return
return
}
}
...
@@ -380,33 +427,10 @@ func (api *API) UploadFileFlowJS() http.Handler {
...
@@ -380,33 +427,10 @@ func (api *API) UploadFileFlowJS() http.Handler {
sendWebResponse
(
w
,
http
.
StatusInternalServerError
,
ErrorResponse
{
Error
:
"failed to mark chunk completed: "
+
err
.
Error
()})
sendWebResponse
(
w
,
http
.
StatusInternalServerError
,
ErrorResponse
{
Error
:
"failed to mark chunk completed: "
+
err
.
Error
()})
return
return
}
}
// TODO: if this is the last chunk to be uploaded wait for fetch converter to finish?
sendWebResponse
(
w
,
http
.
StatusOK
,
nil
)
sendWebResponse
(
w
,
http
.
StatusOK
,
nil
)
})
})
}
}
func
getFlowJSParameterFromQuery
(
r
*
http
.
Request
)
(
id
string
,
chunk
,
totalChunks
,
totalSize
uint64
,
err
error
)
{
q
:=
r
.
URL
.
Query
()
id
=
q
.
Get
(
"flowIdentifier"
)
if
chunk
,
err
=
strconv
.
ParseUint
(
q
.
Get
(
"flowChunkNumber"
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid query parameter 'flowChunkNumber': "
+
err
.
Error
())
return
}
if
chunk
<
1
{
err
=
errors
.
New
(
"invalid chunk number: 0"
)
return
}
if
totalChunks
,
err
=
strconv
.
ParseUint
(
q
.
Get
(
"flowTotalChunks"
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid query parameter 'flowTotalChunks': "
+
err
.
Error
())
return
}
if
totalSize
,
err
=
strconv
.
ParseUint
(
q
.
Get
(
"flowTotalSize"
),
10
,
64
);
err
!=
nil
{
err
=
errors
.
New
(
"invalid query parameter 'flowTotalSize': "
+
err
.
Error
())
return
}
return
}
func
(
api
*
API
)
TestFileFlowJS
()
http
.
Handler
{
func
(
api
*
API
)
TestFileFlowJS
()
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
vars
:=
mux
.
Vars
(
r
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment