deconst / content-service

An API for storing, indexing and retrieving documentation
MIT License
4 stars 9 forks source link

Apply a name to assets when requested. #23

Closed smashwilson closed 9 years ago

smashwilson commented 9 years ago

This is necessary to support assets supplied as part of a layout, the second half of deconst/deconst-docs#13.

My goal is that, if you provide an optional ?layout=true query parameter to an asset upload:

curl -s -F assetname=@someasset.jpg http://content:9000/assets?layout=true

... an additional key called assetname will be provided to the handlebars layout during every page render, with a value that's the SSL URI of the fingerprinted someasset.jpg file on the CDN.

smashwilson commented 9 years ago

The tricky part here is that it's the first time we need non-Cloud Files state in the content service.

I'm probably going to use MongoDB because Strider uses it as well.

smashwilson commented 9 years ago

Looking good:

$ curl -s -F txt_somefile_url=@somefile http://docker:9000/assets?layout=true | python -m json.tool
{
    "drcmap": "https://8c782371ed443340bfce-a76b79aca86ab4305e3e9ef5c9a01022.ssl.cf1.rackcdn.com/somefile-89c680cb317c66e5f553ca02049f702228495d716f4d1349d4cb1c2a66292d1b"
}
$ curl -s http://docker:9000/content/https%3A%2F%2Fgithub.com%2Fdeconst%2Fdeconst-docs | python -m json.tool
{
    "assets": {
        "txt_somefile_url": "https://8c782371ed443340bfce-a76b79aca86ab4305e3e9ef5c9a01022.ssl.cf1.rackcdn.com/somefile-89c680cb317c66e5f553ca02049f702228495d716f4d1349d4cb1c2a66292d1b"
    },
    "body": "...."
}

I'm not that fond of ?layout=true as a query parameter, though. I'll think of something better to replace it with next.

smashwilson commented 9 years ago

There we go:

$ curl -s -F txt_somefile_url=@somefile http://docker:9000/assets?named=true | python -m json.tool
{
    "somefile": "https://8c772371dd443340bfce-a76b79aca86ab4305d3e9ef5c9a01022.ssl.cf1.rackcdn.com/somefile-b027376173d89c6b852bfa1da922997c9b12c8a113426e415a55c9a63a0327f0"
}
$ curl -s http://docker:9000/content/https%3A%2F%2Fgithub.com%2Fdeconst%2Fdeconst-docs | python -m json.tool
{
    "assets": {
        "txt_somefile_url": "https://8c772371dd443340bfce-a76b79aca86ab4305d3e9ef5c9a01022.ssl.cf1.rackcdn.com/somefile-b027376173d89c6b852bfa1da922997c9b12c8a113426e415a55c9a63a0327f0"
    },
    "body": "..."
}