mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Converted variables to be runtime.
This commit is contained in:
parent
b6862de2be
commit
5b6292dd11
11 changed files with 46 additions and 36 deletions
|
|
@ -12,11 +12,8 @@ const cloudMode = process.env.CLOUD_MODE;
|
|||
const cloudUrl = process.env.CLOUD_URL;
|
||||
const corsMaxAge = process.env.CORS_MAX_AGE;
|
||||
const defaultLocale = process.env.DEFAULT_LOCALE;
|
||||
const disableLogin = process.env.DISABLE_LOGIN;
|
||||
const disableUI = process.env.DISABLE_UI;
|
||||
const forceSSL = process.env.FORCE_SSL;
|
||||
const frameAncestors = process.env.ALLOWED_FRAME_URLS ?? '';
|
||||
const privateMode = process.env.PRIVATE_MODE;
|
||||
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||
const trackerScriptURL = process.env.TRACKER_SCRIPT_URL;
|
||||
|
||||
|
|
@ -172,13 +169,11 @@ if (cloudMode && cloudUrl) {
|
|||
permanent: false,
|
||||
});
|
||||
|
||||
if (disableLogin) {
|
||||
redirects.push({
|
||||
source: '/login',
|
||||
destination: cloudUrl,
|
||||
permanent: false,
|
||||
});
|
||||
}
|
||||
redirects.push({
|
||||
source: '/login',
|
||||
destination: cloudUrl,
|
||||
permanent: false,
|
||||
});
|
||||
}
|
||||
|
||||
/** @type {import('next').NextConfig} */
|
||||
|
|
@ -190,9 +185,6 @@ export default {
|
|||
cloudUrl,
|
||||
currentVersion: pkg.version,
|
||||
defaultLocale,
|
||||
disableLogin,
|
||||
disableUI,
|
||||
privateMode,
|
||||
},
|
||||
basePath,
|
||||
output: 'standalone',
|
||||
|
|
|
|||
|
|
@ -13,13 +13,14 @@ export function UpdateNotice({ user, config }) {
|
|||
const { latest, checked, hasUpdate, releaseUrl } = useStore();
|
||||
const pathname = usePathname();
|
||||
const [dismissed, setDismissed] = useState(checked);
|
||||
|
||||
const allowUpdate =
|
||||
process.env.NODE_ENV === 'production' &&
|
||||
user?.isAdmin &&
|
||||
!config?.updatesDisabled &&
|
||||
!config?.privateMode &&
|
||||
!pathname.includes('/share/') &&
|
||||
!process.env.cloudMode &&
|
||||
!process.env.privateMode &&
|
||||
!dismissed;
|
||||
|
||||
const updateCheck = useCallback(() => {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export function LanguageSetting() {
|
|||
const [search, setSearch] = useState('');
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { locale, saveLocale } = useLocale();
|
||||
|
||||
const options = search
|
||||
? Object.keys(languages).filter(n => {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -1,11 +1,23 @@
|
|||
'use server';
|
||||
|
||||
export async function getConfig() {
|
||||
export type Config = {
|
||||
faviconUrl: string | undefined;
|
||||
loginDisabled: boolean;
|
||||
privateMode: boolean;
|
||||
telemetryDisabled: boolean;
|
||||
trackerScriptName: string | undefined;
|
||||
uiDisabled: boolean;
|
||||
updatesDisabled: boolean;
|
||||
};
|
||||
|
||||
export async function getConfig(): Promise<Config> {
|
||||
return {
|
||||
faviconUrl: process.env.FAVICON_URL,
|
||||
loginDisabled: !!process.env.DISABLE_LOGIN,
|
||||
privateMode: !!process.env.PRIVATE_MODE,
|
||||
telemetryDisabled: !!process.env.DISABLE_TELEMETRY,
|
||||
trackerScriptName: process.env.TRACKER_SCRIPT_NAME,
|
||||
uiDisabled: !!process.env.DISABLE_UI,
|
||||
updatesDisabled: !!process.env.DISABLE_UPDATES,
|
||||
faviconUrl: process.env.FAVICON_URL,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,25 +2,25 @@ import { CURRENT_VERSION, TELEMETRY_PIXEL } from '@/lib/constants';
|
|||
|
||||
export async function GET() {
|
||||
if (
|
||||
process.env.NODE_ENV !== 'production' &&
|
||||
process.env.DISABLE_TELEMETRY &&
|
||||
process.env.NODE_ENV !== 'production' ||
|
||||
process.env.DISABLE_TELEMETRY ||
|
||||
process.env.PRIVATE_MODE
|
||||
) {
|
||||
const script = `
|
||||
(()=>{const i=document.createElement('img');
|
||||
i.setAttribute('src','${TELEMETRY_PIXEL}?v=${CURRENT_VERSION}');
|
||||
i.setAttribute('style','width:0;height:0;position:absolute;pointer-events:none;');
|
||||
document.body.appendChild(i);})();
|
||||
`;
|
||||
|
||||
return new Response(script.replace(/\s\s+/g, ''), {
|
||||
return new Response('/* telemetry disabled */', {
|
||||
headers: {
|
||||
'content-type': 'text/javascript',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return new Response('/* telemetry disabled */', {
|
||||
const script = `
|
||||
(()=>{const i=document.createElement('img');
|
||||
i.setAttribute('src','${TELEMETRY_PIXEL}?v=${CURRENT_VERSION}');
|
||||
i.setAttribute('style','width:0;height:0;position:absolute;pointer-events:none;');
|
||||
document.body.appendChild(i);})();
|
||||
`;
|
||||
|
||||
return new Response(script.replace(/\s\s+/g, ''), {
|
||||
headers: {
|
||||
'content-type': 'text/javascript',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
'use client';
|
||||
import { useConfig } from '@/components/hooks';
|
||||
import LoginForm from './LoginForm';
|
||||
import styles from './LoginPage.module.css';
|
||||
|
||||
export function LoginPage() {
|
||||
if (process.env.disableLogin) {
|
||||
const config = useConfig();
|
||||
|
||||
if (config?.loginDisabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
'use client';
|
||||
import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useApi } from '@/components/hooks';
|
||||
import { useApi, useConfig } from '@/components/hooks';
|
||||
import { setUser } from '@/store/app';
|
||||
import { removeClientAuthToken } from '@/lib/client';
|
||||
|
||||
export function LogoutPage() {
|
||||
const disabled = !!(process.env.disableLogin || process.env.cloudMode);
|
||||
const config = useConfig();
|
||||
const router = useRouter();
|
||||
const { post } = useApi();
|
||||
const disabled = !!(config?.loginDisabled || process.env.cloudMode);
|
||||
|
||||
useEffect(() => {
|
||||
async function logout() {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ function getHostName(url: string) {
|
|||
export function Favicon({ domain, ...props }) {
|
||||
const config = useConfig();
|
||||
|
||||
if (process.env.privateMode) {
|
||||
if (config?.privateMode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const url = config?.faviconURL || FAVICON_URL;
|
||||
const url = config?.faviconUrl || FAVICON_URL;
|
||||
const hostName = domain ? getHostName(domain) : null;
|
||||
const domainName = GROUPED_DOMAINS[hostName]?.domain || hostName;
|
||||
const src = hostName ? url.replace(/\{\{\s*domain\s*}}/, domainName) : null;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { useEffect } from 'react';
|
||||
import useStore, { setConfig } from '@/store/app';
|
||||
import { getConfig } from '@/app/actions/getConfig';
|
||||
import { getConfig, Config } from '@/app/actions/getConfig';
|
||||
|
||||
export function useConfig() {
|
||||
export function useConfig(): Config {
|
||||
const { config } = useStore();
|
||||
|
||||
async function loadConfig() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export const UPDATES_URL = 'https://api.umami.is/v1/updates';
|
|||
export const TELEMETRY_PIXEL = 'https://i.umami.is/a.png';
|
||||
export const FAVICON_URL = 'https://icons.duckduckgo.com/ip3/{{domain}}.ico';
|
||||
|
||||
export const DEFAULT_LOCALE = process.env.defaultLocale || 'en-US';
|
||||
export const DEFAULT_LOCALE = 'en-US';
|
||||
export const DEFAULT_THEME = 'light';
|
||||
export const DEFAULT_ANIMATION_DURATION = 300;
|
||||
export const DEFAULT_DATE_RANGE = '24hour';
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function getDefaultTheme() {
|
|||
}
|
||||
|
||||
const initialState = {
|
||||
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
|
||||
locale: getItem(LOCALE_CONFIG) || process.env.defaultLocale || DEFAULT_LOCALE,
|
||||
theme: getItem(THEME_CONFIG) || getDefaultTheme() || DEFAULT_THEME,
|
||||
timezone: getItem(TIMEZONE_CONFIG) || getTimezone(),
|
||||
dateRange: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue