Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- '8'
services:
- mongodb
- redis-server
after_script: istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
decentralize
============
[![Build Status](https://img.shields.io/travis/FabricLabs/decentralize.svg?branch=master&style=flat-square)](https://travis-ci.org/FabricLabs/decentralize)
[![Coverage Status](https://img.shields.io/coveralls/FabricLabs/decentralize.svg?style=flat-square)](https://coveralls.io/r/FabricLabs/decentralize)
[![Total Contributors](https://img.shields.io/github/contributors/FabricLabs/decentralize.svg?style=flat-square)](https://github.com/FabricLabs/decentralize/contributors)

podcast
11 changes: 6 additions & 5 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ module.exports = {
mission: 'the podcast',
description: 'The best place for learning about what\'s going on with the latest decentralized tech.',
source: 'https://github.com/martindale/decentralize',
points: []
points: [],
dependencies: ['decentral']
},
source: {
sockets: 'ws://',
proto: 'http',
host: 'localhost',
port: '15005'
sockets: 'wss://',
proto: 'https',
host: process.env.DECENTRAL_HOST || 'decentral.fm',
port: process.env.DECENTRAL_PORT || '443'
},
soundcloud: {
clientID: '98ce66124fabdff2f33beb2f810a0a25',
Expand Down
67 changes: 32 additions & 35 deletions decentralize.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,42 @@
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';

var config = require('./config');
var WebSocket = require('ws');
var procure = require('procure');

var Maki = require('maki');

var Soundcloud = require('./lib/Soundcloud');
var Engine = require('./lib/Engine');

var Remote = require('maki-remote');
var WebSocket = require('ws');
var Sessions = require('maki-sessions');
var ProxAuth = require('maki-auth-proxy');
var Policies = require('maki-auth-tokens');

var jsonpatch = require('fast-json-patch');
var rest = require('restler');

var home = 'https://' + config.service.authority;

var source = config.source;
source.authority = source.host;

if (!~[80, 443].indexOf( parseInt(source.port) )) {
source.authority += ':' + source.port;
}
source.base = source.proto + '://' + source.authority;

var decentralize = new Maki( config );
var soundcloud = new Soundcloud( config.soundcloud );

var Sessions = require('maki-sessions');
var sessions = new Sessions();
var policies = new Policies();

decentralize.use(sessions);
//decentralize.use(policies);

// setup of various remotes, subservices on another Maki namespace
var MailPimpSubscription = new Remote('http://localhost:2525/subscriptions');
var MailPimpTask = new Remote('http://localhost:2525/tasks');

Show = decentralize.define('Show', {
attributes: {
title: { type: String , slug: true },
slug: { type: String },
recorded: { type: Date },
released: { type: Date , default: Date.now , required: true },
description: { type: String },
audio: { type: String },
filename: { type: String },
// TODO: replace with a sources list.
youtube: { type: String },
soundcloud: { type: String },
},
names: { get: 'item' },
source: source.proto + '://' + source.authority + '/recordings',
icon: 'sound'
});

var Subscription = decentralize.define('Subscription', {
attributes: {
email: { type: String , required: true , validator: function(value) {
Expand Down Expand Up @@ -88,18 +75,8 @@ Subscription.post('create', function(done) {
});
});

Index = decentralize.define('Index', {
name: 'Index',
routes: { query: '/' },
templates: { query: 'index' },
requires: {
'Show': {
filter: {}
}
},
static: true,
internal: true
});
Show = decentralize.define('Show', require('./resources/Show') );
Index = decentralize.define('Index', require('./resources/Index') );

procure( source.base + '/shows/decentralize' , function(err, show) {
if (err || !show) return console.error(err || 'no such show: decentralize');
Expand Down Expand Up @@ -157,6 +134,25 @@ procure( source.base + '/shows/decentralize' , function(err, show) {
return next();
}
});
decentralize.app.get('/shows/:showSlug/edit', function(req, res, next) {
Show.get({ slug: req.param('showSlug') }, function(err, show) {
return res.render('show-edit', {
item: show
});
});
});
decentralize.app.post('/shows/:showSlug', function(req, res, next) {
rest.patch( source.proto + '://' + source.authority + '/recordings/' + req.param('showSlug') , {
headers: {
Accept: 'application/json'
},
data: req.body
}).on('complete', function(data, request) {
if (request.statusCode !== 200) return res.error('Editing failed');
req.flash('success', 'Content edited successfully!');
return res.redirect('/shows/' + req.param('showSlug'));
});
});
decentralize.app.get('/rss', function(req, res, next) {
res.redirect( 301 , '/feed' );
});
Expand All @@ -178,6 +174,7 @@ procure( source.base + '/shows/decentralize' , function(err, show) {

engine.subscribe();
engine.sync();
engine.subscribe();

});

Expand Down
5 changes: 5 additions & 0 deletions decentralize:web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var config = require('./config');
var DECENTRALIZE = require('./lib/decentralize');
var decentralize = new DECENTRALIZE(config);

decentralize.start();
6 changes: 4 additions & 2 deletions lib/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Engine.prototype.subscribe = function( cb ) {
attemptReconnect();

});

// TODO: port to Fabric
// TODO: add Router
self.ws.on('message', function(data) {
console.log('DATAGRAM:' , data );
var msg = JSON.parse( data );
Expand All @@ -72,7 +75,6 @@ Engine.prototype.subscribe = function( cb ) {
}
}
}

}
});
};
Expand Down Expand Up @@ -171,6 +173,6 @@ Engine.prototype.sync = function( cb ) {
});
});
});
}
};

