util.js 664 B

1234567891011121314151617181920212223242526
  1. const SplittableRandom = Java.type('java.util.SplittableRandom');
  2. const random = new SplittableRandom();
  3. module.exports = {
  4. randomWorld: () => {
  5. return 1 + random.nextInt(10000)
  6. },
  7. /**
  8. * Returns the value of the "queries" getRequest parameter, which is an integer
  9. * bound between 1 and 500 with a default value of 1.
  10. *
  11. * @param request the current HTTP request
  12. * @return the value of the "queries" parameter
  13. */
  14. getQueries: (request) => {
  15. let param = request.getParam("queries");
  16. if (param == null) {
  17. return 1;
  18. }
  19. // invalid params are converted to 1
  20. return Math.min(500, parseInt(param, 10) || 1);
  21. }
  22. };