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