Skip to content

Commit

Permalink
Finalized API, seems sane. Need to test/refactor, and actually start …
Browse files Browse the repository at this point in the history
…using crypto
  • Loading branch information
Saem Ghani committed Mar 8, 2011
1 parent 66b1dfd commit dbe6547
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -14,7 +14,10 @@ Additionally, we can put new content in by way of a POST -- this still needs to

* Install node (https://github.com/ry/node/wiki/Installation)
* Install npm (https://github.com/isaacs/npm)
* NODE_ENV=(development|production) node cacey.js (note I use supervisor (https://github.com/fgnass/node-dev) during development)
* NODE_ENV=(development|production) node cacey.js

*Note* I use supervisor (https://github.com/fgnass/node-dev) during development, so the last step is:
* NODE_ENV=development node-dev cacey.js

## API

Expand Down
18 changes: 12 additions & 6 deletions cacey.js
Expand Up @@ -16,7 +16,7 @@
var express = require('express')
var app = express.createServer();

contentHash = {'sha-1:content' : 'your mom'}
contentHash = {'sha-1:hashkey' : 'some awesome content =D'}

app.configure(function() {
app.use(express.methodOverride())
Expand All @@ -37,7 +37,7 @@ app.configure('production', function(){
//Setup the routes

app.get('/hashing', function(req, res) {
res.send(supportedHashingSchemes(), 200);
res.send(supportedHashingSchemes().toString(), 200);
});

app.get('/hashing/:hashing', function(req, res) {
Expand All @@ -59,20 +59,26 @@ app.get('/hashing/:hashingScheme/content', function(req, res) {
});

app.get('/hashing/:hashing/content/:contentKey', function(req, res) {
var content = contentHash[createHashKey(req.query['hashing'], req.params['contentKey'])];
var content = contentHash[createHashKey(req.params['hashing'], req.params['contentKey'])];
if(content == null) { send404(res); } else { res.send(content, 200); }
});

app.post('/content', function(req, res) {
var hashing = 'sha-1';
var contentKey = contentHash.size() + 1;
var contentKey = Object.keys(contentHash).length + 1; //lame hashing until I wire in the crypto stuffs

var content = req.body['content'];

var key = createHashKey(hashing, contentKey);

contentHash[key] = content;
res.redirect('/' + hashing + '/' + contentKey, 200);
if(!contentHash.hasOwnProperty(key)) {
contentHash[key] = content;
res.redirect('/' + hashing + '/' + contentKey, 200);
} else {
res.send('Cannot overwrite existing content, or key collision', 409);
//Security issue, you could flood a server with the same content, will need the logging system to be smart, otherwise DoS, possibly
console.log('Possible key collision content. key: ' + key + 'content: ' + req.body['content']);
}
});

app.get(/.*/, function(req, res) {
Expand Down

0 comments on commit dbe6547

Please sign in to comment.