From 839ffb3be4642717111d25f3bc06739dde539613 Mon Sep 17 00:00:00 2001 From: radazen Date: Thu, 24 Oct 2024 13:26:58 -0400 Subject: [PATCH] Use original images instead of imgix (#1541) * Fix docker compose syntax * Make imgix optional, and return GIFMedia for gifs * Update tests --- Makefile | 20 +++++++------- graphql/graphql_test.go | 2 +- graphql/resolver/schema.resolvers.helpers.go | 29 ++++---------------- service/mediamapper/mediamapper.go | 22 +++++++++++++++ 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index dac4e2983..b7396ef1d 100644 --- a/Makefile +++ b/Makefile @@ -548,16 +548,16 @@ abi-gen: # Miscellaneous stuff docker-start-clean: docker-build - docker-compose up -d + docker compose up -d docker-build: docker-stop - docker-compose build + docker compose build docker-start: docker-stop - docker-compose up -d + docker compose up -d docker-stop: - docker-compose down + docker compose down format-graphql: yarn install; @@ -565,13 +565,13 @@ format-graphql: yarn prettier --write graphql/testdata/operations.graphql; start-local-graphql-gateway: - docker-compose -f docker/graphql-gateway/docker-compose.yml up --build -d graphql-gateway-local + docker compose -f docker/graphql-gateway/docker-compose.yml up --build -d graphql-gateway-local start-dev-graphql-gateway: - docker-compose -f docker/graphql-gateway/docker-compose.yml up --build -d graphql-gateway-dev + docker compose -f docker/graphql-gateway/docker-compose.yml up --build -d graphql-gateway-dev start-prod-graphql-gateway: - docker-compose -f docker/graphql-gateway/docker-compose.yml up --build -d graphql-gateway-prod + docker compose -f docker/graphql-gateway/docker-compose.yml up --build -d graphql-gateway-prod # Listing targets as dependencies doesn't pull in target-specific secrets, so we need to # invoke $(MAKE) here to read appropriate secrets for each target. @@ -580,13 +580,13 @@ start-sql-proxy: $(MAKE) start-prod-sql-proxy start-dev-sql-proxy: - docker-compose -f docker/cloud_sql_proxy/docker-compose.yml up -d cloud-sql-proxy-dev + docker compose -f docker/cloud_sql_proxy/docker-compose.yml up -d cloud-sql-proxy-dev start-prod-sql-proxy: - docker-compose -f docker/cloud_sql_proxy/docker-compose.yml up -d cloud-sql-proxy-prod + docker compose -f docker/cloud_sql_proxy/docker-compose.yml up -d cloud-sql-proxy-prod stop-sql-proxy: - docker-compose -f docker/cloud_sql_proxy/docker-compose.yml down + docker compose -f docker/cloud_sql_proxy/docker-compose.yml down migrate-local-coredb: go run cmd/migrate/main.go diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index c7c62c894..d115affb9 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -1068,7 +1068,7 @@ func testSyncShouldProcessMedia(t *testing.T) { response, err := syncTokensMutation(ctx, c, []Chain{ChainEthereum}, nil) tokens := assertSyncedTokens(t, response, err, 1) - media := waitForSynced[*syncTokensMutationSyncTokensSyncTokensPayloadViewerUserGalleryUserTokensTokenMediaVideoMedia](*tokens[0].Media) + media := waitForSynced[*syncTokensMutationSyncTokensSyncTokensPayloadViewerUserGalleryUserTokensTokenMediaGIFMedia](*tokens[0].Media) assert.Equal(t, string(persist.MediaTypeGIF), *media.MediaType) assert.NotEmpty(t, *media.MediaURL) }) diff --git a/graphql/resolver/schema.resolvers.helpers.go b/graphql/resolver/schema.resolvers.helpers.go index 81470923d..66cd1593a 100644 --- a/graphql/resolver/schema.resolvers.helpers.go +++ b/graphql/resolver/schema.resolvers.helpers.go @@ -2527,34 +2527,15 @@ func getFallbackMedia(ctx context.Context, media persist.FallbackMedia) *model.F } } -// getGIFMedia returns VideoMedia because we convert GIFs to videos. -func getGIFMedia(ctx context.Context, tokenMedia db.TokenMedia, fallbackMedia *model.FallbackMedia, darkMode persist.DarkMode) model.VideoMedia { +func getGIFMedia(ctx context.Context, tokenMedia db.TokenMedia, fallbackMedia *model.FallbackMedia, darkMode persist.DarkMode) model.GIFMedia { url := remapLargeImageUrls(tokenMedia.Media.MediaURL.String()) - options := make([]mediamapper.Option, 2) - options[0] = mediamapper.WithFormatVideo() - - // GIFs support transparency, but MP4s don't, so we need to set a background color for the MP4 - // that will look transparent. - if darkMode == persist.DarkModeEnabled { - options[1] = mediamapper.WithBackgroundColor(darkModeMP4BackgroundColor) - } else { - options[1] = mediamapper.WithBackgroundColor(lightModeMP4BackgroundColor) - } - - mm := mediamapper.For(ctx) - videoUrls := model.VideoURLSet{ - Raw: util.ToPointer(mm.GetLargeImageUrl(url, options...)), - Small: util.ToPointer(mm.GetSmallImageUrl(url, options...)), - Medium: util.ToPointer(mm.GetMediumImageUrl(url, options...)), - Large: util.ToPointer(mm.GetLargeImageUrl(url, options...)), - } - - return model.VideoMedia{ - PreviewURLs: previewURLsFromTokenMedia(ctx, tokenMedia, mediamapper.WithStaticImage()), + return model.GIFMedia{ + PreviewURLs: previewURLsFromTokenMedia(ctx, tokenMedia), + StaticPreviewURLs: previewURLsFromTokenMedia(ctx, tokenMedia, mediamapper.WithStaticImage()), MediaURL: util.ToPointer(tokenMedia.Media.MediaURL.String()), MediaType: (*string)(&tokenMedia.Media.MediaType), - ContentRenderURLs: &videoUrls, + ContentRenderURL: &url, Dimensions: mediaToDimensions(tokenMedia.Media.Dimensions), FallbackMedia: fallbackMedia, } diff --git a/service/mediamapper/mediamapper.go b/service/mediamapper/mediamapper.go index e0ded1d75..eeef6b850 100644 --- a/service/mediamapper/mediamapper.go +++ b/service/mediamapper/mediamapper.go @@ -23,6 +23,8 @@ const contextKey = "mediamapper.instance" const assetDomain = "assets.gallery.so" +const imgixEnabled = false + const ( thumbnailWidth = 64 smallWidth = 204 @@ -104,6 +106,10 @@ func getDefaultParams() []imgix.IxParam { } func (u *MediaMapper) buildPreviewImageUrl(sourceUrl string, width int, params []imgix.IxParam, options ...Option) string { + if !imgixEnabled { + return setGoogleWidthParams(sourceUrl, width) + } + if sourceUrl == "" { return sourceUrl } @@ -115,6 +121,10 @@ func (u *MediaMapper) buildPreviewImageUrl(sourceUrl string, width int, params [ } func (u *MediaMapper) buildSrcSet(sourceUrl string, params []imgix.IxParam, options ...Option) string { + if !imgixEnabled { + return sourceUrl + } + if sourceUrl == "" { return sourceUrl } @@ -201,6 +211,10 @@ func (u *MediaMapper) GetSrcSet(sourceUrl string, options ...Option) string { } func (u *MediaMapper) GetBlurhash(sourceUrl string) *string { + if !imgixEnabled { + return nil + } + url := u.urlBuilder.CreateURL(sourceUrl, imgix.Param("fm", "blurhash")) req, err := http.NewRequestWithContext(context.Background(), "GET", url, bytes.NewBuffer([]byte{})) @@ -229,6 +243,10 @@ func (u *MediaMapper) GetBlurhash(sourceUrl string) *string { } func (u *MediaMapper) GetAspectRatio(sourceUrl string) *float64 { + if !imgixEnabled { + return nil + } + url := u.urlBuilder.CreateURL(sourceUrl, buildParams(getDefaultParams(), imgix.Param("fm", "json"))...) rawResponse, err := http.Get(url) @@ -264,6 +282,10 @@ func (u *MediaMapper) GetAspectRatio(sourceUrl string) *float64 { } func PurgeImage(ctx context.Context, u string) error { + if !imgixEnabled { + return nil + } + // '{ "data": { "attributes": { "url": "" }, "type": "purges" } }' body := map[string]interface{}{ "data": map[string]interface{}{