status-go/images/identity.go

57 lines
1.1 KiB
Go
Raw Normal View History

2020-10-26 17:45:51 +00:00
package images
import (
"encoding/json"
"errors"
2020-10-26 17:45:51 +00:00
)
type IdentityImage struct {
KeyUID string
Name string
2020-10-26 17:45:51 +00:00
Payload []byte
2020-10-27 14:42:42 +00:00
Width int
Height int
FileSize int
ResizeTarget int
2020-10-26 17:45:51 +00:00
}
func (i IdentityImage) GetType() (ImageType, error) {
it := GetType(i.Payload)
if it == UNKNOWN {
return it, errors.New("unsupported file type")
}
return it, nil
}
2020-10-26 17:45:51 +00:00
func (i IdentityImage) GetDataURI() (string, error) {
return GetPayloadDataURI(i.Payload)
2020-10-26 17:45:51 +00:00
}
func (i IdentityImage) MarshalJSON() ([]byte, error) {
uri, err := i.GetDataURI()
if err != nil {
return nil, err
}
temp := struct {
KeyUID string `json:"key_uid"`
Name string `json:"type"`
2020-10-26 17:45:51 +00:00
URI string `json:"uri"`
Width int `json:"width"`
Height int `json:"height"`
FileSize int `json:"file_size"`
ResizeTarget int `json:"resize_target"`
}{
KeyUID: i.KeyUID,
Name: i.Name,
2020-10-26 17:45:51 +00:00
URI: uri,
Width: i.Width,
Height: i.Height,
FileSize: i.FileSize,
ResizeTarget: i.ResizeTarget,
}
return json.Marshal(temp)
}