Skip to content

Commit

Permalink
Merge pull request #447 from kabalin/nearest-limit
Browse files Browse the repository at this point in the history
Restrict photo.giveNearestPhotos distance
  • Loading branch information
kabalin authored Jan 24, 2022
2 parents 8ed6fab + fba0865 commit 9b7edb3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions controllers/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ async function giveUserPhotosAround({ cid, limitL, limitR }) {
* @param {number} obj.year
* @param {number} obj.year2
* @param {number} obj.except cid to exclude
* @param {number} obj.distance distance in radians
* @param {number} obj.distance distance in meters (1000km max)
* @param {number} obj.limit
* @param {number} obj.skip
* @returns {object[]} photos
Expand Down Expand Up @@ -1977,11 +1977,11 @@ async function giveNearestPhotos({ geo, type, year, year2, except, distance, lim
query.cid = { $ne: except };
}

if (_.isNumber(distance) && distance > 0 && distance < Math.PI) {
query.geo.$nearSphere.$maxDistance = Utils.geo.rad2meter(distance);
if (_.isNumber(distance) && distance > 0) {
query.geo.$nearSphere.$maxDistance = Math.min(1000000, distance);
} else {
// By default restrict distance to hemisphere with the center at the point.
query.geo.$nearSphere.$maxDistance = Utils.geo.rad2meter(Math.PI / 2);
// By default restrict distance to 10km.
query.geo.$nearSphere.$maxDistance = 10000;
}

if (_.isNumber(limit) && limit > 0 && limit < 30) {
Expand Down

0 comments on commit 9b7edb3

Please sign in to comment.