From 9700580624de775a85fd93ae6f7523ea61368c98 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Tue, 15 Oct 2024 16:12:32 +0200 Subject: [PATCH] feat(thumbnails): allow thumbnails on ggp files Signed-off-by: jkoberg --- changelog/unreleased/ggp-mimetype-thumbnails.md | 5 +++++ services/thumbnails/pkg/preprocessor/preprocessor.go | 11 ++++++----- .../thumbnails/pkg/preprocessor/preprocessor_test.go | 9 +++++---- services/thumbnails/pkg/thumbnail/encoding.go | 5 ++++- 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/ggp-mimetype-thumbnails.md diff --git a/changelog/unreleased/ggp-mimetype-thumbnails.md b/changelog/unreleased/ggp-mimetype-thumbnails.md new file mode 100644 index 00000000000..a4c9b72da14 --- /dev/null +++ b/changelog/unreleased/ggp-mimetype-thumbnails.md @@ -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 diff --git a/services/thumbnails/pkg/preprocessor/preprocessor.go b/services/thumbnails/pkg/preprocessor/preprocessor.go index 1733dcf8353..409e2239a2c 100644 --- a/services/thumbnails/pkg/preprocessor/preprocessor.go +++ b/services/thumbnails/pkg/preprocessor/preprocessor.go @@ -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": diff --git a/services/thumbnails/pkg/preprocessor/preprocessor_test.go b/services/thumbnails/pkg/preprocessor/preprocessor_test.go index 3c85f2c6638..531fe6a51e4 100644 --- a/services/thumbnails/pkg/preprocessor/preprocessor_test.go +++ b/services/thumbnails/pkg/preprocessor/preprocessor_test.go @@ -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()) diff --git a/services/thumbnails/pkg/thumbnail/encoding.go b/services/thumbnails/pkg/thumbnail/encoding.go index 917642db98a..4e26227a31e 100644 --- a/services/thumbnails/pkg/thumbnail/encoding.go +++ b/services/thumbnails/pkg/thumbnail/encoding.go @@ -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 "" }