add env variable (#513)

This commit is contained in:
Philip Okugbe
2024-11-28 18:48:25 +00:00
committed by GitHub
parent 8349d8271c
commit d97baf5824
7 changed files with 23 additions and 6 deletions

View File

@ -40,3 +40,5 @@ SMTP_IGNORETLS=false
# Postmark driver config # Postmark driver config
POSTMARK_TOKEN= POSTMARK_TOKEN=
# for custom drawio server
DRAWIO_URL=

View File

@ -3,7 +3,7 @@ import { ActionIcon, Card, Image, Modal, Text, useComputedColorScheme } from '@m
import { useRef, useState } from 'react'; import { useRef, useState } from 'react';
import { uploadFile } from '@/features/page/services/page-service.ts'; import { uploadFile } from '@/features/page/services/page-service.ts';
import { useDisclosure } from '@mantine/hooks'; import { useDisclosure } from '@mantine/hooks';
import { getFileUrl } from '@/lib/config.ts'; import { getDrawioUrl, getFileUrl } from '@/lib/config.ts';
import { import {
DrawIoEmbed, DrawIoEmbed,
DrawIoEmbedRef, DrawIoEmbedRef,
@ -87,6 +87,7 @@ export default function DrawioView(props: NodeViewProps) {
<DrawIoEmbed <DrawIoEmbed
ref={drawioRef} ref={drawioRef}
xml={initialXML} xml={initialXML}
baseUrl={getDrawioUrl()}
urlParameters={{ urlParameters={{
ui: computedColorScheme === 'light' ? 'kennedy' : 'dark', ui: computedColorScheme === 'light' ? 'kennedy' : 'dark',
spin: true, spin: true,

View File

@ -57,6 +57,14 @@ export function getFileUrl(src: string) {
} }
export function getFileUploadSizeLimit() { export function getFileUploadSizeLimit() {
const limit = window.CONFIG?.FILE_UPLOAD_SIZE_LIMIT || process?.env.FILE_UPLOAD_SIZE_LIMIT || '50mb'; const limit =getConfigValue("FILE_UPLOAD_SIZE_LIMIT", "50mb");
return bytes(limit); return bytes(limit);
} }
export function getDrawioUrl() {
return getConfigValue("DRAWIO_URL", "https://embed.diagrams.net");
}
function getConfigValue(key: string, defaultValue: string = undefined) {
return window.CONFIG?.[key] || process?.env?.[key] || defaultValue;
}

View File

@ -5,13 +5,14 @@ import * as path from "path";
export const envPath = path.resolve(process.cwd(), "..", ".."); export const envPath = path.resolve(process.cwd(), "..", "..");
export default defineConfig(({ mode }) => { export default defineConfig(({ mode }) => {
const { APP_URL, FILE_UPLOAD_SIZE_LIMIT } = loadEnv(mode, envPath, ""); const { APP_URL, FILE_UPLOAD_SIZE_LIMIT, DRAWIO_URL } = loadEnv(mode, envPath, "");
return { return {
define: { define: {
"process.env": { "process.env": {
APP_URL, APP_URL,
FILE_UPLOAD_SIZE_LIMIT FILE_UPLOAD_SIZE_LIMIT,
DRAWIO_URL
}, },
'APP_VERSION': JSON.stringify(process.env.npm_package_version), 'APP_VERSION': JSON.stringify(process.env.npm_package_version),
}, },

View File

@ -122,6 +122,10 @@ export class EnvironmentService {
return this.configService.get<string>('POSTMARK_TOKEN'); return this.configService.get<string>('POSTMARK_TOKEN');
} }
getDrawioUrl(): string {
return this.configService.get<string>('DRAWIO_URL');
}
isCloud(): boolean { isCloud(): boolean {
const cloudConfig = this.configService const cloudConfig = this.configService
.get<string>('CLOUD', 'false') .get<string>('CLOUD', 'false')

View File

@ -33,7 +33,8 @@ export class StaticModule implements OnModuleInit {
ENV: this.environmentService.getNodeEnv(), ENV: this.environmentService.getNodeEnv(),
APP_URL: this.environmentService.getAppUrl(), APP_URL: this.environmentService.getAppUrl(),
IS_CLOUD: this.environmentService.isCloud(), IS_CLOUD: this.environmentService.isCloud(),
FILE_UPLOAD_SIZE_LIMIT: this.environmentService.getFileUploadSizeLimit() FILE_UPLOAD_SIZE_LIMIT: this.environmentService.getFileUploadSizeLimit(),
DRAWIO_URL: this.environmentService.getDrawioUrl()
}; };
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`; const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;