diff --git a/src/UI/Settings/UITabAbout.js b/src/UI/Settings/UITabAbout.js index 8a6631b6..f53a587b 100644 --- a/src/UI/Settings/UITabAbout.js +++ b/src/UI/Settings/UITabAbout.js @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +import { fetchServerInfo } from '../../services/VersionService.js'; + // About export default { id: 'about', @@ -92,24 +94,15 @@ export default { `; }, init: ($el_window) => { - // version - $.ajax({ - url: api_origin + "/version", - type: 'GET', - async: true, - contentType: "application/json", - headers: { - "Authorization": "Bearer " + auth_token - }, - statusCode: { - 401: function () { - logout(); - }, - }, - success: function (res) { - var d = new Date(0); - $el_window.find('.version').html('Version: ' + res.version + ' • ' + 'Server: ' + res.location + ' • ' + 'Deployed: ' + new Date(res.deploy_timestamp)); - } + // server and version infomration + fetchServerInfo(api_origin, auth_token) + .then(res => { + const deployed_date = new Date(res.deployTimestamp).toLocaleString(); + $el_window.find('.version').html(`Version: ${res.version} • Server: ${res.location} • Deployed: ${deployed_date}`); + }) + .catch(error => { + console.error("Failed to fetch server info:", error); + $el_window.find('.version').html("Failed to load version information."); }); $el_window.find('.credits').on('click', function (e) { diff --git a/src/UI/UIWindowLogin.js b/src/UI/UIWindowLogin.js index 6cbb9733..ea3b1e60 100644 --- a/src/UI/UIWindowLogin.js +++ b/src/UI/UIWindowLogin.js @@ -20,6 +20,7 @@ import UIWindow from './UIWindow.js' import UIWindowSignup from './UIWindowSignup.js' import UIWindowRecoverPassword from './UIWindowRecoverPassword.js' +import { fetchServerInfo } from '../services/VersionService.js'; async function UIWindowLogin(options){ options = options ?? {}; @@ -59,6 +60,8 @@ async function UIWindowLogin(options){ h += ``; // password recovery h += `

${i18n('forgot_pass_c2a')}

`; + // server and version info + h += `
`; h += ``; h += ``; // create account link @@ -68,6 +71,16 @@ async function UIWindowLogin(options){ h += ``; } h += ``; + + // server and version infomration + fetchServerInfo(api_origin, auth_token) + .then(res => { + const deployed_date = new Date(res.deployTimestamp).toLocaleString(); + $("#version-placeholder").html(`Version: ${res.version} • Server: ${res.location} • Deployed: ${deployed_date}`); + }) + .catch(() => { + $("#version-placeholder").html("Failed to load version or server information."); + }); const el_window = await UIWindow({ title: null, diff --git a/src/css/style.css b/src/css/style.css index cabcd58a..f466d84b 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -3601,6 +3601,11 @@ label { height: 12px; } +.version#version-placeholder { + margin-top: 10px; + margin-bottom: 0; +} + .version:hover { opacity: 1; } diff --git a/src/services/VersionService.js b/src/services/VersionService.js new file mode 100644 index 00000000..2aadf3bc --- /dev/null +++ b/src/services/VersionService.js @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2024 Puter Technologies Inc. + * + * This file is part of Puter. + * + * Puter is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +let server_info = null; + +export async function fetchServerInfo(api_origin, auth_token) { + if (server_info) return server_info; + + try { + const res = await $.ajax({ + url: api_origin + "/version", + type: 'GET', + contentType: "application/json", + headers: { + "Authorization": "Bearer " + auth_token + }, + statusCode: { + 401: function () { + logout(); + } + } + }); + server_info = { + version: res.version, + location: res.location, + deployTimestamp: res.deploy_timestamp + }; + return server_info; + } catch (error) { + console.error('Failed to fetch server info:', error); + throw error; + } +}