Returning notes sorted. laast first
This commit is contained in:
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 |
|
@ -15,6 +15,7 @@
|
||||||
"express": "^4.14.0",
|
"express": "^4.14.0",
|
||||||
"gcloud": "^0.36.0",
|
"gcloud": "^0.36.0",
|
||||||
"geolib": "^2.0.21",
|
"geolib": "^2.0.21",
|
||||||
|
"imgur-node-api": "^0.1.0",
|
||||||
"node-uuid": "^1.4.7"
|
"node-uuid": "^1.4.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ var utils = require('./utils');
|
||||||
// var bucket = require('./storageManager');
|
// var bucket = require('./storageManager');
|
||||||
var uuid = require('node-uuid');
|
var uuid = require('node-uuid');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var imgur = require('imgur-node-api');
|
||||||
|
imgur.setClientID('d694242fc19e1a8');
|
||||||
|
|
||||||
var gcloud = require('gcloud');
|
var gcloud = require('gcloud');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
@ -27,14 +29,9 @@ router.post('/upload', (req, res) => {
|
||||||
var image_name = uuid.v4() + '.' + file_ending;
|
var image_name = uuid.v4() + '.' + file_ending;
|
||||||
var file_path = path.join(__dirname, '..', '/Images/', image_name);
|
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 data = req.body.image.replace(/^data:image\/\w+;base64,/, '');
|
||||||
// var fd = fs.openSync(path.join(__dirname, '..', '/Images/', image_name), 'w');
|
// var fd = fs.openSync(path.join(__dirname, '..', '/Images/', image_name), 'w');
|
||||||
|
//
|
||||||
fs.writeFile(file_path, data, {
|
fs.writeFile(file_path, data, {
|
||||||
encoding: 'base64'
|
encoding: 'base64'
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
|
@ -45,30 +42,21 @@ router.post('/upload', (req, res) => {
|
||||||
image_url: null
|
image_url: null
|
||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
res.send({
|
imgur.upload(file_path, function (err, _res) {
|
||||||
status: "OK",
|
console.log(_res.data.link);
|
||||||
image_url: "http://thesocialnotework-api.appspot.com/file/image/" + image_name
|
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;
|
module.exports = router;
|
||||||
|
|
|
@ -131,6 +131,7 @@ router.get('/all', (req, res) => {
|
||||||
notes.push(n);
|
notes.push(n);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
notes = notes.sort(utils.sort); //SORT BY TIME _ LATEST FIRST
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
res.send({
|
res.send({
|
||||||
status: "OK",
|
status: "OK",
|
||||||
|
@ -218,6 +219,7 @@ router.post('/getPublic', (req, res) => {
|
||||||
if (Number(n.owner_id) !== Number(req.body.id)) return true;
|
if (Number(n.owner_id) !== Number(req.body.id)) return true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
notes = notes.sort(utils.sort); //SORT BY TIME _ LATEST FIRST
|
||||||
if (req.body.filter) {
|
if (req.body.filter) {
|
||||||
if (req.body.filter.location) {
|
if (req.body.filter.location) {
|
||||||
notes = notes.filter((note) => {
|
notes = notes.filter((note) => {
|
||||||
|
|
|
@ -15,7 +15,13 @@ class Server {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// parse application/json
|
// 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('/api', api);
|
||||||
this.app.use('/file/image/', express.static('Images'));
|
this.app.use('/file/image/', express.static('Images'));
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ router.post('/upsert', (req, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
utils.response_500(res, "DB Error");
|
utils.response_500(res, "DB Error");
|
||||||
} else {
|
} else {
|
||||||
|
utils.clearCash();
|
||||||
entity.data.email = req.body.email || entity.data.email;
|
entity.data.email = req.body.email || entity.data.email;
|
||||||
entity.data.avatar = req.body.avatar || entity.data.avatar;
|
entity.data.avatar = req.body.avatar || entity.data.avatar;
|
||||||
entity.data.password = req.body.password || entity.data.password;
|
entity.data.password = req.body.password || entity.data.password;
|
||||||
|
|
|
@ -3,8 +3,14 @@ var avatars = {};
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
console.log('Clearing Cash');
|
console.log('Clearing Cash');
|
||||||
avatars = {};
|
avatars = {};
|
||||||
}, 10 * 60 * 1000);
|
}, 3 * 60 * 1000);
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
clearCash: () => {
|
||||||
|
avatars = {};
|
||||||
|
},
|
||||||
|
sort: (a, b) => {
|
||||||
|
return b.created_at - a.created_at;
|
||||||
|
},
|
||||||
response_400: (res, example, msg) => {
|
response_400: (res, example, msg) => {
|
||||||
res.statusCode = 400;
|
res.statusCode = 400;
|
||||||
var r = {
|
var r = {
|
||||||
|
|
Loading…
Reference in a new issue