Skip to content

Commit

Permalink
feat(thumbnails): allow thumbnails on ggp files
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Oct 28, 2024
1 parent d701e79 commit 9700580
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/ggp-mimetype-thumbnails.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions services/thumbnails/pkg/preprocessor/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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":
Expand Down
9 changes: 5 additions & 4 deletions services/thumbnails/pkg/preprocessor/preprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 4 additions & 1 deletion services/thumbnails/pkg/thumbnail/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
typeJpeg = "jpeg"
typeGif = "gif"
typeGgs = "ggs"
typeGgp = "ggp"
)

// Encoder encodes the thumbnail to a specific format.
Expand Down Expand Up @@ -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
Expand All @@ -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 ""
}
Expand Down

0 comments on commit 9700580

Please sign in to comment.