Refactors Cover's Extension cleaning in Album

This commit is contained in:
2016-01-25 15:20:19 +01:00
parent c858e99d06
commit 1c39ad27a5
3 changed files with 33 additions and 7 deletions

View File

@@ -8,9 +8,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"ponyo.epfl.ch/gitlab/alexandre.tuleu/narco"
@@ -20,8 +18,6 @@ import (
"golang.org/x/net/context"
)
var rxExt = regexp.MustCompile(`[0-9]+`)
func (a *appData) buildRouter() http.Handler {
router := httprouter.New()
@@ -79,9 +75,7 @@ func (a *appData) buildRouter() http.Handler {
}
album := *albumUnsafe
ext := path.Ext(album.CoverURL)
ext = strings.ToLower(rxExt.ReplaceAllString(ext, ""))
album.CoverURL = fmt.Sprintf("/covers/%d%s", album.ID, ext)
album.CoverURL = fmt.Sprintf("/covers/%d%s", album.ID, album.CoverExt())
enc := json.NewEncoder(w)
if err := enc.Encode(album); err != nil {