Mercurial > psgxs
view modules/http/mod_atom.js @ 37:45d0cd9388ea
Fix mod_retrieve.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 10 Nov 2010 18:31:02 +0100 |
parents | 62cbb1c49bc5 |
children | bc717575e66a |
line wrap: on
line source
var config = require('../../configuration'); var storage = require('../../storage'); var forms = require('../../forms'); var errors = require('../../errors'); var makeError = errors.makeError; var NS = require('../../namespaces'); var xmpp = require('xmpp'); exports.atom = { url: /^\/atom/, func: function (req, res) { var url = require('url').parse(req.url); nodeID = url.pathname.substr(url.pathname.indexOf('/', 1)+1); var children; if (nodeID && nodeID != '') { var md = storage.getMetadata(nodeID); if (md['pubsub#type'] != NS.ATOM) return false; var response = xmpp.stanza('feed', {xmlns: 'http://www.w3.org/2005/Atom'}); res.writeHead(200, {'Content-Type': 'text/xml'}); if (!storage.existsNode(nodeID)) return false; if (md['pubsub#title']) response.c('title').t(md['pubsub#title']).up(); if (md['pubsub#description']) response.c('subtitle').t(md['pubsub#description']).up(); if (md['pubsub#creation_date']) response.c('published').t(md['pubsub#creation_date']).up(); children = storage.getItems(nodeID); if (typeof children == 'number') return false; for (var i in children) response.cnode(children[i].content).up(); } else { res.writeHead(200, {'Content-Type': 'text/xml'}); var response = xmpp.stanza('ul', {xmlns: 'http://www.w3.org/1999/xhtml'}); children = storage.getChildren(); if (typeof children == 'number') return false; for (var i in children) response.c('li').c('a', {href: i}).t(i).up().up(); } res.end(response.toString()); return true; }, }