Permalink
Browse files

updating to node.couchapp.js

  • Loading branch information...
1 parent 25dae75 commit 0609b9edda4af4e68bcc6bb103459e5ebcf2554c @maxogden committed Jul 14, 2011
Showing with 238 additions and 288 deletions.
  1. +5 −5 README.textile
  2. +0 −1 _id
  3. +227 −0 app.js
  4. BIN {_attachments → attachments}/images/ajax-loader.gif
  5. BIN {_attachments → attachments}/images/ajax-loader2.gif
  6. BIN {_attachments → attachments}/images/arrowdown.gif
  7. BIN {_attachments → attachments}/images/arrowleft.gif
  8. BIN {_attachments → attachments}/images/arrowright.gif
  9. BIN {_attachments → attachments}/images/arrowup.gif
  10. BIN {_attachments → attachments}/images/bl.gif
  11. BIN {_attachments → attachments}/images/bl.png
  12. BIN {_attachments → attachments}/images/br.gif
  13. BIN {_attachments → attachments}/images/br.png
  14. BIN {_attachments → attachments}/images/css3buttons_backgrounds.png
  15. BIN {_attachments → attachments}/images/darrowdown.gif
  16. BIN {_attachments → attachments}/images/darrowleft.gif
  17. BIN {_attachments → attachments}/images/darrowright.gif
  18. BIN {_attachments → attachments}/images/darrowup.gif
  19. BIN {_attachments → attachments}/images/deletelabel.png
  20. BIN {_attachments → attachments}/images/itunes.png
  21. BIN {_attachments → attachments}/images/loading-bar.gif
  22. BIN {_attachments → attachments}/images/pbar-ani.gif
  23. BIN {_attachments → attachments}/images/rarrowdown.gif
  24. BIN {_attachments → attachments}/images/rarrowleft.gif
  25. BIN {_attachments → attachments}/images/rarrowright.gif
  26. BIN {_attachments → attachments}/images/rarrowup.gif
  27. BIN {_attachments → attachments}/images/tl.gif
  28. BIN {_attachments → attachments}/images/tl.png
  29. BIN {_attachments → attachments}/images/tr.gif
  30. BIN {_attachments → attachments}/images/tr.png
  31. BIN {_attachments → attachments}/images/wait.gif
  32. BIN {_attachments → attachments}/images/x.png
  33. +3 −3 {_attachments → attachments}/pages/monocles.html
  34. 0 {_attachments → attachments}/script/ezcrypto.js
  35. 0 {_attachments → attachments}/script/helpers.js
  36. 0 {_attachments → attachments}/script/jiverscripts/compat/array.js
  37. 0 {_attachments → attachments}/script/jiverscripts/compat/object.js
  38. 0 {_attachments → attachments}/script/jiverscripts/conc/next_tick.js
  39. 0 {_attachments → attachments}/script/jiverscripts/conc/observable.js
  40. 0 {_attachments → attachments}/script/jiverscripts/conc/promise.js
  41. 0 {_attachments → attachments}/script/jiverscripts/conc/synchronize.js
  42. 0 {_attachments → attachments}/script/jquery-1.4.4.min.js
  43. 0 {_attachments → attachments}/script/jquery.bgiframe.min.js
  44. 0 {_attachments → attachments}/script/jquery.cluetip.js
  45. 0 {_attachments → attachments}/script/jquery.couch.app.js
  46. 0 {_attachments → attachments}/script/jquery.couch.js
  47. 0 {_attachments → attachments}/script/jquery.fileupload-ui.js
  48. 0 {_attachments → attachments}/script/jquery.fileupload.js
  49. 0 {_attachments → attachments}/script/jquery.hoverIntent.js
  50. 0 {_attachments → attachments}/script/jquery.infieldlabel.js
  51. 0 {_attachments → attachments}/script/jquery.mustache.js
  52. 0 {_attachments → attachments}/script/jquery.timeago.js
  53. 0 {_attachments → attachments}/script/models/comments.js
  54. 0 {_attachments → attachments}/script/models/posts.js
  55. +3 −1 {_attachments → attachments}/script/monocles.js
  56. 0 {_attachments → attachments}/script/sammy.js
  57. 0 {_attachments → attachments}/script/vendor/aes_cbc.js
  58. 0 {_attachments → attachments}/script/vendor/aes_core.js
  59. 0 {_attachments → attachments}/script/vendor/jsbn.js
  60. 0 {_attachments → attachments}/script/vendor/md5.js
  61. 0 {_attachments → attachments}/script/vendor/pidcrypt.js
  62. 0 {_attachments → attachments}/script/vendor/pidcrypt_util.js
  63. 0 {_attachments → attachments}/script/vendor/prng4.js
  64. 0 {_attachments → attachments}/script/vendor/rng.js
  65. 0 {_attachments → attachments}/script/vendor/rsa.js
  66. 0 {_attachments → attachments}/script/vendor/unhosted_encryption.js
  67. 0 {_attachments → attachments}/style/blueprint-screen.css
  68. BIN {_attachments → attachments}/style/brandongrotesque_light/Brandon_light-webfont.eot
  69. 0 {_attachments → attachments}/style/brandongrotesque_light/Brandon_light-webfont.svg
  70. BIN {_attachments → attachments}/style/brandongrotesque_light/Brandon_light-webfont.ttf
  71. BIN {_attachments → attachments}/style/brandongrotesque_light/Brandon_light-webfont.woff
  72. BIN {_attachments → attachments}/style/brandongrotesque_light/Extras/Brandon_light-webfont.svgz
  73. 0 {_attachments → attachments}/style/brandongrotesque_light/Extras/alt_base64_stylesheet.css
  74. 0 {_attachments → attachments}/style/brandongrotesque_light/demo.html
  75. 0 {_attachments → attachments}/style/brandongrotesque_light/stylesheet.css
  76. 0 {_attachments → attachments}/style/css3buttons.css
  77. 0 {_attachments → attachments}/style/jquery.cluetip.css
  78. 0 {_attachments → attachments}/style/jquery.fileupload-ui.css
  79. 0 {_attachments → attachments}/style/monocles.css
  80. 0 {_attachments → attachments}/style/ui.css
  81. 0 {vendor → common}/atom.js
  82. 0 {vendor → common}/base64.js
  83. 0 {vendor → common}/crypto.js
  84. 0 {vendor → common}/md5.js
  85. 0 {vendor → common}/mustache.js
  86. 0 {vendor → common}/rfc3339.js
  87. 0 {vendor → common}/sax.js
  88. 0 {vendor → common}/uri-template.js
  89. 0 {vendor → common}/validate.js
  90. 0 {vendor → common}/webfinger-buzz.js
  91. 0 {vendor → common}/webfinger-client.js
  92. 0 {vendor → common}/xml2js.js
  93. 0 {vendor → common}/xrd.js
  94. 0 {vendor → common}/xrd_gen.js
  95. +0 −43 lists/feed.js
  96. +0 −16 lists/profile.js
  97. +0 −3 lists/push.js
  98. +0 −5 lists/test.js
  99. +0 −91 rewrites.json
  100. +0 −3 shows/challenge.js
  101. +0 −7 shows/cors.js
  102. +0 −15 shows/lrdd.js
  103. +0 −9 shows/profile.js
  104. +0 −13 shows/webfinger.js
  105. +0 −10 updates/pubsub.js
  106. +0 −34 updates/salmon.js
  107. +0 −19 validate_doc_update.js
  108. +0 −5 views/comments/map.js
  109. +0 −5 views/stream/map.js
