Support permalinks

Issue #44 new
Wes Chao created an issue

A few people have requested this feature, and I think it's a pretty significant upgrade in usability if you don't have padherder. I think there are three parts here:

  1. Capture a JSON blob that has all the data: each monster (id, level, +eggs, awoken, latents), combos, active skill, leader override, and enemy stats. Take an MD5 hash of the blob (it's ok that MD5 isn't cryptographically secure, we just want a hash function).

  2. Create a mapping of MD5 hash -> JSON blob, and use the MD5 hash as a URL parameter for the perma-link (optional: allow the user to set the permalink text, though we would need to detect and disallow duplicates). I'm thinking we want to integrate with something like Parse (but not Parse since Parse is shutting down next year) so that we don't have to install/maintain our own database or use something hacky like saving the blob to the filesystem.

  3. Detect the MD5 hash URL parameter, read the JSON blob, and fill in the data.

Comments (6)

  1. Wes Chao reporter

    For #2, I think what we want to do is have a simple php script that we can hit with an AJAX request, and have the PHP talk to a database. The DB can either be a MySQL instance hosted locally, or a Mongo DB instance that's cloud-based (I couldn't find a free cloud-based MySQL host that doesn't seem super sketchy).

    We're just storing a hash and a json blob, so I don't think the technical differences between MySQL and Mongo matter that much, so the difference boils down to, if we use Mongo, permalinks written from any server can be read by any other server (which is also nice for testing), but we'll need access to the webserver to install the PHP mongo driver.

    I'll continue working on parts 1 and 3 while we figure out what's possible for #2.

  2. Jean-Paul Cato repo owner

    It'd be easier to put the JSON data in the url params then shrink the request-encoded url, I think.

  3. Wes Chao reporter

    Yeah, I think that would work. tinyurl.com has a REST API that should do what we want. It's a little inelegant that the resulting permalink is a tinyurl.com domain rather than a padspike domain, but I think that's worth the tradeoff of not having to maintain a database.

  4. Wes Chao reporter

    Running into a problem: cross-origin request restrictions.

    tinyurl's REST API doesn't support CORS, so won't respond to a request made from a different origin. Bitly and goo.gl support CORS, but they require authentication, which means we'd either have to expose the token in Javascript or write a server page to hide it.

    I did some looking around, but I can't find an api that both supports CORS and doesn't require authentication.

  5. Jean-Paul Cato repo owner

    Google lets you origin restrict calls using certain keys, so I think we should be fine. I'll gen. the key and pass it along.

    Sidenote: ...tinyurl doesn't? I've done it before, but maybe I cheated. I'll go look for that code, since we'll both probably find a use for it someday.

  6. Log in to comment