Implemented API for full CRD of IdentityImages

This commit is contained in:
Samuel Hawksby-Robinson 2020-10-27 15:26:22 +00:00 committed by Andrea Maria Piana
parent 2960fc49d4
commit fcbd9285f6
2 changed files with 46 additions and 7 deletions

View file

@ -1271,8 +1271,8 @@ func (b *GethStatusBackend) SignHash(hexEncodedHash string) (string, error) {
return hexEncodedSignature, nil
}
// GetProfileImages returns an array of base64 encoded images related to the user's profile
func (b *GethStatusBackend) GetProfileImages() (string, error) {
// GetIdentityImages returns an array of json marshalled IdentityImages assigned to the user's identity
func (b *GethStatusBackend) GetIdentityImages() (string, error) {
idb := images.NewDatabase(b.appDB)
iis, err := idb.GetIdentityImages()
if err != nil {
@ -1284,11 +1284,24 @@ func (b *GethStatusBackend) GetProfileImages() (string, error) {
return string(js), err
}
// SaveProfileImage takes the filepath of an image, crops it as per the rect coords and finally resizes the image.
// GetIdentityImage returns a json object representing the image with the given name
func (b *GethStatusBackend) GetIdentityImage(name string) (string, error) {
idb := images.NewDatabase(b.appDB)
ii, err := idb.GetIdentityImage(name)
if err != nil {
return "", err
}
js, err := json.Marshal(ii)
return string(js), err
}
// StoreIdentityImage takes the filepath of an image, crops it as per the rect coords and finally resizes the image.
// The resulting image(s) will be stored in the DB along with other user account information.
// aX and aY represent the pixel coordinates of the upper left corner of the image's cropping area
// bX and bY represent the pixel coordinates of the lower right corner of the image's cropping area
func (b *GethStatusBackend) SaveProfileImage(filepath string, aX, aY, bX, bY int) (string, error) {
func (b *GethStatusBackend) StoreIdentityImage(filepath string, aX, aY, bX, bY int) (string, error) {
iis, err := images.GenerateIdentityImages(filepath, aX, aY, bX, bY)
if err != nil {
return "", err
@ -1304,3 +1317,9 @@ func (b *GethStatusBackend) SaveProfileImage(filepath string, aX, aY, bX, bY int
return string(js), err
}
// DeleteIdentityImage deletes an IdentityImage from the db with the given name
func (b *GethStatusBackend) DeleteIdentityImage(name string) error {
idb := images.NewDatabase(b.appDB)
return idb.DeleteIdentityImage(name)
}

View file

@ -629,9 +629,9 @@ func MultiformatDeserializePublicKey(key, outBase string) string {
return pk
}
// GetProfileImages returns an array of base64 encoded images related to the user's profile
// GetProfileImages returns an array of json marshalled IdentityImages assigned to the user's identity
func GetProfileImages() string {
pis, err := statusBackend.GetProfileImages()
pis, err := statusBackend.GetIdentityImages()
if err != nil {
return makeJSONResponse(err)
}
@ -639,15 +639,35 @@ func GetProfileImages() string {
return pis
}
// GetProfileImage returns a json object representing the image with the given name
func GetProfileImage(name string) string {
ii, err := statusBackend.GetIdentityImage(name)
if err != nil {
return makeJSONResponse(err)
}
return ii
}
// SaveProfileImage takes the filepath of an image, crops it as per the rect coords and finally resizes the image.
// The resulting image(s) will be stored in the DB along with other user account information.
// aX and aY represent the pixel coordinates of the upper left corner of the image's cropping area
// bX and bY represent the pixel coordinates of the lower right corner of the image's cropping area
func SaveProfileImage(filepath string, aX, aY, bX, bY int) string {
imgs, err := statusBackend.SaveProfileImage(filepath, aX, aY, bX, bY)
imgs, err := statusBackend.StoreIdentityImage(filepath, aX, aY, bX, bY)
if err != nil {
return makeJSONResponse(err)
}
return imgs
}
// DeleteProfileImage deletes an IdentityImage from the db with the given name
func DeleteProfileImage(name string) string {
err := statusBackend.DeleteIdentityImage(name)
if err != nil {
return makeJSONResponse(err)
}
return "ok"
}