bin icon indicating copy to clipboard operation
bin copied to clipboard

[update] generate shortid

Open pavanjadhaw opened this issue 4 years ago • 6 comments

pavanjadhaw avatar Aug 27 '19 08:08 pavanjadhaw

With these changes existing code snippets wont be retrieved, for that we can check if request/params is valid objectid If its object id then we return doc by id else we query and return doc by shortid

pavanjadhaw avatar Aug 27 '19 08:08 pavanjadhaw

  • No breaking changes in bin.
  • The ~ prefix is there to avoid breaking when we implement more features some day (like an alternate ID system).

MKRhere avatar Aug 27 '19 08:08 MKRhere

What would be best way to handle this and not break bin at same time? Any suggestions?

pavanjadhaw avatar Aug 27 '19 08:08 pavanjadhaw

Ideas:

  1. Use a new prefix system like /+:id for shortid
  2. Use a path separator like /b/:id

The second idea may be more scalable when we add short URL and file upload features to bin in the future. /l/:id could go to a link; /f/:id might go to a file. It can also be that they use other symbols. It might be cleaner while less expressive (!:id for links, *:id for files, we'll run out of characters soon).

MKRhere avatar Aug 27 '19 12:08 MKRhere

Any new snippets will be using !shortid while earlier snippets can be retrieved using their objectId

pavanjadhaw avatar Aug 28 '19 05:08 pavanjadhaw

Always prefer doing more at compile-time rather than runtime.

Instead of this:

app.get('/~:id', getSnippet);
app.get('/!:hash', isHash, getSnippet);

You should do this:

app.get("/~:id", getSnippet("id"));
app.get("/!:hash", getSnippet("hash"));

getSnippet would become a factory function of signature getSnippet :: str -> Handler

Edit: I prefer + or - over ! I think. bin.mkr.pw/+ar34i just looks neater.

MKRhere avatar Aug 28 '19 08:08 MKRhere