4
0

api.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
  2. 'use strict';
  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. });
  59. // @license-end