make playlist uploading a little more robust
This commit is contained in:
@@ -45,6 +45,10 @@ func playlistParseUpload(c *Controller, userID int, header *multipart.FileHeader
|
|||||||
if playlistName == "" {
|
if playlistName == "" {
|
||||||
return []string{fmt.Sprintf("invalid filename %q", header.Filename)}, false
|
return []string{fmt.Sprintf("invalid filename %q", header.Filename)}, false
|
||||||
}
|
}
|
||||||
|
contentType := header.Header.Get("Content-Type")
|
||||||
|
if !(contentType == "audio/x-mpegurl" || contentType == "application/octet-stream") {
|
||||||
|
return []string{fmt.Sprintf("invalid content-type %q", contentType)}, false
|
||||||
|
}
|
||||||
playlist := &model.Playlist{}
|
playlist := &model.Playlist{}
|
||||||
c.DB.FirstOrCreate(playlist, model.Playlist{
|
c.DB.FirstOrCreate(playlist, model.Playlist{
|
||||||
Name: playlistName,
|
Name: playlistName,
|
||||||
@@ -56,7 +60,8 @@ func playlistParseUpload(c *Controller, userID int, header *multipart.FileHeader
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
path := scanner.Text()
|
path := scanner.Text()
|
||||||
if err := playlistParseLine(c, playlist.ID, path); err != nil {
|
if err := playlistParseLine(c, playlist.ID, path); err != nil {
|
||||||
errors = append(errors, err.Error())
|
// trim length of error to not overflow cookie flash
|
||||||
|
errors = append(errors, fmt.Sprintf("%.100s", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user