VersionService.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. let server_info = null;
  20. export async function fetchServerInfo(api_origin, auth_token) {
  21. if (server_info) return server_info;
  22. try {
  23. const res = await $.ajax({
  24. url: api_origin + "/version",
  25. type: 'GET',
  26. contentType: "application/json",
  27. headers: {
  28. "Authorization": "Bearer " + auth_token
  29. },
  30. statusCode: {
  31. 401: function () {
  32. logout();
  33. }
  34. }
  35. });
  36. server_info = {
  37. version: res.version,
  38. location: res.location,
  39. deployTimestamp: res.deploy_timestamp
  40. };
  41. return server_info;
  42. } catch (error) {
  43. console.error('Failed to fetch server info:', error);
  44. throw error;
  45. }
  46. }