config.js 765 B

12345678910111213141516171819202122
  1. var results = {};
  2. results["username"] = USERNAME;
  3. results["usericon"] = USERICON;
  4. results["unlimited"] = false;
  5. if (USERQUOTA_TOTAL == -1) {
  6. results["unlimited"] = true;
  7. results["quota"] = 0;
  8. results["quota_human"] = bytesToSize(USERQUOTA_USED);
  9. } else {
  10. results["quota"] = USERQUOTA_USED / USERQUOTA_TOTAL * 100;
  11. }
  12. sendJSONResp(JSON.stringify(results));
  13. //From stackoverflow.com
  14. //https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
  15. function bytesToSize(bytes) {
  16. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  17. if (bytes == 0) return '0 Byte';
  18. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  19. return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
  20. }