Socket
Socket
Sign inDemoInstall

couchdb-node-cms

Package Overview
Dependencies
123
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 0.1.3

208

lib/main.js

@@ -13,3 +13,3 @@ var nano = require('nano'),

breaks: true,
highlight: function(code) {
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;

@@ -52,5 +52,5 @@ }

CmsEngine.prototype.start = function() {
CmsEngine.prototype.start = function () {
var that = this;
syncDesignDoc.create(this.config, function(err, db) {
syncDesignDoc.create(this.config, function (err, db) {
if (err)

@@ -63,3 +63,3 @@ throw new Exception(err);

CmsEngine.prototype.addServer = function() {
CmsEngine.prototype.addServer = function () {
// add urls for the express server

@@ -81,9 +81,7 @@ var app = this.server;

app.get(apiRoot + '/', function(req, res) {
res.redirect(apiRoot + '/posts');
});
app.get(this.apiRoot + '/posts', function(req, res) {
db.view(that.config.db, 'posts_by_date', function(err, resp) {
var renderPosts = function (res) {
db.view(that.config.db, 'posts_by_date', function (err, resp) {
if (!err) {
var posts = resp.rows.map(function(x) {
var posts = resp.rows.map(function (x) {
x.value.body = marked(x.value.body);

@@ -103,7 +101,59 @@ return x.value;

}
});
};
var renderPost = function (id, res) {
db.get(id, function (err, resp) {
if (!err) {
var attachments = resp._attachments;
resp.body = marked(resp.body);
var files = [];
if (attachments) {
for (var key in attachments) {
files.push({
name: key,
option: (resp.credentials[key].isPrivate ? 'Make public' : 'Make private'),
credentials: resp.credentials[key].isPrivate
});
}
resp.files = files;
delete resp._attachments;
}
resp.apiRoot = apiRoot;
res.render('post.html', resp);
} else {
res.status(500).send('Error retrieving data');
}
});
};
app.get(apiRoot + '/', function (req, res) {
res.redirect(apiRoot + '/posts');
});
app.get(apiRoot + '/posts/new', function(req, res) {
app.get(this.apiRoot + '/posts', function (req, res) {
renderPosts(res);
// db.view(that.config.db, 'posts_by_date', function(err, resp) {
// if (!err) {
// var posts = resp.rows.map(function(x) {
// x.value.body = marked(x.value.body);
// return x.value;
// });
// res.render('posts', {
// head: {
// title: 'page title'
// },
// posts: posts,
// apiRoot: that.apiRoot
// });
// } else {
// res.status(500).send('Error retrieving data');
// }
// });
});
app.get(apiRoot + '/posts/new', function (req, res) {
res.render('new-post.html', {

@@ -117,3 +167,3 @@ head: {

app.post(apiRoot + '/posts', function(req, res) {
app.post(apiRoot + '/posts', function (req, res) {
var post = req.body;

@@ -124,3 +174,3 @@ post.type = 'post';

if (req.body._id) {
db.get(req.body._id, function(err, resp) {
db.get(req.body._id, function (err, resp) {
if (!err) {

@@ -130,4 +180,5 @@ resp.title = post.title;

resp.postedAt = post.postedAt;
db.insert(resp, function(err, resp) {
res.redirect(apiRoot + '/posts');
db.insert(resp, function (err, resp) {
// res.redirect(apiRoot + '/posts');
renderPosts(res);
});

@@ -139,5 +190,6 @@ } else {

} else {
db.insert(post, function(err, resp) {
db.insert(post, function (err, resp) {
if (!err)
res.redirect(apiRoot + '/posts');
// res.redirect(apiRoot + '/posts');
renderPosts(res);
else

@@ -151,4 +203,4 @@ res.status(500).send('Error retrieving data');

app.get(apiRoot + '/posts/:id/edit', function(req, res) {
db.get(req.params.id, function(err, resp) {
app.get(apiRoot + '/posts/:id/edit', function (req, res) {
db.get(req.params.id, function (err, resp) {
if (!err) {

@@ -168,32 +220,27 @@ res.render('edit-post.html', {

app.get(apiRoot + '/posts/:id', function(req, res) {
db.get(req.params.id, function(err, resp) {
app.get(apiRoot + '/posts/:id/delete', function (req, res) {
console.log("destroying");
db.get(req.params.id, function (err, resp1) {
if (!err) {
var attachments = resp._attachments;
resp.body = marked(resp.body);
var files = [];
if (attachments) {
for (var key in attachments) {
files.push({
name: key,
option: (resp.credentials[key].isPrivate ? 'Make public' : 'Make private'),
credentials: resp.credentials[key].isPrivate
});
db.destroy(req.params.id, resp1._rev, function (err, resp2) {
if (!err) {
renderPosts(res);
} else {
res.status(500).send('Error Deleting data');
}
resp.files = files;
delete resp._attachments;
}
resp.apiRoot = apiRoot;
res.render('post.html', resp);
});
} else {
res.status(500).send('Error retrieving data');
res.status(500).send('Error Deleting data');
}
});
});
app.get('/authenticate' + apiRoot + '/posts/:id/files/:filename', this.auth, function(req, res) {
db.get(req.params.id, function(err, resp) {
app.get(apiRoot + '/posts/:id', function (req, res) {
renderPost(req.params.id, res);
});
app.get('/authenticate' + apiRoot + '/posts/:id/files/:filename', this.auth, function (req, res) {
db.get(req.params.id, function (err, resp) {
if (!err) {
db.attachment.get(req.params.id, req.params.filename).pipe(res);
db.attachment.get(req.params.id, req.params.filename).pipe(res);
} else {

@@ -205,11 +252,11 @@ res.status(500).send('Error retrieving data');

app.get(apiRoot + '/posts/:id/files/:filename', function(req, res) {
db.get(req.params.id, function(err, resp) {
app.get(apiRoot + '/posts/:id/files/:filename', function (req, res) {
db.get(req.params.id, function (err, resp) {
if (!err) {
if (!resp.credentials[req.params.filename].isPrivate)
db.attachment.get(req.params.id, req.params.filename).pipe(res);
else{
if(that.auth){
else {
if (that.auth) {
res.redirect('/authenticate' + req.url);
}else{
} else {
res.status(403).send('Access denied');

@@ -224,4 +271,4 @@ }

app.get(apiRoot + '/posts/:id/files/:filename/credentials/:credentials', function(req, res) {
db.get(req.params.id, function(err, resp) {
app.get(apiRoot + '/posts/:id/files/:filename/credentials/:credentials', function (req, res) {
db.get(req.params.id, function (err, resp) {
if (!err) {

@@ -231,8 +278,9 @@ // console.log(resp.credentials[req.params.filename].isPrivate);

// console.log(resp.credentials[req.params.filename].isPrivate);
db.insert(resp, function(err, r) {
res.writeHead(303, {
Connection: 'close',
Location: apiRoot + '/posts/' + req.params.id
})
res.end();
db.insert(resp, function (err, r) {
renderPost(req.params.id, res);
// res.writeHead(303, {
// Connection: 'close',
// Location: apiRoot + '/posts/' + req.params.id
// })
// res.end();
});

@@ -245,17 +293,18 @@ } else {

app.get(apiRoot + '/posts/:id/files/:filename/delete', function(req, res) {
db.get(req.params.id, function(err, resp) {
app.get(apiRoot + '/posts/:id/files/:filename/delete', function (req, res) {
db.get(req.params.id, function (err, resp) {
if (!err) {
db.attachment.destroy(req.params.id, req.params.filename, {
rev: resp._rev
}, function(err, body) {
}, function (err, body) {
if (!err) {
db.get(req.params.id, function(err, resp2) {
db.get(req.params.id, function (err, resp2) {
delete resp2.credentials[req.params.filename];
db.insert(resp2, function(err, r) {
res.writeHead(303, {
Connection: 'close',
Location: apiRoot + '/posts/' + req.params.id
})
res.end();
db.insert(resp2, function (err, r) {
renderPost(req.params.id, res);
// res.writeHead(303, {
// Connection: 'close',
// Location: apiRoot + '/posts/' + req.params.id
// })
// res.end();
});

@@ -277,3 +326,3 @@ });

app.post(apiRoot + '/posts/:id/files', function(req, res) {
app.post(apiRoot + '/posts/:id/files', function (req, res) {

@@ -284,15 +333,15 @@ var busboy = new Busboy({

var fileData, fileName, mimeType, isPrivate = false;
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
// console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);
fileName = filename;
mimeType = mimetype;
file.on('data', function(data) {
file.on('data', function (data) {
fileData = data
// console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
file.on('end', function () {
console.log('File [' + fieldname + '] Finished');
});
});
busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {
busboy.on('field', function (fieldname, val, fieldnameTruncated, valTruncated) {
console.log('Field [' + fieldname + ']: value: ' + val);

@@ -305,5 +354,5 @@ if (val === 'on')

busboy.on('finish', function() {
busboy.on('finish', function () {
console.log('Done parsing form!');
db.get(req.params.id, function(err, resp) {
db.get(req.params.id, function (err, resp) {
if (!err) {

@@ -313,5 +362,5 @@ db.attachment.insert(req.params.id, fileName, fileData, mimeType, {

},
function(err, attachResp) {
function (err, attachResp) {
if (!err) {
db.get(req.params.id, function(err, resp2) {
db.get(req.params.id, function (err, resp2) {
resp2.credentials = resp2.credentials || {};

@@ -321,8 +370,9 @@ resp2.credentials[fileName] = {

};
db.insert(resp2, function(err, r) {
res.writeHead(303, {
Connection: 'close',
Location: apiRoot + '/posts/' + req.params.id
})
res.end();
db.insert(resp2, function (err, r) {
renderPost(req.params.id, res);
// res.writeHead(303, {
// Connection: 'close',
// Location: apiRoot + '/posts/' + req.params.id
// })
// res.end();
});

@@ -329,0 +379,0 @@ });

{
"name": "couchdb-node-cms",
"version": "0.1.2",
"version": "0.1.3",
"author": "Hussein Taha",

@@ -5,0 +5,0 @@ "email": "taha.hussein@outlook.com",

@@ -52,2 +52,2 @@

* 0.1.2 Initial release
* 0.1.3 Initial release

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc