annotate modules/http/mod_atom.js @ 35:6697f394301f

Replace util with fdsq to work around a stupid bug.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 10 Nov 2010 01:30:03 +0100
parents 62cbb1c49bc5
children bc717575e66a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 var config = require('../../configuration');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 var storage = require('../../storage');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 var forms = require('../../forms');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 var errors = require('../../errors');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 var makeError = errors.makeError;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 var NS = require('../../namespaces');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 var xmpp = require('xmpp');
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 exports.atom = {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 url: /^\/atom/,
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 func: function (req, res) {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 var url = require('url').parse(req.url);
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 nodeID = url.pathname.substr(url.pathname.indexOf('/', 1)+1);
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 var children;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 if (nodeID && nodeID != '') {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 var md = storage.getMetadata(nodeID);
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 if (md['pubsub#type'] != NS.ATOM)
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 return false;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 var response = xmpp.stanza('feed', {xmlns: 'http://www.w3.org/2005/Atom'});
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 res.writeHead(200, {'Content-Type': 'text/xml'});
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 if (!storage.existsNode(nodeID))
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 return false;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 if (md['pubsub#title'])
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 response.c('title').t(md['pubsub#title']).up();
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 if (md['pubsub#description'])
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 response.c('subtitle').t(md['pubsub#description']).up();
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 if (md['pubsub#creation_date'])
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 response.c('published').t(md['pubsub#creation_date']).up();
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 children = storage.getItems(nodeID);
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 if (typeof children == 'number')
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 return false;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 for (var i in children)
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 response.cnode(children[i].content).up();
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 } else {
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 res.writeHead(200, {'Content-Type': 'text/xml'});
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 var response = xmpp.stanza('ul', {xmlns: 'http://www.w3.org/1999/xhtml'});
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 children = storage.getChildren();
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 if (typeof children == 'number')
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 return false;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 for (var i in children)
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 response.c('li').c('a', {href: i}).t(i).up().up();
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 }
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 res.end(response.toString());
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 return true;
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 },
62cbb1c49bc5 Fix publish; add owner metadata field; add HTTP module and Atom HTTP module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 }