How do I generate the Github camo URL for an image used in a Github wiki?
Asked Answered
M

1

7

Can someone point me how to convert from the URL I enter in a github wiki to the camo url that gets rendered? Here's why:

I am working on building custom Github pages documentation for what is currently a Github wiki. The wiki has images in it like:

http://svn.delph-in.net/erg/tags/1214/www/esd/the-garden-dog-tried-not-to-bark.png

If you browse the wiki page that includes this image, it is converted to use the Github camo proxy and looks like this:

https://camo.githubusercontent.com/30d1fc9dec67d165016698dc28b70c1e5e419baf67f6f0bdb5021091e5f889ca/687474703a2f2f73766e2e64656c70682d696e2e6e65742f6572672f746167732f313231342f7777772f6573642f7468652d67617264656e2d646f672d74726965642d6e6f742d746f2d6261726b2e706e67

That's fine, and the reasons why are described here. In fact, how it works is described here.

My problem is that I am building my google pages site using Jekyll in the manner described here. To populate the Jekyll site, I copy the markdown source from the original wiki into my Jekyll "documentation" repository to build the official docs. The original source only contains the original link, not the camo'd link. This means that the links to images are not camo'd and have one of the problems camo was meant to solve: they don't work since they are often http: references on an https page.

I was hoping there was just a setting in a Jekyll plug-in, maybe in the kramdown parser or something that would just fix this but I couldn't find any.

Then I was hoping there was just a way to generate the camo URL from the original URL since it seems straightforward as described here. However, creating the URL requires knowing what "shared secret key" github is using (I think).

Can someone point me how to convert from the URL I enter in a github wiki to the camo url that gets rendered?

Megen answered 9/9, 2022 at 19:0 Comment(2)
Just a question, do you try to put images in a folder inside the wiki repo? That way you jus link the image from inside and appear on jekyll website.Apoplexy
Yes, that is a workaround. The problem is that the images are from many different sites and may get updated on the original sites. I'd rather not duplicate them.Megen
M
1

Seens like there's no way to generate the same image URL, since you need to know the shared-key.

But the code for generate the URL can be found in the suite tests

class CamoProxyPathTest < Test::Unit::TestCase
  include CamoProxyTests

  def hexenc(image_url)
    image_url.to_enum(:each_byte).map { |byte| "%02x" % byte }.join
  end

  def request_uri(image_url)
    hexdigest = OpenSSL::HMAC.hexdigest(
      OpenSSL::Digest.new('sha1'), config['key'], image_url)
    encoded_image_url = hexenc(image_url)
    "#{config['host']}/#{hexdigest}/#{encoded_image_url}"
  end

  def request(image_url)
    RestClient.get(request_uri(image_url))
  end
end

Maybe if they didn't changed the key you could try to use the same that was mocked in code 0x24FEEDFACEDEADBEEFCAFE

Also there's to client libs responsable to create the URLs you could checkout the logic.

Maltese answered 31/10, 2022 at 17:45 Comment(1)
OK, I'll try that, although it is quite suspiciously constructed "feed face dead beef cafe" so I have a hard time believing that it is the public key for something...Either way I appreciate the URL generation code, and this is the best answer I've gotten so I'll award you the bountyMegen

© 2022 - 2024 — McMap. All rights reserved.