api.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. /* jshint esversion:6, strict:global */
  3. function check(url, next) {
  4. if (!url || !next) {
  5. return;
  6. }
  7. const req = new XMLHttpRequest();
  8. req.open('GET', url, true);
  9. req.setRequestHeader('Authorization', 'GoogleLogin auth=test/1');
  10. req.onerror = function (e) {
  11. next('FAIL: HTTP ' + e);
  12. };
  13. req.onload = function () {
  14. if (this.status == 200) {
  15. next(this.response);
  16. } else {
  17. next('FAIL: HTTP error ' + this.status + ' ' + this.statusText);
  18. }
  19. };
  20. req.send();
  21. }
  22. const jsonVars = JSON.parse(document.getElementById('jsonVars').innerHTML);
  23. check(jsonVars.greader + '/check/compatibility', function next(result1) {
  24. const greaderOutput = document.getElementById('greaderOutput');
  25. if (result1 === 'PASS') {
  26. greaderOutput.innerHTML = '✔️ ' + result1;
  27. } else {
  28. check(jsonVars.greader + '/check%2Fcompatibility', function next(result2) {
  29. if (result2 === 'PASS') {
  30. greaderOutput.innerHTML = '⚠️ WARN: no <code>%2F</code> support, so some clients will not work!';
  31. } else {
  32. check('./greader.php/check/compatibility', function next(result3) {
  33. if (result3 === 'PASS') {
  34. greaderOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php';
  35. } else {
  36. greaderOutput.innerHTML = '❌ ' + result1;
  37. }
  38. });
  39. }
  40. });
  41. }
  42. });
  43. check(jsonVars.fever + '?api', function next(result1) {
  44. const feverOutput = document.getElementById('feverOutput');
  45. try {
  46. JSON.parse(result1);
  47. feverOutput.innerHTML = '✔️ PASS';
  48. } catch (ex) {
  49. check('./fever.php?api', function next(result2) {
  50. try {
  51. JSON.parse(result2);
  52. feverOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php';
  53. } catch (ex) {
  54. feverOutput.innerHTML = '❌ ' + result1;
  55. }
  56. });
  57. }
  58. });