bin
bin copied to clipboard
[update] generate shortid
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
- No breaking changes in
bin
. - The
~
prefix is there to avoid breaking when we implement more features some day (like an alternate ID system).
What would be best way to handle this and not break bin at same time? Any suggestions?
Ideas:
- Use a new prefix system like
/+:id
for shortid - 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).
Any new snippets will be using !shortid while earlier snippets can be retrieved using their objectId
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.