Migrate away from system version file to fetch

This commit is contained in:
Michael Green
2024-10-02 12:25:08 +10:00
parent 4075976ad8
commit 32f6a86dc9
3 changed files with 138 additions and 70 deletions

View File

@@ -72,10 +72,50 @@ namespace gaseous_server.Controllers
[MapToApiVersion("1.1")]
[HttpGet]
[Route("Version")]
[ProducesResponseType(StatusCodes.Status200OK)]
public Version GetSystemVersion()
[ProducesResponseType(typeof(Dictionary<string, object>), StatusCodes.Status200OK)]
public ActionResult GetSystemVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version;
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
// get age ratings dictionary
Dictionary<int, string> ClassificationBoardsStrings = new Dictionary<int, string>();
foreach (IGDB.Models.AgeRatingCategory ageRatingCategory in Enum.GetValues(typeof(IGDB.Models.AgeRatingCategory)))
{
ClassificationBoardsStrings.Add((int)ageRatingCategory, ageRatingCategory.ToString());
}
Dictionary<int, string> AgeRatingsStrings = new Dictionary<int, string>();
foreach (IGDB.Models.AgeRatingTitle ageRatingTitle in Enum.GetValues(typeof(IGDB.Models.AgeRatingTitle)))
{
AgeRatingsStrings.Add((int)ageRatingTitle, ageRatingTitle.ToString());
}
Dictionary<string, object> retVal = new Dictionary<string, object>
{
{
"AppVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString()
},
{
"DBSchemaVersion", db.GetDatabaseSchemaVersion().ToString()
},
{
"FirstRunStatus", Config.ReadSetting<string>("FirstRunStatus", "0")
},
{
"AgeRatingBoardsStrings", ClassificationBoardsStrings
},
{
"AgeRatingStrings", AgeRatingsStrings
},
{
"AgeRatingGroups", AgeGroups.AgeGroupingsFlat
},
{
"emulatorDebugMode", Config.ReadSetting<string>("emulatorDebugMode", false.ToString()).ToLower()
}
};
return Ok(retVal);
}
[MapToApiVersion("1.0")]

View File

