snarfed / bridgy-fed

🌉 A bridge between decentralized social network protocols
https://fed.brid.gy
Creative Commons Zero v1.0 Universal
753 stars 39 forks source link

Rewrite Jetpack CDN image (URLs) since some instances don't load them #439

Open snarfed opened 1 year ago

snarfed commented 1 year ago

Posted a photo just now and it's not working. Forgot to include u-photo first, but then I tried attaching it to the img and then the surrounding a and updated both times. No luck, shows a black rectangle with "Not available."

https://indieweb.social/@snarfed.org@snarfed.org/109984562159038607, BF log: https://fed.brid.gy/log?start_time=1678231601&key=https://snarfed.org/2023-03-07_49461&module=

If I click on it, it links to the image on my site ok though. The a and img are fetting federated inside content, but Mastodon should be stripping the img, so I doubt that's a problem.

image

Also older post with photos aren't working either: https://indieweb.social/@snarfed.org@snarfed.org/109729051822644849 , https://indieweb.social/@snarfed.org@snarfed.org/109677037763348328

image image
snarfed commented 1 year ago

The plot thickens. Evidently u-featured works ok, this is just a u-photo issue? Examples from www.jvt.me:

snarfed commented 1 year ago

Another broken u-photo example, from gregorlove.com, 2/26:

snarfed commented 1 year ago

They're also broken on other instances, so it's not an indieweb.social thing. eg:

snarfed commented 1 year ago

Oddly gregorlove.com has two successful u-photo posts since then:

snarfed commented 1 year ago

Pruned down JSON AS2 objects from five of these examples. The second and third bad ones make sense, they have no image and their attachments aren't images. The first one though, my original example, looks identical to the two good ones except it's missing name. Guess I'll try adding that? Not holding my breath.

bad, my original example:

{
    "type": "Note",
    "id": "https://fed.brid.gy/r/https://snarfed.org/2023-03-07_49461",
    "image": {
      "type": "Image",
      "url": "https://i0.wp.com/snarfed.org/w/wp-content/uploads/2023/03/PXL_20230307_163518349-1.PANO_-scaled.jpg?ssl=1"
    },
    "attachment": [{
        "type": "Image",
        "url": "https://i0.wp.com/snarfed.org/w/wp-content/uploads/2023/03/PXL_20230307_163518349-1.PANO_-scaled.jpg?ssl=1"
    }],
}

bad:

{
    "type": "Note",
    "id": "https://fed.brid.gy/r/https://www.jvt.me/mf2/2023/03/lerm1/",
    "attachment": [{
        "type": "Note",
        "url": "https://twitter.com/juhuachai/status/1631458755480023041",
        "content": "\u201coptimal posting times\u201d \u201cstagger your posts\u201d if you see me you see me. it\u2019s in gods hands and i am not praying"
    }]
}

bad:

{
    "type": "Note",
    "id": "https://fed.brid.gy/r/https://gregorlove.com/2023/02/after-following-on-instagram/",
    "attachment": [{
        "type": "Note",
        "url": "https://manenough.com/podcast/",
        "name": "The Man Enough Podcast"
    }]
}

good:

{
    "type": "Note",
    "id": "https://fed.brid.gy/r/https://gregorlove.com/2023/03/i-usually-tend-to/",
    "image": {
      "type": "Image",
      "url": "https://gregorlove.com/site/assets/files/6398/pxl_20230304_234257890_portrait.2000x0-is.jpg",
      "name": "recent selfie"
    },
    "attachment": [{
        "type": "Image",
        "url": "https://gregorlove.com/site/assets/files/6398/pxl_20230304_234257890_portrait.2000x0-is.jpg",
        "name": "recent selfie"
    }]
}

good:

{
    "type": "Note",
    "id": "https://fed.brid.gy/r/https://gregorlove.com/2023/03/foggy-downtown/",
    "image": {
      "type": "Image",
      "url": "https://gregorlove.com/site/assets/files/6404/pxl_20230311_224353429.1500x0.jpg",
      "name": "Downtown San Diego with fog obscuring the tops of some buildings"
    },
    "attachment": [{
        "type": "Image",
        "url": "https://gregorlove.com/site/assets/files/6404/pxl_20230311_224353429.1500x0.jpg",
        "name": "Downtown San Diego with fog obscuring the tops of some buildings"
    }]
}
snarfed commented 1 year ago

Added name to the original post's image and attachment. No dice. 🤷 https://indieweb.social/@snarfed.org@snarfed.org/109984562159038607

snarfed commented 1 year ago

Oh man. I switched the image URLs from the Jetpack CDN to my site directly (snarfed.org), and that fixed it. Ugh, so that CDN is blocking Mastodon, or it's otherwise failing to fetch from it? Oh, sheesh, looks like it was just indieweb.social, the image wasn't broken on other instances, eg https://tech.lgbt/@snarfed.org@snarfed.org/109984559730340646.

I bet Reclaim Hosting is the culprit here. Ugh. https://github.com/snarfed/bridgy/issues/885

snarfed commented 1 year ago

Also, the two other bad example posts were probably unrelated, I suspect Mastodon expected their attachments were images and choked on them?

snarfed commented 1 year ago

Confirmed. I removed the attachment from one of them, and the broken image went away. https://indieweb.social/@gregorlove.com@gregorlove.com/109934332056357887

snarfed commented 1 year ago

Oh and re https://github.com/snarfed/bridgy-fed/issues/439#issuecomment-1469040563, looks like indieweb.social is hosted on https://masto.host/, not Reclaim.

snarfed commented 1 year ago

Looks like we started adding attachment for Mastodon, initially discovered in https://github.com/snarfed/bridgy-fed/issues/33#issuecomment-440965618. Evidently they still use it:

https://github.com/mastodon/mastodon/blob/65669d3c5719e72000bf26849d0ee1eaec1f9d1b/app/lib/activitypub/activity/create.rb#L255-L282

snarfed commented 1 year ago

One hacky fix here would be to auto detect WP Jetpack CDN URLs and rewrite them to the original URL. ~Unfortunate to need to do that only because Reclaim is blocking Jetpack's CDN though. (Along with what seems like half the internet.)~ (Reclaim is blocking half the internet, but evidently not the root cause here specifically.)

snarfed commented 1 year ago

https://mastodon.art/ has the same problem, and they're also on masto.host.

snarfed commented 1 year ago

Hrm, so does https://mastodon.social/ , and they're not on masto.host.

Haven't yet found anything relevant in https://github.com/mastodon/mastodon/issues

snarfed commented 1 year ago

Found an interesting workaround here: leave the img pointing to the CDN image, move the u-photo to an <a> wrapping it that points to the local (ie not CDN) image file.