diff --git a/app/logical/sources/strategies/foundation.rb b/app/logical/sources/strategies/foundation.rb index 9666db76f..a07535248 100644 --- a/app/logical/sources/strategies/foundation.rb +++ b/app/logical/sources/strategies/foundation.rb @@ -6,6 +6,8 @@ # Page URLs # # * https://foundation.app/@mochiiimo/~/97376 +# * https://foundation.app/@mochiiimo/foundation/97376 +# * https://foundation.app/@KILLERGF/kgfgen/4 # * https://foundation.app/@huwari/~/88982 (video) # # Even if the username is wrong, the ID is still fetched correctly. Example: @@ -24,7 +26,7 @@ module Sources class Foundation < Base BASE_URL = %r{\Ahttps?://(www\.)?foundation\.app}i PROFILE_URL = %r{#{BASE_URL}/@(?[^/]+)/?}i - PAGE_URL = %r{#{PROFILE_URL}/~/(?\d+)}i + PAGE_URL = %r{#{PROFILE_URL}/[^/]+/(?\d+)}i IMAGE_HOST = /f8n-ipfs-production\.imgix\.net/ IMAGE_URL = %r{\Ahttps?://#{IMAGE_HOST}/\w+/nft.\w+}i @@ -50,7 +52,7 @@ module Sources image = "https://f8n-ipfs-production.imgix.net/#{$1}/nft.#{$2}" end - [image] + [image].compact end def preview_urls diff --git a/app/models/upload_media_asset.rb b/app/models/upload_media_asset.rb index 3cdbc591f..43d1b6334 100644 --- a/app/models/upload_media_asset.rb +++ b/app/models/upload_media_asset.rb @@ -12,6 +12,10 @@ class UploadMediaAsset < ApplicationRecord after_create :async_process_upload! after_save :update_upload_status, if: :saved_change_to_status? + # XXX there are ~150 old assets with blank source urls because the source went bad id before the image url could be saved. + validates :source_url, format: { with: %r{\A(https?|file)://}i, message: "is not a valid URL" } + validates :page_url, format: { with: %r{\A(https?)://}i, message: "is not a valid URL" }, allow_nil: true + enum status: { pending: 0, processing: 100, diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 12721f61e..47e478f4f 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -334,6 +334,10 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest should_upload_successfully("https://kmyama.fanbox.cc/posts/104708") should_upload_successfully("https://downloads.fanbox.cc/images/post/104708/wsF73EC5Fq0CIK84W0LGYk2p.jpeg") + + should_upload_successfully("https://foundation.app/@mochiiimo/~/97376") + should_upload_successfully("https://foundation.app/@mochiiimo/foundation/97376") + should_upload_successfully("https://foundation.app/@KILLERGF/kgfgen/4") end end end diff --git a/test/unit/sources/foundation_test.rb b/test/unit/sources/foundation_test.rb index 3169f7d78..87227c3b8 100644 --- a/test/unit/sources/foundation_test.rb +++ b/test/unit/sources/foundation_test.rb @@ -50,6 +50,25 @@ module Sources end end + context "for a collection" do + should "get the image urls" do + assert_equal( + ["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"], + Sources::Strategies.find("https://foundation.app/@mochiiimo/~/97376").image_urls, + ) + + assert_equal( + ["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"], + Sources::Strategies.find("https://foundation.app/@mochiiimo/foundation/97376").image_urls, + ) + + assert_equal( + ["https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png"], + Sources::Strategies.find("https://foundation.app/@KILLERGF/kgfgen/4").image_urls, + ) + end + end + context "non-alphanumeric usernames" do should "still work" do case1 = Sources::Strategies.find("https://foundation.app/@brandon.dalmer/~/6792")