From 0eb77147ef63bfe5923d19c0bc15a6531325e66b Mon Sep 17 00:00:00 2001
From: Jason Rasmussen <jason@rasm.me>
Date: Thu, 3 Oct 2024 16:33:43 -0400
Subject: [PATCH] refactor(server): build support env (#13163)

---
 server/src/config.ts                            | 16 ----------------
 server/src/interfaces/config.interface.ts       | 16 ++++++++++++++++
 server/src/repositories/config.repository.ts    | 17 +++++++++++++++++
 server/src/services/server.service.ts           |  3 +--
 .../test/repositories/config.repository.mock.ts |  2 ++
 5 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/server/src/config.ts b/server/src/config.ts
index 7731bb6b6c..4fdf23ecc2 100644
--- a/server/src/config.ts
+++ b/server/src/config.ts
@@ -408,19 +408,3 @@ export const clsConfig: ClsModuleOptions = {
     },
   },
 };
-
-export const getBuildMetadata = () => ({
-  build: process.env.IMMICH_BUILD,
-  buildUrl: process.env.IMMICH_BUILD_URL,
-  buildImage: process.env.IMMICH_BUILD_IMAGE,
-  buildImageUrl: process.env.IMMICH_BUILD_IMAGE_URL,
-  repository: process.env.IMMICH_REPOSITORY,
-  repositoryUrl: process.env.IMMICH_REPOSITORY_URL,
-  sourceRef: process.env.IMMICH_SOURCE_REF,
-  sourceCommit: process.env.IMMICH_SOURCE_COMMIT,
-  sourceUrl: process.env.IMMICH_SOURCE_URL,
-  thirdPartySourceUrl: process.env.IMMICH_THIRD_PARTY_SOURCE_URL,
-  thirdPartyBugFeatureUrl: process.env.IMMICH_THIRD_PARTY_BUG_FEATURE_URL,
-  thirdPartyDocumentationUrl: process.env.IMMICH_THIRD_PARTY_DOCUMENTATION_URL,
-  thirdPartySupportUrl: process.env.IMMICH_THIRD_PARTY_SUPPORT_URL,
-});
diff --git a/server/src/interfaces/config.interface.ts b/server/src/interfaces/config.interface.ts
index cbe1f6fde3..544e63d771 100644
--- a/server/src/interfaces/config.interface.ts
+++ b/server/src/interfaces/config.interface.ts
@@ -9,6 +9,22 @@ export interface EnvData {
   configFile?: string;
   logLevel?: LogLevel;
 
+  buildMetadata: {
+    build?: string;
+    buildUrl?: string;
+    buildImage?: string;
+    buildImageUrl?: string;
+    repository?: string;
+    repositoryUrl?: string;
+    sourceRef?: string;
+    sourceCommit?: string;
+    sourceUrl?: string;
+    thirdPartySourceUrl?: string;
+    thirdPartyBugFeatureUrl?: string;
+    thirdPartyDocumentationUrl?: string;
+    thirdPartySupportUrl?: string;
+  };
+
   database: {
     skipMigrations: boolean;
     vectorExtension: VectorExtension;
diff --git a/server/src/repositories/config.repository.ts b/server/src/repositories/config.repository.ts
index 1369757da6..ec80ed4db4 100644
--- a/server/src/repositories/config.repository.ts
+++ b/server/src/repositories/config.repository.ts
@@ -47,6 +47,23 @@ export class ConfigRepository implements IConfigRepository {
       environment,
       configFile: process.env.IMMICH_CONFIG_FILE,
       logLevel: process.env.IMMICH_LOG_LEVEL as LogLevel,
+
+      buildMetadata: {
+        build: process.env.IMMICH_BUILD,
+        buildUrl: process.env.IMMICH_BUILD_URL,
+        buildImage: process.env.IMMICH_BUILD_IMAGE,
+        buildImageUrl: process.env.IMMICH_BUILD_IMAGE_URL,
+        repository: process.env.IMMICH_REPOSITORY,
+        repositoryUrl: process.env.IMMICH_REPOSITORY_URL,
+        sourceRef: process.env.IMMICH_SOURCE_REF,
+        sourceCommit: process.env.IMMICH_SOURCE_COMMIT,
+        sourceUrl: process.env.IMMICH_SOURCE_URL,
+        thirdPartySourceUrl: process.env.IMMICH_THIRD_PARTY_SOURCE_URL,
+        thirdPartyBugFeatureUrl: process.env.IMMICH_THIRD_PARTY_BUG_FEATURE_URL,
+        thirdPartyDocumentationUrl: process.env.IMMICH_THIRD_PARTY_DOCUMENTATION_URL,
+        thirdPartySupportUrl: process.env.IMMICH_THIRD_PARTY_SUPPORT_URL,
+      },
+
       database: {
         skipMigrations: process.env.DB_SKIP_MIGRATIONS === 'true',
         vectorExtension: getVectorExtension(),
diff --git a/server/src/services/server.service.ts b/server/src/services/server.service.ts
index 08d0c13085..3fc319a2fd 100644
--- a/server/src/services/server.service.ts
+++ b/server/src/services/server.service.ts
@@ -1,5 +1,4 @@
 import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
-import { getBuildMetadata } from 'src/config';
 import { serverVersion } from 'src/constants';
 import { StorageCore } from 'src/cores/storage.core';
 import { OnEvent } from 'src/decorators';
@@ -36,7 +35,7 @@ export class ServerService extends BaseService {
 
   async getAboutInfo(): Promise<ServerAboutResponseDto> {
     const version = `v${serverVersion.toString()}`;
-    const buildMetadata = getBuildMetadata();
+    const { buildMetadata } = this.configRepository.getEnv();
     const buildVersions = await this.serverInfoRepository.getBuildVersions();
     const licensed = await this.systemMetadataRepository.get(SystemMetadataKey.LICENSE);
 
diff --git a/server/test/repositories/config.repository.mock.ts b/server/test/repositories/config.repository.mock.ts
index 39450d4745..786e9adbcc 100644
--- a/server/test/repositories/config.repository.mock.ts
+++ b/server/test/repositories/config.repository.mock.ts
@@ -7,6 +7,8 @@ const envData: EnvData = {
   port: 3001,
   environment: ImmichEnvironment.PRODUCTION,
 
+  buildMetadata: {},
+
   database: {
     skipMigrations: false,
     vectorExtension: DatabaseExtension.VECTORS,