diff options
Diffstat (limited to 'p/scripts')
| -rw-r--r-- | p/scripts/api.js | 114 |
1 files changed, 72 insertions, 42 deletions
diff --git a/p/scripts/api.js b/p/scripts/api.js index ce52c50ad..62ce386f8 100644 --- a/p/scripts/api.js +++ b/p/scripts/api.js @@ -1,7 +1,7 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 'use strict'; -function check(url, next) { +const check = function (url, next) { if (!url || !next) { return; } @@ -19,45 +19,75 @@ function check(url, next) { } }; req.send(); -} - -const jsonVars = JSON.parse(document.getElementById('jsonVars').innerHTML); - -check(jsonVars.greader + '/check/compatibility', function next(result1) { - const greaderOutput = document.getElementById('greaderOutput'); - if (result1 === 'PASS') { - greaderOutput.innerHTML = '✔️ ' + result1; - } else { - check(jsonVars.greader + '/check%2Fcompatibility', function next(result2) { - if (result2 === 'PASS') { - greaderOutput.innerHTML = '⚠️ WARN: no <code>%2F</code> support, so some clients will not work!'; - } else { - check('./greader.php/check/compatibility', function next(result3) { - if (result3 === 'PASS') { - greaderOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; - } else { - greaderOutput.innerHTML = '❌ ' + result1; - } - }); - } - }); - } -}); - -check(jsonVars.fever + '?api', function next(result1) { - const feverOutput = document.getElementById('feverOutput'); - try { - JSON.parse(result1); - feverOutput.innerHTML = '✔️ PASS'; - } catch (ex) { - check('./fever.php?api', function next(result2) { - try { - JSON.parse(result2); - feverOutput.innerHTML = '⚠️ WARN: Probable invalid base URL in ./data/config.php'; - } catch (ex) { - feverOutput.innerHTML = '❌ ' + result1; - } - }); - } -}); +}; + +const pass = function (output) { + output.innerHTML = output.dataset.i18nPass; +}; + +const encodingSupport = function (output) { + output.innerHTML = output.dataset.i18nEncodingSupport; +}; + +const invalidConfiguration = function (output) { + output.innerHTML = output.dataset.i18nInvalidConfiguration; +}; + +const unknownError = function (output, message) { + output.innerHTML = output.dataset.i18nUnknownError + message; +}; + +const checkGReaderAPI = function () { + const output = document.getElementById('greaderOutput'); + const apiUrl = output.dataset.apiUrl; + + check(apiUrl + '/check/compatibility', function next(result1) { + if (result1 === 'PASS') { + pass(output); + } else { + check(apiUrl + '/check%2Fcompatibility', function next(result2) { + if (result2 === 'PASS') { + encodingSupport(output); + } else { + check('./greader.php/check/compatibility', function next(result3) { + if (result3 === 'PASS') { + invalidConfiguration(output); + } else { + unknownError(output, result1); + } + }); + } + }); + } + }); +}; + +const checkFeverAPI = function () { + const output = document.getElementById('feverOutput'); + const apiUrl = output.dataset.apiUrl; + + check(apiUrl + '?api', function next(result1) { + try { + JSON.parse(result1); + pass(output); + } catch (ex) { + check('./fever.php?api', function next(result2) { + try { + JSON.parse(result2); + invalidConfiguration(output); + } catch (ex) { + unknownError(output, result1); + } + }); + } + }); +}; + +/** + * The API tests are done this way to simulate in a more accurate manner + * outside requests. Since the APIs are used by third-party tools, they + * cannot interact at the server level. + */ +checkGReaderAPI(); +checkFeverAPI(); // @license-end |
