mirror of
https://github.com/status-im/status-go.git
synced 2025-03-03 16:11:05 +00:00
fix_: ensure generated identity-images have a valid clock value (#6239)
This changes updates the logic for generating identity-images to populate the `clock` value instead of initialising with zero. This change also updates the identity-image url format functions to include the `clock` value in the returned url so clients can rely on that url for triggering refetches of identity images when they've been updated.
This commit is contained in:
parent
bb7b1f246d
commit
e6738e5343
@ -3,6 +3,7 @@ package images
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error) {
|
||||
@ -25,6 +26,7 @@ func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error) {
|
||||
Height: rImg.Bounds().Dy(),
|
||||
FileSize: bb.Len(),
|
||||
ResizeTarget: int(s),
|
||||
Clock: uint64(time.Now().UnixMilli()),
|
||||
}
|
||||
|
||||
iis = append(iis, ii)
|
||||
|
@ -44,3 +44,27 @@ func TestGenerateBannerImage_ShrinkOnly(t *testing.T) {
|
||||
require.Exactly(t, identityImage.Width, int(BannerDim))
|
||||
require.Exactly(t, identityImage.Height, 805)
|
||||
}
|
||||
|
||||
func TestGenerateIdentityImages(t *testing.T) {
|
||||
// Create image data
|
||||
testImage := image.NewRGBA(image.Rect(0, 0, int(BannerDim)+10, int(BannerDim)+20))
|
||||
|
||||
// Create a temporary file for storing the image data
|
||||
tmpTestFilePath := t.TempDir() + "/test.png"
|
||||
file, err := os.Create(tmpTestFilePath)
|
||||
require.NoError(t, err)
|
||||
defer file.Close()
|
||||
|
||||
// Save the image data to the temporary file
|
||||
err = png.Encode(file, testImage)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Generate the identity images
|
||||
identityImages, err := GenerateIdentityImages(tmpTestFilePath, 100, 100, 500, 500)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check the identity images have a valid clock value
|
||||
for _, image := range identityImages {
|
||||
require.NotEqual(t, image.Clock, uint64(0))
|
||||
}
|
||||
}
|
||||
|
@ -779,7 +779,7 @@ func (m *Messenger) updateContactImagesURL(contact *Contact) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.LocalURL = m.httpServer.MakeContactImageURL(common.PubkeyToHex(publicKey), k)
|
||||
v.LocalURL = m.httpServer.MakeContactImageURL(common.PubkeyToHex(publicKey), k, v.Clock)
|
||||
contact.Images[k] = v
|
||||
}
|
||||
}
|
||||
|
@ -230,10 +230,10 @@ func (s *MediaServer) MakeQRURL(qurul string,
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func (s *MediaServer) MakeContactImageURL(publicKey string, imageType string) string {
|
||||
func (s *MediaServer) MakeContactImageURL(publicKey string, imageType string, imageClock uint64) string {
|
||||
u := s.MakeBaseURL()
|
||||
u.Path = contactImagesPath
|
||||
u.RawQuery = url.Values{"publicKey": {publicKey}, "imageName": {imageType}}.Encode()
|
||||
u.RawQuery = url.Values{"publicKey": {publicKey}, "imageName": {imageType}, "clock": {fmt.Sprint(imageClock)}}.Encode()
|
||||
|
||||
return u.String()
|
||||
}
|
||||
|
@ -145,6 +145,15 @@ func (s *ServerURLSuite) TestServer_MakeStickerURL() {
|
||||
s.serverNoPort.MakeStickerURL("0xdeadbeef4ac0"))
|
||||
}
|
||||
|
||||
func (s *ServerURLSuite) TestServer_MakeContactImageURL() {
|
||||
s.Require().Equal(
|
||||
baseURLWithCustomPort+"/contactImages?clock=1&imageName=Test&publicKey=0x1",
|
||||
s.server.MakeContactImageURL("0x1", "Test", uint64(1)))
|
||||
s.testNoPort(
|
||||
baseURLWithDefaultPort+"/contactImages?clock=1&imageName=Test&publicKey=0x1",
|
||||
s.serverNoPort.MakeContactImageURL("0x1", "Test", uint64(1)))
|
||||
}
|
||||
|
||||
// TestQRCodeGeneration tests if we provide all the correct parameters to the media server
|
||||
// do we get a valid QR code or not as part of the response payload.
|
||||
// we have stored a generated QR code in tests folder, and we compare their bytes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user