diff --git a/frontend/src/components/files/Preview.vue b/frontend/src/components/files/Preview.vue index bc008447..1294fa5f 100644 --- a/frontend/src/components/files/Preview.vue +++ b/frontend/src/components/files/Preview.vue @@ -86,15 +86,14 @@ export default { download () { return `${baseURL}/api/raw${this.req.path}?auth=${this.jwt}` }, - thumbnail () { + previewUrl () { if (this.req.type === 'image') { return `${baseURL}/api/preview/big${this.req.path}?auth=${this.jwt}` - } else { - return `${baseURL}/api/raw${this.req.path}?auth=${this.jwt}` } + return `${baseURL}/api/raw${this.req.path}?auth=${this.jwt}` }, raw () { - return `${this.thumbnail}&inline=true` + return `${this.previewUrl}&inline=true` } }, async mounted () { diff --git a/http/preview.go b/http/preview.go index 26b2d6ca..060d60eb 100644 --- a/http/preview.go +++ b/http/preview.go @@ -50,9 +50,13 @@ var previewHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *da }) func handleImagePreview(w http.ResponseWriter, r *http.Request, file *files.FileInfo, size string) (int, error) { - // Unsupported extensions directly return the raw data - if file.Extension == ".ico" || file.Extension == ".svg" { - return rawFileHandler(w, r, file) + format, err := imaging.FormatFromExtension(file.Extension) + if err != nil { + // Unsupported extensions directly return the raw data + if err == imaging.ErrUnsupportedFormat { + return rawFileHandler(w, r, file) + } + return errToStatus(err), err } var imgProcessor imageProcessor @@ -74,10 +78,7 @@ func handleImagePreview(w http.ResponseWriter, r *http.Request, file *files.File return errToStatus(err), err } defer fd.Close() - format, err := imaging.FormatFromExtension(file.Extension) - if err != nil { - return http.StatusNotImplemented, err - } + img, err := imaging.Decode(fd, imaging.AutoOrientation(true)) if err != nil { return errToStatus(err), err diff --git a/http/raw.go b/http/raw.go index bcd0360d..c3796bef 100644 --- a/http/raw.go +++ b/http/raw.go @@ -22,7 +22,7 @@ func parseQueryFiles(r *http.Request, f *files.FileInfo, _ *users.User) ([]strin fileSlice = append(fileSlice, f.Path) } else { for _, name := range names { - name, err := url.QueryUnescape(strings.Replace(name, "+", "%2B", -1)) // nolint:shadow + name, err := url.QueryUnescape(strings.Replace(name, "+", "%2B", -1)) //nolint:shadow if err != nil { return nil, err } @@ -35,7 +35,7 @@ func parseQueryFiles(r *http.Request, f *files.FileInfo, _ *users.User) ([]strin return fileSlice, nil } -// nolint: goconst +//nolint: goconst func parseQueryAlgorithm(r *http.Request) (string, archiver.Writer, error) { // TODO: use enum switch r.URL.Query().Get("algo") {