diff backends/directory.js @ 56:99bd1d1ac071

Migration to node-xmpp, done!
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 10 Aug 2011 15:11:22 -0700
parents fd69d35cf2e6
children
line wrap: on
line diff
--- a/backends/directory.js
+++ b/backends/directory.js
@@ -74,6 +74,7 @@ backend.save = function(dir) {
 }
 
 backend.load = function(dir) {
+	var parse = require('ltx').parse;
 	if (!dir)
 		dir = 'data';
 
@@ -86,23 +87,11 @@ backend.load = function(dir) {
 		}
 
 		fs.readdir(dir, function(err, files) {
-			var xmpp = require('xmpp');
-			function parseStanza(path, content) {
-				var stanza = null;
-				var stream = new xmpp.Stream({
-					stanza: function (stanza) {
-						path[content] = stanza;
-					}
-				});
-				stream.opened = true;
-				stream.data(path[content]);
-			}
-
 			function endParsing(o) {
 				var regexp = /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ/;
 				for (var i in o) {
 					if (typeof o[i] == 'string' && i == 'content')
-						parseStanza(o, i);
+						o[i] = parse(o[i]);
 					else if (typeof o[i] == 'string' && regexp(o[i])) {
 						var today = new Date();
 						today.setFromISO8601(o[i]);
@@ -120,6 +109,9 @@ backend.load = function(dir) {
 				if (/^\./.test(file))
 					continue;
 
+				if (!/\.json$/.test(file))
+					continue;
+
 				var nodeID = decodeURI(file.replace(/\.json$/, '').replace('%2f', '/'));
 
 				var data = fs.readFileSync(dir+'/'+file).toString();