@@ -3,7 +3,11 @@
<head>
<meta charset="utf-8" />
<script src="/api/v1.1/System/VersionFile"></script>
<script type="text/javascript" src="/scripts/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.lazy.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.lazy.plugins.min.js"></script>
<script type="text/javascript" src="/scripts/moment-with-locales.min.js"></script>
<script type="text/javascript" src="/scripts/select2.min.js"></script>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
@@ -21,11 +25,6 @@
];
let scriptLinks = [
"/scripts/jquery-3.6.0.min.js",
"/scripts/jquery.lazy.min.js",
"/scripts/jquery.lazy.plugins.min.js",
"/scripts/moment-with-locales.min.js",
"/scripts/select2.min.js",
"/scripts/filterformating.js",
"/scripts/gamesformating.js",
"/scripts/main.js",
@@ -60,31 +59,21 @@
<div id="content"></div>
<script type="text/javascript">
// Gaseous Games - Main Application Script
let APIVersion = "v1.1";
// start the application
let AppVersion = "0.0.0";
let DBSchemaVersion = "1000";
let FirstRunStatus = "0";
let AgeRatingBoardStrings = {};
let AgeRatingStrings = {};
let AgeRatingGroups = {};
let emulatorDebugMode = "false";
let backgroundImageHandler = undefined;
async function loadScriptsAndStyles() {
// update script links
for (let i = 0; i < scriptLinks.length; i++) {
let newScript = document.createElement('script');
newScript.src = scriptLinks[i] + '?v=' + AppVersion;
newScript.type = "text/javascript";
newScript.async = false;
head.appendChild(newScript);
}
// update stylesheet links
for (let i = 0; i < styleSheets.length; i++) {
let newLink = document.createElement('link');
newLink.rel = "stylesheet";
newLink.href = styleSheets[i] + '?v=' + AppVersion;
newLink.type = "text/css";
head.appendChild(newLink);
}
}
async function LoadPageContent(page, targetDiv) {
if (targetDiv == undefined || targetDiv == null || targetDiv == '') {
targetDiv = 'content';
@@ -107,49 +96,88 @@
}
async function startApp() {
await loadScriptsAndStyles();
// load /api/v1.1/System/Version
await fetch('/api/v1.1/System/Version')
.then(async response => {
if (response.ok) {
// get version information
let versionFile = await response.json();
AppVersion = versionFile.AppVersion;
DBSchemaVersion = versionFile.DBSchemaVersion;
FirstRunStatus = versionFile.FirstRunStatus;
AgeRatingBoardStrings = versionFile.AgeRatingBoardStrings;
AgeRatingStrings = versionFile.AgeRatingStrings;
AgeRatingGroups = versionFile.AgeRatingGroups;
emulatorDebugMode = versionFile.EmulatorDebugMode;
console.log("Starting Gaseous Games");
console.log("App Version: " + AppVersion);
console.log("First Run Status: " + FirstRunStatus);
switch (FirstRunStatus) {
case 0:
case "0":
// first run - load first run wizard
await LoadPageContent('first', 'content');
break;
// load scripts and style files
// update script links
for (let i = 0; i < scriptLinks.length; i++) {
let newScript = document.createElement('script');
newScript.src = scriptLinks[i] + '?v=' + AppVersion;
newScript.type = "text/javascript";
newScript.async = false;
default:
// first run - load login page or redirect if user already logged in
head.appendChild(newScript);
}
await fetch('/api/v1.1/Account/Profile/Basic')
.then(async response => {
if (response.ok) {
// user is signed in - start setting up the application
console.log("User is logged in");
userProfile = await response.json();
// update stylesheet links
for (let i = 0; i < styleSheets.length; i++) {
let newLink = document.createElement('link');
newLink.rel = "stylesheet";
newLink.href = styleSheets[i] + '?v=' + AppVersion;
newLink.type = "text/css";
// load page banner
await LoadPageContent('banner', 'banner_target');
head.appendChild(newLink);
}
// load page content
let pageSelection = getQueryString('page', 'string');
// start the application
console.log("Starting Gaseous");
console.log("App Version: " + AppVersion);
console.log("First Run Status: " + FirstRunStatus);
switch (FirstRunStatus) {
case 0:
case "0":
// first run - load first run wizard
await LoadPageContent('first', 'content');
break;
if (!pageSelection) {
pageSelection = GetPreference("DefaultHomePage", 'home');
}
await LoadPageContent(pageSelection, 'content');
} else {
// user is not signed in - load login page
await LoadPageContent('login');
}
})
.catch(async (error) => {
console.log(error);
await LoadPageContent('login');
});
break;
}
default:
// first run - load login page or redirect if user already logged in
await fetch('/api/v1.1/Account/Profile/Basic')
.then(async response => {
if (response.ok) {
// user is signed in - start setting up the application
console.log("User is logged in");
userProfile = await response.json();
// load page banner
await LoadPageContent('banner', 'banner_target');
// load page content
let pageSelection = getQueryString('page', 'string');
if (!pageSelection) {
pageSelection = GetPreference("DefaultHomePage", 'home');
}
await LoadPageContent(pageSelection, 'content');
} else {
// user is not signed in - load login page
await LoadPageContent('login');
}
})
.catch(async (error) => {
console.log(error);
await LoadPageContent('login');
});
break;
}
}
})
.catch(async (error) => {
console.log(error);
});
}
window.document.addEventListener('DOMContentLoaded', startApp);

View File

@@ -1,6 +1,6 @@
function getSystemSettings() {
ajaxCall(
'/api/v1/System/Settings/System',
'/api/v1.1/System/Settings/System',
'GET',
function (result) {
console.log(result);
@@ -66,7 +66,7 @@ function setSystemSettings() {
console.log(model);
ajaxCall(
'/api/v1/System/Settings/System',
'/api/v1.1/System/Settings/System',
'POST',
function (result) {
getSystemSettings();