From 4d362e26bacc08aeab4313595ff8ededf3504129 Mon Sep 17 00:00:00 2001 From: goga-m Date: Fri, 27 Oct 2023 14:25:40 +0200 Subject: [PATCH 01/13] wip --- app/Support/NftImageUrl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Support/NftImageUrl.php b/app/Support/NftImageUrl.php index a3ce76c63..b97d7f4ec 100644 --- a/app/Support/NftImageUrl.php +++ b/app/Support/NftImageUrl.php @@ -55,8 +55,9 @@ private static function getAlchemyCdn(string $url, ?ImageSize $imageSize): ?stri $size = 'w_'.$imageSize->width().',h_'.$imageSize->height(); $newPath = preg_replace('/(?<=\/)upload(?=\/)/', "upload/{$size}", $path); + $scaledPath = preg_replace('/thumbnailv2/', "scaled", $newPath); - $url = str_replace($path, $newPath, $url); + $url = str_replace($path, $scaledPath, $url); } return $url; From baae8dd5613ccc5acdf0820ba597289fa9d64ffd Mon Sep 17 00:00:00 2001 From: goga-m Date: Fri, 27 Oct 2023 13:14:22 +0000 Subject: [PATCH 02/13] style: resolve style guide violations --- app/Support/NftImageUrl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Support/NftImageUrl.php b/app/Support/NftImageUrl.php index b97d7f4ec..1e52976ec 100644 --- a/app/Support/NftImageUrl.php +++ b/app/Support/NftImageUrl.php @@ -55,7 +55,7 @@ private static function getAlchemyCdn(string $url, ?ImageSize $imageSize): ?stri $size = 'w_'.$imageSize->width().',h_'.$imageSize->height(); $newPath = preg_replace('/(?<=\/)upload(?=\/)/', "upload/{$size}", $path); - $scaledPath = preg_replace('/thumbnailv2/', "scaled", $newPath); + $scaledPath = preg_replace('/thumbnailv2/', 'scaled', $newPath); $url = str_replace($path, $scaledPath, $url); } From 7d4af458b040ee04c335f280485540e26c457425 Mon Sep 17 00:00:00 2001 From: goga-m Date: Fri, 27 Oct 2023 15:38:19 +0200 Subject: [PATCH 03/13] wip --- tests/App/Support/NftImageUrlTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/App/Support/NftImageUrlTest.php b/tests/App/Support/NftImageUrlTest.php index 5d51e1d30..c12782d9c 100644 --- a/tests/App/Support/NftImageUrlTest.php +++ b/tests/App/Support/NftImageUrlTest.php @@ -12,8 +12,8 @@ 'OpenSea (no change)' => [null, 'https://i.seadn.io/gcs/files/5ff2b7fa5c94616f34a27e37eadfbfd1.png?w=96&auto=format', 'https://i.seadn.io/gcs/files/5ff2b7fa5c94616f34a27e37eadfbfd1.png?w=96&auto=format'], 'OpenSea (custom size)' => [ImageSize::Large, 'https://i.seadn.io/gcs/files/5ff2b7fa5c94616f34a27e37eadfbfd1.png?w=96&auto=format', 'https://i.seadn.io/gcs/files/5ff2b7fa5c94616f34a27e37eadfbfd1.png?w=512&auto=format'], - 'Alchemy (no change)' => [null, 'https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', 'https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c'], - 'Alchemy (custom size)' => [ImageSize::Thumb, 'https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', 'https://res.cloudinary.com/alchemyapi/image/upload/w_96,h_96/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c'], + 'Alchemy (no change)' => [null, 'https://res.cloudinary.com/alchemyapi/image/upload/scaled/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', 'https://res.cloudinary.com/alchemyapi/image/upload/scaled/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c'], + 'Alchemy (custom size)' => [ImageSize::Thumb, 'https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', 'https://res.cloudinary.com/alchemyapi/image/upload/w_96,h_96/scaled/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c'], 'Moralis (no change)' => [null, 'https://nft-preview-media.s3.us-east-1.amazonaws.com/evm/0x1/0xc54567b294d7ec7807529fbaec71d326543453c5/0xbecb6f250337775b7d85ef2720d80dfc2f4e0c3a94ee2486038fd5e8ac1b43d6/low.jpeg', 'https://nft-preview-media.s3.us-east-1.amazonaws.com/evm/0x1/0xc54567b294d7ec7807529fbaec71d326543453c5/0xbecb6f250337775b7d85ef2720d80dfc2f4e0c3a94ee2486038fd5e8ac1b43d6/low.jpeg'], 'Moralis (no extension, defaults to large)' => [null, 'https://nft-preview-media.s3.us-east-1.amazonaws.com/evm/0x1/0xc54567b294d7ec7807529fbaec71d326543453c5/0xbecb6f250337775b7d85ef2720d80dfc2f4e0c3a94ee2486038fd5e8ac1b43d6', 'https://nft-preview-media.s3.us-east-1.amazonaws.com/evm/0x1/0xc54567b294d7ec7807529fbaec71d326543453c5/0xbecb6f250337775b7d85ef2720d80dfc2f4e0c3a94ee2486038fd5e8ac1b43d6/high.jpeg'], @@ -39,9 +39,9 @@ ], 'Alchemy' => ['https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', [ - 'thumb' => 'https://res.cloudinary.com/alchemyapi/image/upload/w_96,h_96/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', - 'small' => 'https://res.cloudinary.com/alchemyapi/image/upload/w_256,h_256/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', - 'large' => 'https://res.cloudinary.com/alchemyapi/image/upload/w_512,h_512/thumbnailv2/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', + 'thumb' => 'https://res.cloudinary.com/alchemyapi/image/upload/w_96,h_96/scaled/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', + 'small' => 'https://res.cloudinary.com/alchemyapi/image/upload/w_256,h_256/scaled/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', + 'large' => 'https://res.cloudinary.com/alchemyapi/image/upload/w_512,h_512/scaled/eth-mainnet/f065afd5cf799f4ab1252111f8f3d38c', ], ], 'Moralis' => ['https://nft-preview-media.s3.us-east-1.amazonaws.com/evm/0x1/0xc54567b294d7ec7807529fbaec71d326543453c5/0xbecb6f250337775b7d85ef2720d80dfc2f4e0c3a94ee2486038fd5e8ac1b43d6/low.jpeg', From b540928a7695381551b42f9d87e125a5a5ec1b5f Mon Sep 17 00:00:00 2001 From: goga-m Date: Mon, 30 Oct 2023 14:40:06 +0100 Subject: [PATCH 04/13] wip --- ..._115558_update_nft_thumbnail_to_scaled.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php new file mode 100644 index 000000000..2d453c82d --- /dev/null +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -0,0 +1,41 @@ +get()->each(function ($nft) { + $extraAttributes = json_decode($nft->extra_attributes); + + $previousThumb = $extraAttributes->images->thumb; + $previousSmall = $extraAttributes->images->small; + $previousLarge = $extraAttributes->images->large; + + $extraAttributes->images->thumb = $this->replaceThumbnailsWithScaled($extraAttributes->images->thumb); + $extraAttributes->images->small = $this->replaceThumbnailsWithScaled($extraAttributes->images->small); + $extraAttributes->images->large = $this->replaceThumbnailsWithScaled($extraAttributes->images->large); + + if($previousThumb !== $extraAttributes->images->thumb || $previousSmall !== $extraAttributes->images->small || $previousLarge !== $extraAttributes->images->large) { + DB::table('nfts') + ->where('id', $nft->id) + ->update(['extra_attributes' => json_encode($extraAttributes)]); + } + + }); + } + + public function replaceThumbnailsWithScaled(string $url): string + { + return preg_replace('/thumbnailv2/', 'scaled', $url); + } +}; From 34bd3922c2942a6687dba47b6af9bcda80537673 Mon Sep 17 00:00:00 2001 From: goga-m Date: Mon, 30 Oct 2023 13:46:28 +0000 Subject: [PATCH 05/13] style: resolve style guide violations --- ...23_10_30_115558_update_nft_thumbnail_to_scaled.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index 2d453c82d..d8d6033e5 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -1,13 +1,12 @@ images->small = $this->replaceThumbnailsWithScaled($extraAttributes->images->small); $extraAttributes->images->large = $this->replaceThumbnailsWithScaled($extraAttributes->images->large); - if($previousThumb !== $extraAttributes->images->thumb || $previousSmall !== $extraAttributes->images->small || $previousLarge !== $extraAttributes->images->large) { + if ($previousThumb !== $extraAttributes->images->thumb || $previousSmall !== $extraAttributes->images->small || $previousLarge !== $extraAttributes->images->large) { DB::table('nfts') ->where('id', $nft->id) ->update(['extra_attributes' => json_encode($extraAttributes)]); From a1416c3f6814f1697375f924fba523566c0be187 Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 31 Oct 2023 09:25:26 +0100 Subject: [PATCH 06/13] wip --- ..._115558_update_nft_thumbnail_to_scaled.php | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index d8d6033e5..23f14230f 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -5,32 +5,27 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class() extends Migration -{ +return new class () extends Migration { /** * Run the migrations. */ public function up(): void { + DB::table('nfts') + ->whereRaw("extra_attributes->'images'->>'thumb' LIKE '%thumbnailv2%'") + ->orWhereRaw("extra_attributes->'images'->>'small' LIKE '%thumbnailv2%'") + ->orWhereRaw("extra_attributes->'images'->>'large' LIKE '%thumbnailv2%'")->get()->each(function ($nft) { + $extraAttributes = json_decode($nft->extra_attributes); - DB::table('nfts')->get()->each(function ($nft) { - $extraAttributes = json_decode($nft->extra_attributes); + $extraAttributes->images->thumb = $this->replaceThumbnailsWithScaled($extraAttributes->images->thumb); + $extraAttributes->images->small = $this->replaceThumbnailsWithScaled($extraAttributes->images->small); + $extraAttributes->images->large = $this->replaceThumbnailsWithScaled($extraAttributes->images->large); - $previousThumb = $extraAttributes->images->thumb; - $previousSmall = $extraAttributes->images->small; - $previousLarge = $extraAttributes->images->large; - - $extraAttributes->images->thumb = $this->replaceThumbnailsWithScaled($extraAttributes->images->thumb); - $extraAttributes->images->small = $this->replaceThumbnailsWithScaled($extraAttributes->images->small); - $extraAttributes->images->large = $this->replaceThumbnailsWithScaled($extraAttributes->images->large); - - if ($previousThumb !== $extraAttributes->images->thumb || $previousSmall !== $extraAttributes->images->small || $previousLarge !== $extraAttributes->images->large) { DB::table('nfts') ->where('id', $nft->id) ->update(['extra_attributes' => json_encode($extraAttributes)]); - } - }); + }); } public function replaceThumbnailsWithScaled(string $url): string From db7cfd7f53b529e2602b637b1ce3288b12ff197e Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 31 Oct 2023 08:27:30 +0000 Subject: [PATCH 07/13] style: resolve style guide violations --- .../2023_10_30_115558_update_nft_thumbnail_to_scaled.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index 23f14230f..211122ddb 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -5,7 +5,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class () extends Migration { +return new class() extends Migration +{ /** * Run the migrations. */ From a2d79ade69ab462a854c48aa1be2e7d8fb609078 Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 31 Oct 2023 16:06:24 +0100 Subject: [PATCH 08/13] wip --- ..._115558_update_nft_thumbnail_to_scaled.php | 24 ++----------------- queries/nfts.update_thumbnailv2_to_scaled.sql | 23 ++++++++++++++++++ 2 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 queries/nfts.update_thumbnailv2_to_scaled.sql diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index 211122ddb..7fb8308eb 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -5,32 +5,12 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class() extends Migration -{ +return new class () extends Migration { /** * Run the migrations. */ public function up(): void { - DB::table('nfts') - ->whereRaw("extra_attributes->'images'->>'thumb' LIKE '%thumbnailv2%'") - ->orWhereRaw("extra_attributes->'images'->>'small' LIKE '%thumbnailv2%'") - ->orWhereRaw("extra_attributes->'images'->>'large' LIKE '%thumbnailv2%'")->get()->each(function ($nft) { - $extraAttributes = json_decode($nft->extra_attributes); - - $extraAttributes->images->thumb = $this->replaceThumbnailsWithScaled($extraAttributes->images->thumb); - $extraAttributes->images->small = $this->replaceThumbnailsWithScaled($extraAttributes->images->small); - $extraAttributes->images->large = $this->replaceThumbnailsWithScaled($extraAttributes->images->large); - - DB::table('nfts') - ->where('id', $nft->id) - ->update(['extra_attributes' => json_encode($extraAttributes)]); - - }); - } - - public function replaceThumbnailsWithScaled(string $url): string - { - return preg_replace('/thumbnailv2/', 'scaled', $url); + DB::select(get_query('nfts.update_thumbnailv2_to_scaled')); } }; diff --git a/queries/nfts.update_thumbnailv2_to_scaled.sql b/queries/nfts.update_thumbnailv2_to_scaled.sql new file mode 100644 index 000000000..81fbac2ec --- /dev/null +++ b/queries/nfts.update_thumbnailv2_to_scaled.sql @@ -0,0 +1,23 @@ +UPDATE nfts +SET extra_attributes = + jsonb_set( + jsonb_set( + jsonb_set( + extra_attributes::jsonb, + '{images,thumb}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', '/thumbnailv2/', '/scaled/')), + true + ), + '{images,large}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', '/thumbnailv2/', '/scaled/')), + true + ), + '{images,small}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', '/thumbnailv2/', '/scaled/')), + true + )::json + +WHERE + extra_attributes->'images'->>'thumb' LIKE '%/thumbnailv2/%' + OR extra_attributes->'images'->>'large' LIKE '%/thumbnailv2/%' + OR extra_attributes->'images'->>'small' LIKE '%/thumbnailv2/%'; From a6e5cac4f3878ad81c23127a02724e83bbcb8cff Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 31 Oct 2023 16:29:46 +0100 Subject: [PATCH 09/13] wip --- ..._115558_update_nft_thumbnail_to_scaled.php | 25 ++++++++++++++++++- queries/nfts.update_thumbnailv2_to_scaled.sql | 23 ----------------- 2 files changed, 24 insertions(+), 24 deletions(-) delete mode 100644 queries/nfts.update_thumbnailv2_to_scaled.sql diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index 7fb8308eb..c57cd4336 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -11,6 +11,29 @@ */ public function up(): void { - DB::select(get_query('nfts.update_thumbnailv2_to_scaled')); + DB::select(" + UPDATE nfts + SET extra_attributes = + jsonb_set( + jsonb_set( + jsonb_set( + extra_attributes::jsonb, + '{images,thumb}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', '/thumbnailv2/', '/scaled/')), + true + ), + '{images,large}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', '/thumbnailv2/', '/scaled/')), + true + ), + '{images,small}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', '/thumbnailv2/', '/scaled/')), + true + )::json + + WHERE + extra_attributes->'images'->>'thumb' LIKE '%/thumbnailv2/%' + OR extra_attributes->'images'->>'large' LIKE '%/thumbnailv2/%' + OR extra_attributes->'images'->>'small' LIKE '%/thumbnailv2/%'; "); } }; diff --git a/queries/nfts.update_thumbnailv2_to_scaled.sql b/queries/nfts.update_thumbnailv2_to_scaled.sql deleted file mode 100644 index 81fbac2ec..000000000 --- a/queries/nfts.update_thumbnailv2_to_scaled.sql +++ /dev/null @@ -1,23 +0,0 @@ -UPDATE nfts -SET extra_attributes = - jsonb_set( - jsonb_set( - jsonb_set( - extra_attributes::jsonb, - '{images,thumb}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', '/thumbnailv2/', '/scaled/')), - true - ), - '{images,large}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', '/thumbnailv2/', '/scaled/')), - true - ), - '{images,small}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', '/thumbnailv2/', '/scaled/')), - true - )::json - -WHERE - extra_attributes->'images'->>'thumb' LIKE '%/thumbnailv2/%' - OR extra_attributes->'images'->>'large' LIKE '%/thumbnailv2/%' - OR extra_attributes->'images'->>'small' LIKE '%/thumbnailv2/%'; From 94293e2320a29d47ad1abb28f3535554c5194700 Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 31 Oct 2023 15:33:04 +0000 Subject: [PATCH 10/13] style: resolve style guide violations --- .../2023_10_30_115558_update_nft_thumbnail_to_scaled.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index c57cd4336..e4eea88ff 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -5,7 +5,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class () extends Migration { +return new class() extends Migration +{ /** * Run the migrations. */ From da9c96d14dc3df59633ee050205743dfa0a641c6 Mon Sep 17 00:00:00 2001 From: goga-m Date: Tue, 31 Oct 2023 16:45:23 +0100 Subject: [PATCH 11/13] wip This reverts commit a6e5cac4f3878ad81c23127a02724e83bbcb8cff. --- ..._115558_update_nft_thumbnail_to_scaled.php | 25 +------------------ ...ions.nfts.update_thumbnailv2_to_scaled.sql | 23 +++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 queries/migrations.nfts.update_thumbnailv2_to_scaled.sql diff --git a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php index e4eea88ff..08c0ef353 100644 --- a/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php +++ b/database/migrations/2023_10_30_115558_update_nft_thumbnail_to_scaled.php @@ -12,29 +12,6 @@ */ public function up(): void { - DB::select(" - UPDATE nfts - SET extra_attributes = - jsonb_set( - jsonb_set( - jsonb_set( - extra_attributes::jsonb, - '{images,thumb}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', '/thumbnailv2/', '/scaled/')), - true - ), - '{images,large}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', '/thumbnailv2/', '/scaled/')), - true - ), - '{images,small}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', '/thumbnailv2/', '/scaled/')), - true - )::json - - WHERE - extra_attributes->'images'->>'thumb' LIKE '%/thumbnailv2/%' - OR extra_attributes->'images'->>'large' LIKE '%/thumbnailv2/%' - OR extra_attributes->'images'->>'small' LIKE '%/thumbnailv2/%'; "); + DB::select(get_query('migrations.nfts.update_thumbnailv2_to_scaled')); } }; diff --git a/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql b/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql new file mode 100644 index 000000000..81fbac2ec --- /dev/null +++ b/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql @@ -0,0 +1,23 @@ +UPDATE nfts +SET extra_attributes = + jsonb_set( + jsonb_set( + jsonb_set( + extra_attributes::jsonb, + '{images,thumb}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', '/thumbnailv2/', '/scaled/')), + true + ), + '{images,large}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', '/thumbnailv2/', '/scaled/')), + true + ), + '{images,small}', + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', '/thumbnailv2/', '/scaled/')), + true + )::json + +WHERE + extra_attributes->'images'->>'thumb' LIKE '%/thumbnailv2/%' + OR extra_attributes->'images'->>'large' LIKE '%/thumbnailv2/%' + OR extra_attributes->'images'->>'small' LIKE '%/thumbnailv2/%'; From 8b1da958847f3a18c9341f752adaf60a1fa4bc23 Mon Sep 17 00:00:00 2001 From: goga-m Date: Wed, 1 Nov 2023 12:53:43 +0100 Subject: [PATCH 12/13] wip --- app/Support/NftImageUrl.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Support/NftImageUrl.php b/app/Support/NftImageUrl.php index 1e52976ec..f601d63c7 100644 --- a/app/Support/NftImageUrl.php +++ b/app/Support/NftImageUrl.php @@ -55,6 +55,12 @@ private static function getAlchemyCdn(string $url, ?ImageSize $imageSize): ?stri $size = 'w_'.$imageSize->width().',h_'.$imageSize->height(); $newPath = preg_replace('/(?<=\/)upload(?=\/)/', "upload/{$size}", $path); + + // Remove the height & replace thumbnailv2, to keep the proper aspect ratio if width is given. + // E.g `w_512,h_512/thumbnailv2` becomes `w_512/scaled` + $scaledPath = preg_replace('/,h_\d+\/thumbnailv2/', '/scaled', $newPath); + + // Replace thumbnailv2 for those that don't have dimensions specified. $scaledPath = preg_replace('/thumbnailv2/', 'scaled', $newPath); $url = str_replace($path, $scaledPath, $url); From 1a318b031999617c38c06e9e1491af53dacb927f Mon Sep 17 00:00:00 2001 From: goga-m Date: Thu, 2 Nov 2023 14:58:32 +0100 Subject: [PATCH 13/13] wip --- app/Support/NftImageUrl.php | 4 ++-- queries/migrations.nfts.update_thumbnailv2_to_scaled.sql | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Support/NftImageUrl.php b/app/Support/NftImageUrl.php index f601d63c7..02129c896 100644 --- a/app/Support/NftImageUrl.php +++ b/app/Support/NftImageUrl.php @@ -56,11 +56,11 @@ private static function getAlchemyCdn(string $url, ?ImageSize $imageSize): ?stri $size = 'w_'.$imageSize->width().',h_'.$imageSize->height(); $newPath = preg_replace('/(?<=\/)upload(?=\/)/', "upload/{$size}", $path); - // Remove the height & replace thumbnailv2, to keep the proper aspect ratio if width is given. + // Remove the height & replace thumbnailv2, to keep the proper aspect ratio when width is given. // E.g `w_512,h_512/thumbnailv2` becomes `w_512/scaled` $scaledPath = preg_replace('/,h_\d+\/thumbnailv2/', '/scaled', $newPath); - // Replace thumbnailv2 for those that don't have dimensions specified. + // Replace thumbnailv2 for those that don't have dimensions specified (if any). $scaledPath = preg_replace('/thumbnailv2/', 'scaled', $newPath); $url = str_replace($path, $scaledPath, $url); diff --git a/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql b/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql index 81fbac2ec..5f84b3cb3 100644 --- a/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql +++ b/queries/migrations.nfts.update_thumbnailv2_to_scaled.sql @@ -5,15 +5,15 @@ SET extra_attributes = jsonb_set( extra_attributes::jsonb, '{images,thumb}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', '/thumbnailv2/', '/scaled/')), + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'thumb', ',h_\d+\/thumbnailv2', '/scaled')), true ), '{images,large}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', '/thumbnailv2/', '/scaled/')), + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'large', ',h_\d+\/thumbnailv2', '/scaled/')), true ), '{images,small}', - to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', '/thumbnailv2/', '/scaled/')), + to_jsonb(REGEXP_REPLACE(extra_attributes->'images'->>'small', ',h_\d+\/thumbnailv2', '/scaled/')), true )::json