Share URL

16 views
Skip to first unread message

Christiano da Costa

unread,
Jul 19, 2015, 11:39:53 AM7/19/15
to nod...@googlegroups.com
Hi guys, I am trying to create a programm wich lets your users create online text files, and share these via URL to others, so that they can make changes on this online document... Does anyone know ow I could be able to generate a URL, linking to this online document??

Thanks in advance.

Aria Stewart

unread,
Jul 19, 2015, 11:52:07 AM7/19/15
to nod...@googlegroups.com, simiba...@gmail.com


On Sunday, July 19, 2015 at 11:39:53 AM UTC-4, Christiano da Costa wrote:
Hi guys, I am trying to create a programm wich lets your users create online text files, and share these via URL to others, so that they can make changes on this online document... Does anyone know ow I could be able to generate a URL, linking to this online document??

Okay, we're not all guys, but here goes:

you've got three things here: storing documents, identifying them with an ID (which can be or be part of a URL), and then the program that maps a URL being requested to the thing that loads that part from the database.

The way similar systems do it are one of two ways: A random ID -- like gist, they generate a random number, and then use that as the ID for a document. The other is that the ID is generated by hashing the document itself -- "content addressable storage"; this is what git does internally. That gets into complexity when things can change, since changing the content changes the hash. For a simple site, go with random number generation. It can be a UUID, it can be a random series of bytes expressed as hexadecimal (or even a tighter packing if you want shorter IDs)

Then you need a database -- any key-value store works. the filesystem's actually a great thing for cases like this. So are databases like leveldb. Even networked databases like mongodb or mysql work well.

Then you have to generate URLs -- it can be as simple as concatenation. "http://myserver/files/" + id would be the url of your document.

Then you write something to tie those together. In an express app, that might be this:

app.get('/files/:id', function (req, res, next) {
    myDb.get(req.params.id, function (err, data) {
        if (err) return next(err);

        render('viewFile', { file: data });
    });
});

Good luck!

Aria
Reply all
Reply to author
Forward
0 new messages