module.exports = Engine;
181 changes: 181 additions & 0 deletions lib/decentralize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';

var procure = require('procure');

var Maki = require('maki');
var Soundcloud = require('./Soundcloud');
var Engine = require('./Engine');
var Remote = require('maki-remote');
var WebSocket = require('ws');

var jsonpatch = require('fast-json-patch');

function DECENTRALIZE (config) {
if (!config) config = require('../config');

var self = this;

self.config = config;
self.home = 'https://' + config.service.authority;

self.source = config.source;
self.source.authority = self.source.host;
if (!~[80, 443].indexOf( parseInt(self.source.port) )) {
self.source.authority += ':' + self.source.port;
}
self.source.base = self.source.proto + '://' + self.source.authority;

self.app = new Maki( config );
var soundcloud = new Soundcloud( config.soundcloud );

var Sessions = require('maki-sessions');
var sessions = new Sessions();

self.app.use(sessions);

// setup of various remotes, subservices on another Maki namespace
var MailPimpSubscription = new Remote('http://localhost:2525/subscriptions');
var MailPimpTask = new Remote('http://localhost:2525/tasks');

var Subscription = self.app.define('Subscription', {
attributes: {
email: { type: String , required: true , validator: function(value) {
// see HTML spec: https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
// this should mirror HTML5's "type=email", as per the above link
return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
} },
status: { type: String , enum: ['requested', 'pending', 'validated'], default: 'requested' },
created: { type: Date , default: Date.now },
},
handlers: {
html: {
create: function(req, res, next) {
req.flash('info', 'Successfully subscribed! Check your inbox for a confirmation.');
res.redirect('/');
}
}
}
});

Subscription.post('create', function(done) {
var subscription = this;
MailPimpSubscription.create({
email: subscription.email,
// TODO: place in config, or auto-create-and-collect
_list: '55d490d83e5a3dcf5287129e'
}, function(err, data) {
// TODO: retry, error handling, etc.
if (!data._id) return done('no subscription created');
Subscription.patch({ _id: subscription._id }, [
{ op: 'replace', path: '/status', value: 'pending' }
], function(err) {
if (err) console.error(err);
done(err);
});
});
});

Show = self.app.define('Show', require('../resources/Show'));
Index = self.app.define('Index', require('../resources/Index'));

}

DECENTRALIZE.prototype.start = function (done) {
var self = this;
if (!done) done = Function();

procure( self.source.base + '/shows/decentralize' , function(err, show) {
if (err || !show) return console.error(err || 'no such show: decentralize');

try {
self.config.show = JSON.parse( show );
} catch (e) {
console.error(e);
return done(e);
}

self.config.show.source = self.source;
self.config.show.home = self.home;

console.log('maki starting...');

self.app.start(function() {
console.log('maki started!');

self.app.app.locals.show = self.config.show;

self.app.app.get('/about', function(req, res, next) {
res.render('about');
});
self.app.app.get('/contact', function(req, res, next) {
res.render('contact');
});
self.app.app.post('/contact', function(req, res, next) {
MailPimpTask.create({
subject: 'DECENTRALIZE Contact Form',
recipient: 'eric@self.app.fm',
sender: req.param('from'),
content: req.param('message')
}, function(err, task) {
req.flash('info', 'Mail sent successfully! We\'ll get in touch shortly.');
res.redirect('/');
});
});
self.app.app.get('/team', function(req, res, next) {
res.render('team');
});
self.app.app.get('/subscribe', function(req, res, next) {
res.render('subscribe');
});

// redirect an erroneous lengthy tag
self.app.app.get('/shows/episode-26-nick-sullivan-on-changetip-and-the-future-of-bitcoin-microtransactions', function(req, res, next) {
res.redirect( 301 , '/shows/episode-25-nick-sullivan');
});
self.app.app.get('/shows/episode-29-susanne-tempelhof-and-dan-metcalf-on-blockchain-applications-and-bitcoin-2-0', function(req, res, next) {
res.redirect( 301 , '/shows/episode-29-susanne-tempelhof-and-dan-metcalf');
});

self.app.app.get('/:somePath', function(req, res, next) {
Show.get({ slug: req.param('somePath') }, function(err, show) {
if (show) return res.redirect('/shows/' + show.slug );
next();
});
});
self.app.app.get('/shows', function(req, res, next) {
if (req.accepts('application/rss+xml')) {
return res.redirect('/feed');
} else {
return next();
}
});
self.app.app.get('/rss', function(req, res, next) {
res.redirect( 301 , '/feed' );
});
self.app.app.get('/feed', function(req, res, next) {
Show.query({}, function(err, shows) {
res.set('Content-Type', 'application/rss+xml');
res.render('feed', {
resource: Show,
collection: shows
});
});
});

var engine = new Engine( self.config , self.app );

setInterval(function() {
//engine.sync();
}, /*/ 2500 /*/ 1 * 3600 * 1000 /**/ );

engine.subscribe();
engine.sync();

return done();

});

});
}

module.exports = DECENTRALIZE;
Loading