2020-10-26 17:45:51 +00:00
|
|
|
package images
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2020-11-05 17:35:20 +00:00
|
|
|
"errors"
|
2020-12-10 10:12:51 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2020-10-26 17:45:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type IdentityImage struct {
|
2022-06-24 14:06:13 +00:00
|
|
|
KeyUID string `json:"key_uid"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Payload []byte `json:"payload"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
|
|
|
FileSize int `json:"file_size"`
|
|
|
|
ResizeTarget int `json:"resize_target"`
|
|
|
|
Clock uint64 `json:"clock"`
|
2020-10-26 17:45:51 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 17:35:20 +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-12-10 10:12:51 +00:00
|
|
|
func (i IdentityImage) Hash() []byte {
|
|
|
|
return crypto.Keccak256(i.Payload)
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:45:51 +00:00
|
|
|
func (i IdentityImage) GetDataURI() (string, error) {
|
2020-11-18 12:41:36 +00:00
|
|
|
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 {
|
2020-11-30 16:42:52 +00:00
|
|
|
KeyUID string `json:"keyUid"`
|
2020-10-27 15:41:20 +00:00
|
|
|
Name string `json:"type"`
|
2020-10-26 17:45:51 +00:00
|
|
|
URI string `json:"uri"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Height int `json:"height"`
|
2020-11-30 16:42:52 +00:00
|
|
|
FileSize int `json:"fileSize"`
|
|
|
|
ResizeTarget int `json:"resizeTarget"`
|
2022-03-24 09:35:56 +00:00
|
|
|
Clock uint64 `json:"clock"`
|
2020-10-26 17:45:51 +00:00
|
|
|
}{
|
2020-11-24 13:13:46 +00:00
|
|
|
KeyUID: i.KeyUID,
|
2020-10-27 15:41:20 +00:00
|
|
|
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,
|
2022-03-24 09:35:56 +00:00
|
|
|
Clock: i.Clock,
|
2020-10-26 17:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return json.Marshal(temp)
|
|
|
|
}
|
2022-06-27 13:48:00 +00:00
|
|
|
|
|
|
|
func (i IdentityImage) IsEmpty() bool {
|
|
|
|
if i.KeyUID == "" && i.Name == "" && len(i.Payload) == 0 && i.Width == 0 && i.Height == 0 && i.FileSize == 0 && i.ResizeTarget == 0 && i.Clock == 0 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|