api.js 1.9 KB

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