Baphomet is the dedicated bot for nulloctet matrix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5 KiB

  1. let fs = require('fs');
  2. let { logger } = require('./logging');
  3. function getShortestPrefix(radixTree, key, sliceSize) {
  4. let shortKey = key.substring(0, sliceSize);
  5. let keyCount = radixTree.countPrefix(shortKey);
  6. if (keyCount < 1) {
  7. return null;
  8. }
  9. if (key.length === sliceSize && radixTree.getPrefix(shortKey).includes(key)) {
  10. return null;
  11. }
  12. if (keyCount === 1) {
  13. return shortKey;
  14. }
  15. return getShortestPrefix(radixTree, key, sliceSize + 1);
  16. }
  17. function toISODateString(d) {
  18. function pad(n) { return n < 10 ? '0' + n : n }
  19. return d.getUTCFullYear() + '-'
  20. + pad(d.getUTCMonth() + 1) + '-'
  21. + pad(d.getUTCDate()) + 'T'
  22. + pad(d.getUTCHours()) + ':'
  23. + pad(d.getUTCMinutes()) + ':'
  24. + pad(d.getUTCSeconds()) + 'Z'
  25. }
  26. function getBuildInfo(buildInfoPath) {
  27. try {
  28. return fs.readFileSync(buildInfoPath, "utf8");
  29. } catch (err) {
  30. if (err.code === 'ENOENT') {
  31. return "UNKNOWN_" + toISODateString(new Date());
  32. } else {
  33. logger.error("Unexpected Error!", err);
  34. }
  35. }
  36. }
  37. function sleep(ms) {
  38. return new Promise(resolve => {
  39. setTimeout(resolve, ms)
  40. })
  41. }
  42. function isString(s) {
  43. return typeof(s) === 'string' || s instanceof String;
  44. }
  45. exports.getShortestPrefix = getShortestPrefix;
  46. exports.toISODateString = toISODateString;
  47. exports.getBuildInfo = getBuildInfo;
  48. exports.sleep = sleep;
  49. exports.isString = isString;