add mimetype to service response

This commit is contained in:
David Christofas
2020-03-18 11:13:09 +01:00
parent 06151de3f4
commit 024e4661e2
4 changed files with 42 additions and 18 deletions
+27 -18
View File
@@ -126,6 +126,7 @@ func (m *GetRequest) GetAuthorization() string {
type GetResponse struct {
Thumbnail []byte `protobuf:"bytes,1,opt,name=thumbnail,proto3" json:"thumbnail,omitempty"`
Mimetype string `protobuf:"bytes,2,opt,name=mimetype,proto3" json:"mimetype,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -163,6 +164,13 @@ func (m *GetResponse) GetThumbnail() []byte {
return nil
}
func (m *GetResponse) GetMimetype() string {
if m != nil {
return m.Mimetype
}
return ""
}
func init() {
proto.RegisterEnum("com.owncloud.ocis.thumbnails.v0.GetRequest_FileType", GetRequest_FileType_name, GetRequest_FileType_value)
proto.RegisterType((*GetRequest)(nil), "com.owncloud.ocis.thumbnails.v0.GetRequest")
@@ -172,24 +180,25 @@ func init() {
func init() { proto.RegisterFile("pkg/proto/v0/thumbnails.proto", fileDescriptor_e354cb4f8a62b6c2) }
var fileDescriptor_e354cb4f8a62b6c2 = []byte{
// 300 bytes of a gzipped FileDescriptorProto
// 309 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0x4f, 0x4f, 0xc2, 0x40,
0x10, 0xc5, 0x2d, 0x50, 0xfe, 0x8c, 0x68, 0xc8, 0xc4, 0x98, 0x86, 0x60, 0x24, 0xc4, 0x03, 0x09,
0x10, 0xc5, 0x2d, 0x50, 0xfe, 0x8c, 0x68, 0xc8, 0xc4, 0x98, 0x86, 0x60, 0x24, 0xc4, 0x03, 0x89,
0x66, 0x21, 0xe8, 0x27, 0xf0, 0x60, 0x13, 0x0f, 0x86, 0x54, 0x4e, 0xde, 0x4a, 0x19, 0xd9, 0x8d,
0xa5, 0xbb, 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0x27, 0xd9, 0x1a, 0x4f, 0xc0, 0x5d, 0xa9, 0x19,
0x4b, 0xaf, 0xd2, 0x75, 0xfa, 0x6e, 0xb0, 0x15, 0x78, 0x0a, 0x55, 0x49, 0x6a, 0x2e, 0xd9, 0x73,
0x2d, 0xfe, 0x52, 0x78, 0x01, 0x47, 0x61, 0xce, 0x52, 0x2f, 0xd4, 0x5b, 0xc8, 0x4a, 0xa7, 0x5e,
0xd5, 0x5a, 0xfd, 0x84, 0xbd, 0x0e, 0xd4, 0x77, 0xd3, 0xb1, 0x06, 0xe5, 0xf1, 0x83, 0xdf, 0x3a,
0xd8, 0x14, 0xf7, 0x63, 0xbf, 0xe5, 0xf4, 0x7c, 0x38, 0xb4, 0x6b, 0x66, 0x46, 0xa7, 0x19, 0x61,
0x07, 0x1a, 0xc5, 0x1b, 0x6c, 0x06, 0xcd, 0x60, 0x0f, 0x36, 0x01, 0x25, 0x2a, 0xd9, 0x87, 0xd0,
0x08, 0x0a, 0x3d, 0x7a, 0x87, 0xd6, 0x64, 0xd7, 0xf8, 0x48, 0x8b, 0xa5, 0x8a, 0x08, 0x15, 0x34,
0x7d, 0xe2, 0x02, 0xe3, 0xe5, 0x3f, 0x22, 0x6b, 0x5f, 0xfd, 0xad, 0x79, 0xbb, 0xf8, 0x6d, 0xed,
0xc9, 0xb5, 0x9f, 0x3e, 0xad, 0xda, 0xe3, 0xfa, 0x33, 0x00, 0x00, 0xff, 0xff, 0xb1, 0x29, 0x25,
0xcc, 0x1c, 0x02, 0x00, 0x00,
}
+1
View File
@@ -22,4 +22,5 @@ message GetRequest {
message GetResponse {
bytes thumbnail = 1;
string mimetype = 2;
}
+2
View File
@@ -55,6 +55,7 @@ func (g Thumbnail) GetThumbnail(ctx context.Context, req *v0proto.GetRequest, rs
thumbnail := g.manager.GetStored(tCtx)
if thumbnail != nil {
rsp.Thumbnail = thumbnail
rsp.Mimetype = tCtx.Encoder.MimeType()
return nil
}
@@ -74,5 +75,6 @@ func (g Thumbnail) GetThumbnail(ctx context.Context, req *v0proto.GetRequest, rs
}
rsp.Thumbnail = thumbnail
rsp.Mimetype = tCtx.Encoder.MimeType()
return nil
}
+12
View File
@@ -14,6 +14,8 @@ type Encoder interface {
Encode(io.Writer, image.Image) error
// Types returns the formats suffixes.
Types() []string
// MimeType returns the mimetype used by the encoder.
MimeType() string
}
// PngEncoder encodes to png
@@ -29,6 +31,11 @@ func (e PngEncoder) Types() []string {
return []string{"png"}
}
// MimeType returns the mimetype for png files.
func (e PngEncoder) MimeType() string {
return "image/png"
}
// JpegEncoder encodes to jpg.
type JpegEncoder struct{}
@@ -42,6 +49,11 @@ func (e JpegEncoder) Types() []string {
return []string{"jpeg", "jpg"}
}
// MimeType returns the mimetype for jpg files.
func (e JpegEncoder) MimeType() string {
return "image/jpeg"
}
// EncoderForType returns the encoder for a given file type
// or nil if the type is not supported.
func EncoderForType(fileType string) Encoder {