Returning notes sorted. laast first

This commit is contained in:
Sagi Dayan 2016-07-09 16:16:24 +03:00
parent 033d807071
commit 9465e8c3f9
12 changed files with 30 additions and 26 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -15,6 +15,7 @@
"express": "^4.14.0",
"gcloud": "^0.36.0",
"geolib": "^2.0.21",
"imgur-node-api": "^0.1.0",
"node-uuid": "^1.4.7"
}
}

View File

@ -4,6 +4,8 @@ var utils = require('./utils');
// var bucket = require('./storageManager');
var uuid = require('node-uuid');
var fs = require('fs');
var imgur = require('imgur-node-api');
imgur.setClientID('d694242fc19e1a8');
var gcloud = require('gcloud');
var path = require('path');
@ -27,14 +29,9 @@ router.post('/upload', (req, res) => {
var image_name = uuid.v4() + '.' + file_ending;
var file_path = path.join(__dirname, '..', '/Images/', image_name);
// //Permissions to file
// file.acl.add({
// entity: 'allUsers',
// role: gcs.acl.READER_ROLE
// }, function (err, aclObject) {
var data = req.body.image.replace(/^data:image\/\w+;base64,/, '');
// var fd = fs.openSync(path.join(__dirname, '..', '/Images/', image_name), 'w');
//
fs.writeFile(file_path, data, {
encoding: 'base64'
}, function (err) {
@ -45,30 +42,21 @@ router.post('/upload', (req, res) => {
image_url: null
});
else {
res.send({
status: "OK",
image_url: "http://thesocialnotework-api.appspot.com/file/image/" + image_name
imgur.upload(file_path, function (err, _res) {
console.log(_res.data.link);
res.send({
status: 'OK',
image_url: _res.data.link
});
});
}
// });
});
//
// });
// });
// fs.createReadStream('/Users/stephen/Photos/birthday-at-the-zoo/panda.jpg')
// .pipe(file.createWriteStream({
// metadata: {
// contentType: 'image/jpeg',
// metadata: {
// custom: 'metadata'
// }
// }
// }))
// .on('error', function(err) {})
// .on('finish', function() {
// // The file upload is complete.
// });
});
module.exports = router;

View File

@ -131,6 +131,7 @@ router.get('/all', (req, res) => {
notes.push(n);
});
}
notes = notes.sort(utils.sort); //SORT BY TIME _ LATEST FIRST
setTimeout(() => {
res.send({
status: "OK",
@ -218,6 +219,7 @@ router.post('/getPublic', (req, res) => {
if (Number(n.owner_id) !== Number(req.body.id)) return true;
return false;
});
notes = notes.sort(utils.sort); //SORT BY TIME _ LATEST FIRST
if (req.body.filter) {
if (req.body.filter.location) {
notes = notes.filter((note) => {

View File

@ -15,7 +15,13 @@ class Server {
}));
// parse application/json
this.app.use(bodyParser.json());
this.app.use(bodyParser.json({
limit: '50mb'
}));
this.app.use(bodyParser.urlencoded({
limit: '50mb',
extended: true
}));
this.app.use('/api', api);
this.app.use('/file/image/', express.static('Images'));

View File

@ -17,6 +17,7 @@ router.post('/upsert', (req, res) => {
if (err) {
utils.response_500(res, "DB Error");
} else {
utils.clearCash();
entity.data.email = req.body.email || entity.data.email;
entity.data.avatar = req.body.avatar || entity.data.avatar;
entity.data.password = req.body.password || entity.data.password;

View File

@ -3,8 +3,14 @@ var avatars = {};
setInterval(() => {
console.log('Clearing Cash');
avatars = {};
}, 10 * 60 * 1000);
}, 3 * 60 * 1000);
module.exports = {
clearCash: () => {
avatars = {};
},
sort: (a, b) => {
return b.created_at - a.created_at;
},
response_400: (res, example, msg) => {
res.statusCode = 400;
var r = {