Skip to content

Fix small issues #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions web.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ var Annotation = new Schema({
}
});

Annotation.index({uri: 1});

var AnnotationModel = mongoose.model('Annotation', Annotation);

// DB
Expand Down Expand Up @@ -205,6 +207,11 @@ app.get('/api/search', tokenOK, function(req, res) {
if (req.query.uri) {
query.where('uri').equals(req.query.uri);
}
default:
query = AnnotationModel.find();
if (req.query.uri) {
query.where('uri').equals(req.query.uri);
}
break;
}

Expand Down Expand Up @@ -251,15 +258,10 @@ app.get('/api/search', tokenOK, function(req, res) {
else {
query.exec(function(err, annotations) {
if (!err) {
// console.info(annotations);
if (annotations.length > 0) {
console.info(annotations);
return res.send({
'rows': annotations
});
}
else {
return res.send(204, 'Successfully deleted annotation.');
}
}
else {
return console.log(err);
Expand Down Expand Up @@ -407,8 +409,8 @@ function tokenOK(req, res, next) {
};

function inWindow(decoded, next) {
var issuedAt = decoded.issuedAt;
var ttl = decoded.ttl;
var issuedAt = decoded.iat;
var ttl = decoded.exp;
var issuedSeconds = new Date(issuedAt) / 1000;
var nowSeconds = new Date().getTime() / 1000;
var diff = ((nowSeconds - issuedSeconds));
Expand Down