mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-06-22 14:59:12 -04:00
make filetype dynamic based on file extension
This commit is contained in:
@@ -42,11 +42,11 @@ func NewRequest(r *http.Request) (Request, error) {
|
||||
return Request{}, fmt.Errorf("c (etag) is missing in query")
|
||||
}
|
||||
|
||||
authorization := r.Header.Get("Authorizaiton")
|
||||
authorization := r.Header.Get("Authorization")
|
||||
|
||||
tr := Request{
|
||||
Filepath: path,
|
||||
Filetype: filepath.Ext(path),
|
||||
Filetype: strings.Replace(filepath.Ext(path), ".", "", 1),
|
||||
Etag: etag,
|
||||
Width: width,
|
||||
Height: height,
|
||||
|
||||
@@ -59,7 +59,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
|
||||
c := thumbnails.NewThumbnailService("com.owncloud.api.thumbnails", client.DefaultClient)
|
||||
rsp, err := c.GetThumbnail(r.Context(), &thumbnails.GetRequest{
|
||||
Filepath: strings.TrimLeft(tr.Filepath, "/"),
|
||||
Filetype: thumbnails.GetRequest_JPG,
|
||||
Filetype: extensionToFiletype(tr.Filetype),
|
||||
Etag: tr.Etag,
|
||||
Width: int32(tr.Width),
|
||||
Height: int32(tr.Height),
|
||||
@@ -71,8 +71,12 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "image/jpeg")
|
||||
w.Header().Set("Content-Type", rsp.GetMimetype())
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
w.Write(rsp.Thumbnail)
|
||||
}
|
||||
|
||||
func extensionToFiletype(ext string) thumbnails.GetRequest_FileType {
|
||||
val := thumbnails.GetRequest_FileType_value[strings.ToUpper(ext)]
|
||||
return thumbnails.GetRequest_FileType(val)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user