From 7656dc51b59db303a7a75dc225305c018c9138d6 Mon Sep 17 00:00:00 2001 From: Huskydog9988 <39809509+Huskydog9988@users.noreply.github.com> Date: Thu, 29 May 2025 13:27:38 -0400 Subject: [PATCH] feat: allow clients to fetch drop version --- server/nuxt.config.ts | 25 ++++++++++++++++++----- server/server/api/v1/index.get.ts | 4 ++++ server/server/internal/config/sys-conf.ts | 16 ++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/server/nuxt.config.ts b/server/nuxt.config.ts index 96b9415b..bd2ffe2c 100644 --- a/server/nuxt.config.ts +++ b/server/nuxt.config.ts @@ -1,6 +1,20 @@ import tailwindcss from "@tailwindcss/vite"; +import { execSync } from "node:child_process"; -const dropVersion = "v0.3.0"; +// get drop version +const dropVersion = + process.env.BUILD_DROP_VERSION === undefined + ? "v0.3.0-alpha.1" + : process.env.BUILD_DROP_VERSION; +// example nightly: "v0.3.0-nightly.2025.05.28" + +// get git ref or supply during build +const commitHash = + process.env.BUILD_GIT_REF === undefined + ? execSync("git rev-parse --short HEAD").toString().trim() + : process.env.BUILD_GIT_REF; + +console.log(`Building Drop ${dropVersion} #${commitHash}`); // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ @@ -42,16 +56,17 @@ export default defineNuxtConfig({ plugins: [tailwindcss()], }, + runtimeConfig: { + gitRef: commitHash, + dropVersion: dropVersion, + }, + app: { head: { link: [{ rel: "icon", href: "/favicon.ico" }], }, }, - appConfig: { - dropVersion: dropVersion, - }, - routeRules: { "/api/**": { cors: true }, }, diff --git a/server/server/api/v1/index.get.ts b/server/server/api/v1/index.get.ts index 37b2372f..322ba50e 100644 --- a/server/server/api/v1/index.get.ts +++ b/server/server/api/v1/index.get.ts @@ -1,5 +1,9 @@ +import { systemConfig } from "~/server/internal/config/sys-conf"; + export default defineEventHandler((_h3) => { return { appName: "Drop", + version: systemConfig.getDropVersion(), + ref: systemConfig.getGitRef(), }; }); diff --git a/server/server/internal/config/sys-conf.ts b/server/server/internal/config/sys-conf.ts index 560a661d..acf58654 100644 --- a/server/server/internal/config/sys-conf.ts +++ b/server/server/internal/config/sys-conf.ts @@ -1,13 +1,23 @@ class SystemConfig { private libraryFolder = process.env.LIBRARY ?? "./.data/library"; private dataFolder = process.env.DATA ?? "./.data/data"; - private dropVersion = "v0.3.0"; + + private dropVersion; + private gitRef; + private checkForUpdates = process.env.CHECK_FOR_UPDATES !== undefined && process.env.CHECK_FOR_UPDATES.toLocaleLowerCase() === "true" ? true : false; + constructor() { + // get drop version and git ref from nuxt config + const config = useRuntimeConfig(); + this.dropVersion = config.dropVersion; + this.gitRef = config.gitRef; + } + getLibraryFolder() { return this.libraryFolder; } @@ -20,6 +30,10 @@ class SystemConfig { return this.dropVersion; } + getGitRef() { + return this.gitRef; + } + shouldCheckForUpdates() { return this.checkForUpdates; }