mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-26 23:48:55 -06:00
feat(thumbnails): allow thumbnails on ggp files
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
5
changelog/unreleased/ggp-mimetype-thumbnails.md
Normal file
5
changelog/unreleased/ggp-mimetype-thumbnails.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Enhancement: Create thumbnails for GGP MIME types
|
||||
|
||||
Creates thumbnails for newly added ggp files
|
||||
|
||||
https://github.com/owncloud/ocis/pull/10303
|
||||
@@ -39,11 +39,10 @@ func (i GifDecoder) Convert(r io.Reader) (interface{}, error) {
|
||||
}
|
||||
|
||||
// GgsDecoder is a converter for the geogebra slides file
|
||||
type GgsDecoder struct{}
|
||||
type GgsDecoder struct{ thumbnailpath string }
|
||||
|
||||
// Convert reads the ggs file and returns the thumbnail image
|
||||
func (g GgsDecoder) Convert(r io.Reader) (interface{}, error) {
|
||||
geogebraThumbnail := "_slide0/geogebra_thumbnail.png"
|
||||
var buf bytes.Buffer
|
||||
_, err := io.Copy(&buf, r)
|
||||
if err != nil {
|
||||
@@ -54,7 +53,7 @@ func (g GgsDecoder) Convert(r io.Reader) (interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
for _, file := range zipReader.File {
|
||||
if file.Name == geogebraThumbnail {
|
||||
if file.Name == g.thumbnailpath {
|
||||
thumbnail, err := file.Open()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -70,7 +69,7 @@ func (g GgsDecoder) Convert(r io.Reader) (interface{}, error) {
|
||||
return img, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Errorf("%s not found", geogebraThumbnail)
|
||||
return nil, errors.Errorf("%s not found", g.thumbnailpath)
|
||||
}
|
||||
|
||||
// AudioDecoder is a converter for the audio file
|
||||
@@ -258,7 +257,9 @@ func ForType(mimeType string, opts map[string]interface{}) FileConverter {
|
||||
fontLoader: fontLoader,
|
||||
}
|
||||
case "application/vnd.geogebra.slides":
|
||||
return GgsDecoder{}
|
||||
return GgsDecoder{"_slide0/geogebra_thumbnail.png"}
|
||||
case "application/vnd.geogebra.pinboard":
|
||||
return GgsDecoder{"geogebra_thumbnail.png"}
|
||||
case "image/gif":
|
||||
return GifDecoder{}
|
||||
case "audio/flac":
|
||||
|
||||
@@ -2,12 +2,13 @@ package preprocessor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/opentype"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -80,14 +81,14 @@ var _ = Describe("ImageDecoder", func() {
|
||||
})
|
||||
|
||||
It("should decode a ggs", func() {
|
||||
decoder := GgsDecoder{}
|
||||
decoder := GgsDecoder{"_slide0/geogebra_thumbnail.png"}
|
||||
img, err := decoder.Convert(fileReader)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(img).ToNot(BeNil())
|
||||
})
|
||||
|
||||
It("should return an error if the ggs is invalid", func() {
|
||||
decoder := GgsDecoder{}
|
||||
decoder := GgsDecoder{"_slide0/geogebra_thumbnail.png"}
|
||||
img, err := decoder.Convert(bytes.NewReader([]byte("not a ggs")))
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(img).To(BeNil())
|
||||
|
||||
@@ -14,6 +14,7 @@ const (
|
||||
typeJpeg = "jpeg"
|
||||
typeGif = "gif"
|
||||
typeGgs = "ggs"
|
||||
typeGgp = "ggp"
|
||||
)
|
||||
|
||||
// Encoder encodes the thumbnail to a specific format.
|
||||
@@ -52,7 +53,7 @@ func (e GifEncoder) MimeType() string {
|
||||
// or nil if the type is not supported.
|
||||
func EncoderForType(fileType string) (Encoder, error) {
|
||||
switch strings.ToLower(fileType) {
|
||||
case typePng, typeGgs:
|
||||
case typePng, typeGgs, typeGgp:
|
||||
return PngEncoder{}, nil
|
||||
case typeJpg, typeJpeg:
|
||||
return JpegEncoder{}, nil
|
||||
@@ -71,6 +72,8 @@ func GetExtForMime(fileType string) string {
|
||||
return ext
|
||||
case "application/vnd.geogebra.slides":
|
||||
return typeGgs
|
||||
case "application/vnd.geogebra.pinboard":
|
||||
return typeGgp
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user