disallow future fetching

This commit is contained in:
_Bastler 2021-10-06 22:17:31 +02:00
parent fe47739cb8
commit 50c2776f19
2 changed files with 77 additions and 36 deletions

View File

@ -72,6 +72,14 @@ public class CommentController extends BaseController {
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("desc") Optional<Boolean> descParameter, @RequestParam("desc") Optional<Boolean> descParameter,
@RequestParam("ignore") Optional<List<String>> ignoreParameter) { @RequestParam("ignore") Optional<List<String>> ignoreParameter) {
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
sizeParameter = Optional.of(100);
}
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Comment> comments = commentManager.fetchByDate(getCurrentUsername(), target, Page<Comment> comments = commentManager.fetchByDate(getCurrentUsername(), target,
parent.orElse(null), dateParameter.orElse(Instant.now()), pageParameter.orElse(0), parent.orElse(null), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false)); sizeParameter.orElse(settingsManager.getPageSize()), descParameter.orElse(false));
@ -102,6 +110,15 @@ public class CommentController extends BaseController {
@RequestParam("date") Optional<Instant> dateParameter, @RequestParam("date") Optional<Instant> dateParameter,
@RequestParam("asc") Optional<Boolean> ascParameter, @RequestParam("asc") Optional<Boolean> ascParameter,
@RequestParam("ignore") Optional<List<String>> ignoreParameter) { @RequestParam("ignore") Optional<List<String>> ignoreParameter) {
if (sizeParameter.isPresent() && sizeParameter.get() > 100) {
sizeParameter = Optional.of(100);
}
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Comment> comments = commentManager.fetchByUsername(username, parent.orElse(null), Page<Comment> comments = commentManager.fetchByUsername(username, parent.orElse(null),
dateParameter.orElse(Instant.now()), pageParameter.orElse(0), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));

View File

@ -82,6 +82,14 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
if (gravityParameter.isPresent() && gravityParameter.get() > 2) {
gravityParameter = Optional.of(2.0);
}
Page<RankedEntry> entries = entryManager.fetchByRanking(dateParameter.orElse(Instant.now()), Page<RankedEntry> entries = entryManager.fetchByRanking(dateParameter.orElse(Instant.now()),
gravityParameter.orElse(getGravity()), pageParameter.orElse(0), gravityParameter.orElse(getGravity()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize())); sizeParameter.orElse(settingsManager.getPageSize()));
@ -119,6 +127,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Entry> entries = entryManager.fetchByDate(dateParameter.orElse(Instant.now()), Page<Entry> entries = entryManager.fetchByDate(dateParameter.orElse(Instant.now()),
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
List<String> ignore = ignoreParameter.orElse(Lists.newArrayList()); List<String> ignore = ignoreParameter.orElse(Lists.newArrayList());
@ -149,6 +161,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<RankedEntry> entries = entryManager.fetchByComments( Page<RankedEntry> entries = entryManager.fetchByComments(
dateParameter.orElse(Instant.now()), gravityParameter.orElse(getGravity()), dateParameter.orElse(Instant.now()), gravityParameter.orElse(getGravity()),
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
@ -184,6 +200,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Entry> entries = entryManager.fetchByLastComment(dateParameter.orElse(Instant.now()), Page<Entry> entries = entryManager.fetchByLastComment(dateParameter.orElse(Instant.now()),
pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize())); pageParameter.orElse(0), sizeParameter.orElse(settingsManager.getPageSize()));
@ -217,6 +237,10 @@ public class EntryController extends BaseController {
sizeParameter = Optional.of(100); sizeParameter = Optional.of(100);
} }
if (dateParameter.isPresent() && dateParameter.get().isAfter(Instant.now())) {
dateParameter = Optional.of(Instant.now());
}
Page<Entry> entries = entryManager.fetchByUser(username, Page<Entry> entries = entryManager.fetchByUser(username,
dateParameter.orElse(Instant.now()), pageParameter.orElse(0), dateParameter.orElse(Instant.now()), pageParameter.orElse(0),
sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false)); sizeParameter.orElse(settingsManager.getPageSize()), ascParameter.orElse(false));