View
@@ -1,6 +1,6 @@
-h1. CouchAppspora (codenamed 'monocles')
+h1. Monocles (formerly CouchAppSpora)
-h3. ..is Diaspora implemented on CouchDB
+h3. ..is (more or less) Diaspora implemented on CouchDB
p. The Diaspora source code was initially "released":http://www.joindiaspora.com/2010/09/15/developer-release.html on September 15th, 2010. This project is an implementation of the Diaspora protocol as a CouchApp built entirely on CouchDB.
@@ -10,23 +10,23 @@ p. CouchDB is a good fit for a federated social web node due to it's robust repl
h3. Protocols
-p. I am shooting for Social Web Acid Test level 0 (SWAT0) compliance by implementing the OStatus stack. Since Couch can use CommonJS, I started a project called "ostatus-js":http://github.com/maxogden/ostatus-js to write the OStatus protocols in server side javascript. To learn more about how monocles works and interoperates with other seeds, check out "this wiki page":http://github.com/maxogden/couchappspora/wiki/Protocols-and-examples.
+p. I am shooting for Social Web Acid Test level 0 (SWAT0) compliance by implementing the OStatus stack. Since Couch can use CommonJS, I started a project called "ostatus-js":http://github.com/maxogden/ostatus-js to write the OStatus protocols in server side javascript. To learn more about how monocles works and interoperates with other seeds, check out "this wiki page":http://github.com/maxogden/monocles/wiki/Protocols-and-examples.
p. !http://i.imgur.com/J0HPe.png!
h3. Hosting your own
p. You can run monocles anywhere that you can run CouchDB, and since it's a CouchApp, the entire application lives inside your database and can be replicated from any other monocles seed. To demonstrate the built in replication that you get with CouchDB:
-* Get a CouchDB somewhere! You can get a hosted Couch from "Cloudant":http://cloudant.com, a downloadable Couch from "CouchBase":http://www.couchbase.com/downloads, or an Android Couch from the Android Marketplace
+* Get a CouchDB somewhere! You can get a hosted Couch from "Cloudant":http://cloudant.com or "IrisCouch":http://iriscouch.com, a downloadable Couch from "CouchBase":http://www.couchbase.com/downloads, or an Android Couch from the Android Marketplace
* Make a database and set up bidirectional continuous replication from @http://monocl.es/api@ (or any other monocles instance) to your new database.
* Visit "http://yourcouch/yourdb/==_design/monocles/_==rewrite":http://yourcouch/yourdb/_design/monocles/_rewrite
h3. TO-DO (aka 'how to contribute')
p. Hack on the interface and make it do something cool! The bulk of the application logic is in @monocles.js@, @monocles.html@ and @monocles.css@
-p. Check out the "Issues page":http://github.com/maxogden/couchappspora/issues
+p. Check out the "Issues page":http://github.com/maxogden/monocles/issues
p. If you've never worked with CouchApps before, I'd highly recommend learning more about them at "couchapp.org":http://couchapp.org/
View
@@ -1 +0,0 @@
-_design/monocles
View
@@ -0,0 +1,227 @@
+var couchapp = require('couchapp')
+ , path = require('path')
+ ;
+
+ddoc =
+ { _id:'_design/monocles'
+ , rewrites :
+ [ {from:"/", to:"pages/monocles.html"}
+ , {from:"/", to:"_show/cors", method: "OPTIONS"},
+ , {from:"/push",to:"_show/challenge",method: "GET"},
+ , {from:"/push", to:"_update/pubsub", method:"POST" },
+ , {from:"/.well-known/host-meta", to:"_show/webfinger" },
+ , {from:"/webfinger", to:"_show/lrdd" },
+ , {from:"/users/:user", to:"_list/profile/stream", query:{name: ":user" } },
+ , {from:"/feeds/:user", to:"_list/feed/stream", query: {name : ":user" } },
+ , {from:"/salmon/:user", to:"_update/salmon" },
+ , {from:"/api", to:"../../"}
+ , {from:"/api/*", to:"../../*"}
+ , {from:"/*", to:"*"}
+ ]
+ }
+ ;
+
+ddoc.views = {
+ comments: {
+ map: function(doc) {
+ if (doc.created_at && doc.parent_id) {
+ emit([doc.parent_id, doc.created_at], doc);
+ }
+ }
+ },
+ stream: {
+ map: function(doc) {
+ if (doc.type && doc.type === "note" || doc.type === "follow") {
+ emit(doc.updated_at || doc.created_at, doc);
+ }
+ }
+ }
+};
+
+ddoc.lists = {
+ feed: function(head, req){
+ provides("atom",function() {
+ var rows = [];
+ // !json templates.feed
+ Mustache = require("common/mustache");
+ Rfc3339 = require("common/rfc3339");
+ while(row = getRow()){
+ if (row.value.profile && row.value.profile.name === req.query.name){
+ rows.push(row);
+ }
+ }
+ var host = req.headers.Host;
+ var view = {
+ username: req.query.name,
+ hubURL: "http://psychicwarlock.com",
+ domain: host,
+ updated_at: Rfc3339.convert(new Date()),
+ gravatar: rows[0].value.profile.gravatar_url,
+ entries: rows.map(function(r){
+ var rand = Math.random();
+ var url = "http://"+host+"/db/"+r.value._id
+ return {
+ entry_title: r.value.message,
+ entry_url: url,
+ entry_published: Rfc3339.convert(new Date(r.value.created_at)),
+ entry_updated: Rfc3339.convert(new Date(r.value.created_at)),
+ entry_content: r.value.message,
+ attachments: Object.keys(r.value._attachments || {}).map(function(a){
+ var val=r.value._attachments[a];
+ return {
+ name: a,
+ type: val.content_type,
+ length: val.length,
+ url: url+"/"+a
+ };
+ })
+ };
+ })
+ };
+ var xml = Mustache.to_html(templates.feed, view);
+ return xml;
+ });
+ },
+ profile: function(head, req){
+ //!json templates.profile
+ provides("html", function(){
+
+ Mustache = require("common/mustache");
+ var rows = [];
+ while(row = getRow()){
+ if (row.value.profile && row.value.profile.name === req.query.name && row.value.message.length > 0){
+ rows.push(row);
+ }
+ }
+ var profile = rows[0].value.profile;
+ var html = Mustache.to_html(templates.profile, profile);
+ return html;
+ });
+ },
+ push: function(head, req){
+ send(JSON.stringify(head)+" "+JSON.stringify(req));
+ }
+}
+
+ddoc.shows = {
+ challenge: function(head, req){
+ return req.query["hub.challenge"];
+ },
+ cors: function(head, req){
+ return {
+ "headers": {
+ "Access-Control-Allow-Origin": "*"
+ }
+ }
+ },
+ lrdd: function(doc, req){
+ //!json templates.lrdd
+ uri = req.query.q
+ Mustache = require("common/mustache");
+ var username = uri.split("@")[0].replace("acct:","");
+ var host = req.headers.Host;
+ var view = {
+ username: username,
+ host: host
+ };
+ var xml = Mustache.to_html(templates.lrdd, view);
+ provides("xml", function(){
+ return xml;
+ });
+ },
+ profile: function(doc, req){
+ //!json templates.profile
+ Mustache = require("common/mustache");
+ var profile = doc.couch.app.profile;
+ var html = Mustache.to_html(templates.profile, profile);
+ provides("html", function(){
+ return html;
+ });
+ },
+ webfinger: function(doc, req){
+ //!json templates.xrd
+ uri = req.query.q
+ Mustache = require("common/mustache");
+ var host = req.headers.Host;
+ var view = {
+ host: host
+ };
+ var xml = Mustache.to_html(templates.xrd, view);
+ provides("xml", function(){
+ return xml;
+ });
+ }
+}
+
+ddoc.updates = {
+ pubsub: function(head, req) {
+ var xml2js = require('common/xml2js');
+ var json;
+
+ new xml2js.Parser(function(data) {
+ json = [{_id:req.uuid, created_at: new Date(), data:data, type:"pubsub"}, "posted"];
+ }).parseString(req.body);
+
+ return json;
+ },
+ salmon: function(doc, req) {
+ // var Base64 = require("common/base64")
+ // , md5 = require('common/md5')
+ // ;
+ // req.body = req.body.replace(/<.*?>/,"");
+ // var codez = new XML(req.body);
+ // var atom = new Namespace('http://www.w3.org/2005/Atom');
+ // var poco = new Namespace('http://portablecontacts.net/spec/1.0');
+ // var me = new Namespace('http://salmon-protocol.org/ns/magic-env');
+ // var thr = new Namespace('http://purl.org/syndication/thread/1.0');
+ // var activity = new Namespace('http://activitystrea.ms/spec/1.0/');
+ // var data = codez..me::data.toString();
+ // function tr(str, from, to) {
+ // var subst;
+ // for (i = 0; i < from.length; i++) {
+ // subst = (to[i]) ? to[i] : to[to.length-1];
+ // str = str.replace(new RegExp(str[str.indexOf(from[i])], 'g'), subst);
+ // }
+ // return str;
+ // }
+ // var striped = tr(data, "-_,","+/=");
+ // var decoded = new XML(Base64.client.decode(striped).replace(/<.*?>/,"").replace(/in-reply-to/g,"reply"));
+ // var profile = {
+ // name: decoded..atom::author.atom::name.toString(),
+ // url: decoded..atom::author.atom::uri.toString(),
+ // gravatar_url: decoded..activity::actor.atom::link.(@rel == 'avatar')[0].@href.toString()
+ // }
+ // var parent_id = decoded..thr::reply.@ref.toString().split("/");
+ // parent_id = parent_id[parent_id.length-1];
+ // var hostname = profile.url.split("/")[2];
+ // var message = decoded..atom::content.toString().replace(/<.*?>/g,"");
+ // var created_at = new Date();
+ // return [{_id:md5.hex(message), created_at:created_at, xml:req.body, decoded:decoded.toString(), hostname:hostname, profile:profile, message:message, parent_id:parent_id, type:"follow" }, "posted"]
+ }
+}
+
+ddoc.validate_doc_update = function ( newDoc, oldDoc, userCtx, secObj ) {
+ var v = require( "common/validate" ).init( newDoc, oldDoc, userCtx, secObj );
+
+ if ( v.isAdmin() ) return;
+
+ if( ! userCtx.name ) {
+ // CouchDB sets userCtx.name only after a successful authentication
+ v.unauthorized( "Please log in first." );
+ }
+
+ // if( oldDoc && oldDoc.profile.name !== userCtx.name ) {
+ // v.unauthorized( "You are not the author" );
+ // }
+
+ // if ( ( oldDoc && oldDoc.type === "comment" ) || ( oldDoc && oldDoc.type === "note" ) ) {
+ // v.unauthorized( "You can't edit that" );
+ // }
+
+}
+
+ddoc.common = couchapp.loadFiles('./common');
+ddoc.templates = couchapp.loadFiles('./templates');
+couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));
+
+module.exports = ddoc;
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
@@ -35,7 +35,7 @@
<header>
<div class="container" id="headerContainer">
<div href="#" id="diaspora_text">
- <a href="http://github.com/maxogden/couchappspora">
+ <a href="http://github.com/maxogden/monocles">
MONOCLES
</a>
<span class="sub_text">
@@ -89,7 +89,7 @@
</script>
<script type="text/mustache" id="loggedOutTemplate">
- <div class="container"><p class="loginMessage">Welcome to <a href="https://github.com/maxogden/couchappspora">monocles</a>, an open source social network based on <a href="https://joindiaspora.com/">Diaspora</a> that lets people on <a href="http://ostatus.org/faq">different networks</a> follow each other. Log in or sign up to post.</p></div>
+ <div class="container"><p class="loginMessage">Welcome to <a href="https://github.com/maxogden/monocles">monocles</a>, an open source social network based on <a href="https://joindiaspora.com/">Diaspora</a> that lets people on <a href="http://ostatus.org/faq">different networks</a> follow each other. Log in or sign up to post.</p></div>
</script>
<script type="text/mustache" id="newProfileFormTemplate">
@@ -155,7 +155,7 @@ <h1 class="aspect-header"><a href="#">Public</a></h1>
{{#profile}}
<div class="right hidden controls">
<a class="delete" href="#">
- <img src="/images/deletelabel.png" />
+ <img src="images/deletelabel.png" />
</a>
</div>
{{/profile}}
File renamed without changes.
@@ -165,8 +165,10 @@ var monocles = {
} else {
monocles.render( 'newProfileForm', 'stream', session.userCtx, false );
$( '#stream form' ).submit( function( e ) {
+ alert('woo')
monocles.saveUser( $( this ) );
e.preventDefault();
+ return false;
});
}
}
@@ -176,7 +178,7 @@ var monocles = {
saveUser: function(form) {
$.couch.app( function( app ) {
- var md5 = app.require( "vendor/md5" );
+ var md5 = app.require( "common/md5" );
var name = $( "input[name=userCtxName]", form ).val();
var newProfile = {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -1,43 +0,0 @@
-function(head, req){
- provides("atom",function() {
- var rows = [];
- // !json templates.feed
- Mustache = require("vendor/mustache");
- Rfc3339 = require("vendor/rfc3339");
- while(row = getRow()){
- if (row.value.profile && row.value.profile.name === req.query.name){
- rows.push(row);
- }
- }
- var host = req.headers.Host;
- var view = {
- username: req.query.name,
- hubURL: "http://psychicwarlock.com",
- domain: host,
- updated_at: Rfc3339.convert(new Date()),
- gravatar: rows[0].value.profile.gravatar_url,
- entries: rows.map(function(r){
- var rand = Math.random();
- var url = "http://"+host+"/db/"+r.value._id
- return {
- entry_title: r.value.message,
- entry_url: url,
- entry_published: Rfc3339.convert(new Date(r.value.created_at)),
- entry_updated: Rfc3339.convert(new Date(r.value.created_at)),
- entry_content: r.value.message,
- attachments: Object.keys(r.value._attachments || {}).map(function(a){
- var val=r.value._attachments[a];
- return {
- name: a,
- type: val.content_type,
- length: val.length,
- url: url+"/"+a
- };
- })
- };
- })
- };
- var xml = Mustache.to_html(templates.feed, view);
- return xml;
- });
-}
View
@@ -1,16 +0,0 @@
-function(head, req){
- //!json templates.profile
- provides("html", function(){
-
- Mustache = require("vendor/mustache");
- var rows = [];
- while(row = getRow()){
- if (row.value.profile && row.value.profile.name === req.query.name && row.value.message.length > 0){
- rows.push(row);
- }
- }
- var profile = rows[0].value.profile;
- var html = Mustache.to_html(templates.profile, profile);
- return html;
- });
-}
View
@@ -1,3 +0,0 @@
-function(head, req){
- send(JSON.stringify(head)+" "+JSON.stringify(req));
-}
View
@@ -1,5 +0,0 @@
-function(head, req){
- provides("html", function(){
- return req.headers.Host; //JSON.stringify(req.headers);
- });
-}
Oops, something went wrong.

0 comments on commit 0609b9e

Please sign in to comment.