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
46b373a9
Commit
46b373a9
authored
4 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
store: refactor playlist BeforeSave Error handling
parent
52f14a64
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/v1/utils.go
+2
-0
2 additions, 0 deletions
api/v1/utils.go
store/playlists.go
+13
-9
13 additions, 9 deletions
store/playlists.go
store/types.go
+9
-0
9 additions, 0 deletions
store/types.go
with
24 additions
and
9 deletions
api/v1/utils.go
+
2
−
0
View file @
46b373a9
...
...
@@ -48,6 +48,8 @@ func statusCodeFromError(err error) (code int, response ErrorResponse) {
response
.
Detail
=
err
case
store
.
ErrInvalidMetadataField
:
code
=
http
.
StatusBadRequest
case
store
.
ErrInvalidPlaylistEntry
:
code
=
http
.
StatusBadRequest
case
*
importer
.
JobSourceResult
:
response
.
Detail
=
err
.
(
*
importer
.
JobSourceResult
)
.
Log
default
:
...
...
This diff is collapsed.
Click to expand it.
store/playlists.go
+
13
−
9
View file @
46b373a9
...
...
@@ -33,29 +33,36 @@ import (
"github.com/jinzhu/gorm"
)
func
generateFileURI
(
file
*
File
)
string
{
uri
:=
url
.
URL
{
Scheme
:
FileURIScheme
,
Host
:
file
.
ShowName
,
Path
:
strconv
.
FormatUint
(
file
.
ID
,
10
)}
return
uri
.
String
()
}
func
(
p
*
Playlist
)
BeforeSave
()
error
{
for
idx
:=
range
p
.
Entries
{
p
.
Entries
[
idx
]
.
LineNum
=
uint
(
idx
)
if
p
.
Entries
[
idx
]
.
File
!=
nil
{
p
.
Entries
[
idx
]
.
URI
=
""
// this will be regenerated in AfterFind()
if
p
.
Entries
[
idx
]
.
URI
!=
""
&&
p
.
Entries
[
idx
]
.
URI
!=
generateFileURI
(
p
.
Entries
[
idx
]
.
File
)
{
return
ErrInvalidPlaylistEntry
{
idx
,
"File and Uri Parameter mismatch"
}
}
}
else
if
p
.
Entries
[
idx
]
.
URI
!=
""
{
uri
,
err
:=
url
.
Parse
(
p
.
Entries
[
idx
]
.
URI
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"p
laylist
e
ntry
#%d is invalid: %v"
,
idx
,
err
)
return
ErrInvalidP
laylist
E
ntry
{
idx
,
err
.
Error
()}
}
if
uri
.
Scheme
==
FileURIScheme
{
if
uri
.
Host
==
""
||
uri
.
Path
==
""
{
return
fmt
.
Errorf
(
"p
laylist
e
ntry
#%d is invalid:
uri must be in the format
%s://<show>/<file-id>"
,
idx
,
FileURIScheme
)
return
ErrInvalidP
laylist
E
ntry
{
idx
,
"
uri must be in the format
"
+
FileURIScheme
+
"://<show>/<file-id>"
}
}
fileID
,
err
:=
strconv
.
ParseUint
(
strings
.
TrimPrefix
(
uri
.
Path
,
"/"
),
10
,
64
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"p
laylist
e
ntry
#%d is invalid: %v"
,
idx
,
err
)
return
ErrInvalidP
laylist
E
ntry
{
idx
,
err
.
Error
()}
}
p
.
Entries
[
idx
]
.
File
=
&
File
{
ID
:
fileID
,
ShowName
:
uri
.
Host
}
p
.
Entries
[
idx
]
.
URI
=
""
// this will be regenerated in AfterFind()
}
}
else
{
return
fmt
.
Errorf
(
"p
laylist
e
ntry
#%d is inval
id, entries must either contain a File or have a URI set"
,
idx
)
return
ErrInvalidP
laylist
E
ntry
{
id
x
,
"
entries must either contain a File or have a URI set"
}
}
}
return
nil
...
...
@@ -68,10 +75,7 @@ func (p *Playlist) AfterSave(tx *gorm.DB) error {
func
(
p
*
Playlist
)
AfterFind
()
error
{
for
idx
:=
range
p
.
Entries
{
if
p
.
Entries
[
idx
]
.
File
!=
nil
{
urihost
:=
p
.
Entries
[
idx
]
.
File
.
ShowName
uripath
:=
strconv
.
FormatUint
(
p
.
Entries
[
idx
]
.
File
.
ID
,
10
)
uri
:=
url
.
URL
{
Scheme
:
FileURIScheme
,
Host
:
urihost
,
Path
:
uripath
}
p
.
Entries
[
idx
]
.
URI
=
uri
.
String
()
p
.
Entries
[
idx
]
.
URI
=
generateFileURI
(
p
.
Entries
[
idx
]
.
File
)
}
}
return
nil
...
...
This diff is collapsed.
Click to expand it.
store/types.go
+
9
−
0
View file @
46b373a9
...
...
@@ -64,6 +64,15 @@ func (e ErrInvalidMetadataField) Error() string {
return
"invalid metadata field: "
+
string
(
e
)
}
type
ErrInvalidPlaylistEntry
struct
{
idx
int
message
string
}
func
(
e
ErrInvalidPlaylistEntry
)
Error
()
string
{
return
fmt
.
Sprintf
(
"playlist entry #%d is invalid: %s"
,
e
.
idx
,
e
.
message
)
}
//******* Logs
type
LogLine
struct
{
...
...
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