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
b861db61
Commit
b861db61
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
some refactoring
parent
8470e586
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/v1/api_uploads.go
+43
-32
43 additions, 32 deletions
api/v1/api_uploads.go
api/v1/utils.go
+8
-0
8 additions, 0 deletions
api/v1/utils.go
with
51 additions
and
32 deletions
api/v1/api_uploads.go
+
43
−
32
View file @
b861db61
...
@@ -130,6 +130,8 @@ func (ch *FlowJSFileChunk) Cleanup() (err error) {
...
@@ -130,6 +130,8 @@ func (ch *FlowJSFileChunk) Cleanup() (err error) {
return
os
.
Remove
(
filename
)
return
os
.
Remove
(
filename
)
}
}
//***
type
FlowJSFile
struct
{
type
FlowJSFile
struct
{
id
string
id
string
size
uint64
size
uint64
...
@@ -192,6 +194,45 @@ func (f *FlowJSFile) Read(p []byte) (n int, err error) {
...
@@ -192,6 +194,45 @@ func (f *FlowJSFile) Read(p []byte) (n int, err error) {
}
}
}
}
//***
func
getOrNewFlowJSFile
(
job
*
importer
.
Job
,
flowId
string
,
chunk
,
totalChunks
,
totalSize
uint64
)
(
file
*
FlowJSFile
,
err
error
)
{
var
src
io
.
Reader
if
src
,
err
=
job
.
GetAttachedUploader
();
err
!=
nil
&&
err
!=
importer
.
ErrSourceNotYetAttached
{
return
}
if
err
==
importer
.
ErrSourceNotYetAttached
{
if
file
,
err
=
newFlowJSFile
(
flowId
,
totalChunks
,
totalSize
,
job
);
err
!=
nil
{
return
}
_
,
err
=
job
.
AttachUploader
(
file
.
size
,
file
)
switch
err
{
case
nil
:
case
importer
.
ErrSourceAlreadyAttached
:
// there has been a race and the other thread won!
file
=
nil
if
src
,
err
=
job
.
GetAttachedUploader
();
err
!=
nil
{
return
}
default
:
return
}
}
if
file
==
nil
{
var
ok
bool
if
file
,
ok
=
src
.
(
*
FlowJSFile
);
!
ok
{
err
=
ErrNotFlowJSUpload
return
}
}
return
}
//***
func
(
api
*
API
)
UploadFileFlowJS
()
http
.
Handler
{
func
(
api
*
API
)
UploadFileFlowJS
()
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// TODO: implement this
// TODO: implement this
...
@@ -240,40 +281,10 @@ func (api *API) TestFileFlowJS() http.Handler {
...
@@ -240,40 +281,10 @@ func (api *API) TestFileFlowJS() http.Handler {
sendError
(
w
,
err
)
sendError
(
w
,
err
)
return
return
}
}
src
,
err
:=
job
.
GetAttachedUploader
()
if
err
!=
nil
&&
err
!=
importer
.
ErrSourceNotYetAttached
{
sendError
(
w
,
err
)
return
}
var
file
*
FlowJSFile
if
err
==
importer
.
ErrSourceNotYetAttached
{
if
file
,
err
=
newFlowJSFile
(
flowId
,
totalChunks
,
totalSize
,
job
);
err
!=
nil
{
sendError
(
w
,
err
)
return
}
_
,
err
=
job
.
AttachUploader
(
file
.
size
,
file
)
file
,
err
:=
getOrNewFlowJSFile
(
job
,
flowId
,
chunk
,
totalChunks
,
totalSize
)
switch
err
{
case
nil
:
case
importer
.
ErrSourceAlreadyAttached
:
// there has been a race and the other thread won!
file
=
nil
if
src
,
err
=
job
.
GetAttachedUploader
();
err
!=
nil
{
sendError
(
w
,
err
)
return
}
default
:
sendError
(
w
,
err
)
return
}
}
if
file
==
nil
{
if
file
==
nil
{
var
ok
bool
sendError
(
w
,
err
)
if
file
,
ok
=
src
.
(
*
FlowJSFile
);
!
ok
{
sendWebResponse
(
w
,
http
.
StatusConflict
,
ErrorResponse
{
Error
:
"this is not a flow.js upload"
})
return
}
}
}
if
chunk
>
uint64
(
len
(
file
.
chunks
))
{
if
chunk
>
uint64
(
len
(
file
.
chunks
))
{
...
...
This diff is collapsed.
Click to expand it.
api/v1/utils.go
+
8
−
0
View file @
b861db61
...
@@ -26,6 +26,7 @@ package v1
...
@@ -26,6 +26,7 @@ package v1
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
"net/http"
"net/http"
"strconv"
"strconv"
...
@@ -33,6 +34,10 @@ import (
...
@@ -33,6 +34,10 @@ import (
"gitlab.servus.at/autoradio/tank/store"
"gitlab.servus.at/autoradio/tank/store"
)
)
var
(
ErrNotFlowJSUpload
=
errors
.
New
(
"this is not a flow.js upload"
)
)
func
idFromString
(
s
string
)
(
uint64
,
error
)
{
func
idFromString
(
s
string
)
(
uint64
,
error
)
{
return
strconv
.
ParseUint
(
s
,
10
,
64
)
return
strconv
.
ParseUint
(
s
,
10
,
64
)
}
}
...
@@ -48,6 +53,9 @@ func sendError(w http.ResponseWriter, err error) {
...
@@ -48,6 +53,9 @@ func sendError(w http.ResponseWriter, err error) {
response
.
Details
=
err
.
(
*
importer
.
JobSourceResult
)
.
Log
response
.
Details
=
err
.
(
*
importer
.
JobSourceResult
)
.
Log
default
:
default
:
switch
err
{
switch
err
{
case
ErrNotFlowJSUpload
:
code
=
http
.
StatusConflict
case
store
.
ErrNotImplemented
:
case
store
.
ErrNotImplemented
:
code
=
http
.
StatusNotImplemented
code
=
http
.
StatusNotImplemented
case
store
.
ErrNotFound
:
case
store
.
ErrNotFound
:
...
...
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