mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Merge branch 'dev' into jajaja
# Conflicts: # next.config.ts # src/app/(main)/settings/preferences/LanguageSetting.tsx # src/components/hooks/useConfig.ts
This commit is contained in:
commit
b552868e0a
14 changed files with 55 additions and 44 deletions
|
|
@ -13,12 +13,8 @@ const cloudMode = process.env.CLOUD_MODE;
|
||||||
const cloudUrl = process.env.CLOUD_URL;
|
const cloudUrl = process.env.CLOUD_URL;
|
||||||
const corsMaxAge = process.env.CORS_MAX_AGE;
|
const corsMaxAge = process.env.CORS_MAX_AGE;
|
||||||
const defaultLocale = process.env.DEFAULT_LOCALE;
|
const defaultLocale = process.env.DEFAULT_LOCALE;
|
||||||
const disableLogin = process.env.DISABLE_LOGIN;
|
|
||||||
const disableUI = process.env.DISABLE_UI;
|
|
||||||
const faviconURL = process.env.FAVICON_URL;
|
|
||||||
const forceSSL = process.env.FORCE_SSL;
|
const forceSSL = process.env.FORCE_SSL;
|
||||||
const frameAncestors = process.env.ALLOWED_FRAME_URLS ?? '';
|
const frameAncestors = process.env.ALLOWED_FRAME_URLS ?? '';
|
||||||
const privateMode = process.env.PRIVATE_MODE;
|
|
||||||
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
const trackerScriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||||
const trackerScriptURL = process.env.TRACKER_SCRIPT_URL;
|
const trackerScriptURL = process.env.TRACKER_SCRIPT_URL;
|
||||||
|
|
||||||
|
|
@ -168,13 +164,11 @@ if (cloudMode && cloudUrl) {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (disableLogin) {
|
redirects.push({
|
||||||
redirects.push({
|
source: '/login',
|
||||||
source: '/login',
|
destination: cloudUrl,
|
||||||
destination: cloudUrl,
|
permanent: false,
|
||||||
permanent: false,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
|
|
@ -186,10 +180,6 @@ export default {
|
||||||
cloudUrl,
|
cloudUrl,
|
||||||
currentVersion: pkg.version,
|
currentVersion: pkg.version,
|
||||||
defaultLocale,
|
defaultLocale,
|
||||||
disableLogin,
|
|
||||||
disableUI,
|
|
||||||
faviconURL,
|
|
||||||
privateMode,
|
|
||||||
},
|
},
|
||||||
basePath,
|
basePath,
|
||||||
output: 'standalone',
|
output: 'standalone',
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,6 @@ export function App({ children }) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.uiDisabled) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid height="100vh" width="100%" columns="auto 1fr" backgroundColor="2">
|
<Grid height="100vh" width="100%" columns="auto 1fr" backgroundColor="2">
|
||||||
<Column>
|
<Column>
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,14 @@ export function UpdateNotice({ user, config }) {
|
||||||
const { latest, checked, hasUpdate, releaseUrl } = useVersion();
|
const { latest, checked, hasUpdate, releaseUrl } = useVersion();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [dismissed, setDismissed] = useState(checked);
|
const [dismissed, setDismissed] = useState(checked);
|
||||||
|
|
||||||
const allowUpdate =
|
const allowUpdate =
|
||||||
process.env.NODE_ENV === 'production' &&
|
process.env.NODE_ENV === 'production' &&
|
||||||
user?.isAdmin &&
|
user?.isAdmin &&
|
||||||
!config?.updatesDisabled &&
|
!config?.updatesDisabled &&
|
||||||
|
!config?.privateMode &&
|
||||||
!pathname.includes('/share/') &&
|
!pathname.includes('/share/') &&
|
||||||
!process.env.cloudMode &&
|
!process.env.cloudMode &&
|
||||||
!process.env.privateMode &&
|
|
||||||
!dismissed;
|
!dismissed;
|
||||||
|
|
||||||
const updateCheck = useCallback(() => {
|
const updateCheck = useCallback(() => {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
export async function getConfig() {
|
export type Config = {
|
||||||
|
faviconUrl: string | undefined;
|
||||||
|
privateMode: boolean;
|
||||||
|
telemetryDisabled: boolean;
|
||||||
|
trackerScriptName: string | undefined;
|
||||||
|
updatesDisabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getConfig(): Promise<Config> {
|
||||||
return {
|
return {
|
||||||
|
faviconUrl: process.env.FAVICON_URL,
|
||||||
|
privateMode: !!process.env.PRIVATE_MODE,
|
||||||
telemetryDisabled: !!process.env.DISABLE_TELEMETRY,
|
telemetryDisabled: !!process.env.DISABLE_TELEMETRY,
|
||||||
trackerScriptName: process.env.TRACKER_SCRIPT_NAME,
|
trackerScriptName: process.env.TRACKER_SCRIPT_NAME,
|
||||||
uiDisabled: !!process.env.DISABLE_UI,
|
|
||||||
updatesDisabled: !!process.env.DISABLE_UPDATES,
|
updatesDisabled: !!process.env.DISABLE_UPDATES,
|
||||||
loginDisabled: !!process.env.DISABLE_LOGIN,
|
loginDisabled: !!process.env.DISABLE_LOGIN,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,25 @@ import { CURRENT_VERSION, TELEMETRY_PIXEL } from '@/lib/constants';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
if (
|
if (
|
||||||
process.env.NODE_ENV !== 'production' &&
|
process.env.NODE_ENV !== 'production' ||
|
||||||
process.env.DISABLE_TELEMETRY &&
|
process.env.DISABLE_TELEMETRY ||
|
||||||
process.env.PRIVATE_MODE
|
process.env.PRIVATE_MODE
|
||||||
) {
|
) {
|
||||||
const script = `
|
return new Response('/* telemetry disabled */', {
|
||||||
(()=>{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: {
|
headers: {
|
||||||
'content-type': 'text/javascript',
|
'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: {
|
headers: {
|
||||||
'content-type': 'text/javascript',
|
'content-type': 'text/javascript',
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,14 @@ import '@/styles/global.css';
|
||||||
import '@/styles/variables.css';
|
import '@/styles/variables.css';
|
||||||
|
|
||||||
export default function ({ children }) {
|
export default function ({ children }) {
|
||||||
|
if (process.env.DISABLE_UI) {
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<body></body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,6 @@ import { Column } from '@umami/react-zen';
|
||||||
import { LoginForm } from './LoginForm';
|
import { LoginForm } from './LoginForm';
|
||||||
|
|
||||||
export function LoginPage() {
|
export function LoginPage() {
|
||||||
if (process.env.disableLogin) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column justifyContent="center" alignItems="center" height="100vh" backgroundColor="2">
|
<Column justifyContent="center" alignItems="center" height="100vh" backgroundColor="2">
|
||||||
<LoginForm />
|
<LoginForm />
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@ import { Metadata } from 'next';
|
||||||
import { LoginPage } from './LoginPage';
|
import { LoginPage } from './LoginPage';
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
|
if (process.env.DISABLE_LOGIN) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return <LoginPage />;
|
return <LoginPage />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ import { setUser } from '@/store/app';
|
||||||
import { removeClientAuthToken } from '@/lib/client';
|
import { removeClientAuthToken } from '@/lib/client';
|
||||||
|
|
||||||
export function LogoutPage() {
|
export function LogoutPage() {
|
||||||
const disabled = !!(process.env.disableLogin || process.env.cloudMode);
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { post } = useApi();
|
const { post } = useApi();
|
||||||
|
const disabled = process.env.cloudMode;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function logout() {
|
async function logout() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@ import { LogoutPage } from './LogoutPage';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
|
if (process.env.DISABLE_LOGIN) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return <LogoutPage />;
|
return <LogoutPage />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { useConfig } from '@/components/hooks';
|
||||||
import { FAVICON_URL, GROUPED_DOMAINS } from '@/lib/constants';
|
import { FAVICON_URL, GROUPED_DOMAINS } from '@/lib/constants';
|
||||||
|
|
||||||
function getHostName(url: string) {
|
function getHostName(url: string) {
|
||||||
|
|
@ -6,11 +7,13 @@ function getHostName(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Favicon({ domain, ...props }) {
|
export function Favicon({ domain, ...props }) {
|
||||||
if (process.env.privateMode) {
|
const config = useConfig();
|
||||||
|
|
||||||
|
if (config?.privateMode) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = process.env.faviconURL || FAVICON_URL;
|
const url = config?.faviconUrl || FAVICON_URL;
|
||||||
const hostName = domain ? getHostName(domain) : null;
|
const hostName = domain ? getHostName(domain) : null;
|
||||||
const domainName = GROUPED_DOMAINS[hostName]?.domain || hostName;
|
const domainName = GROUPED_DOMAINS[hostName]?.domain || hostName;
|
||||||
const src = hostName ? url.replace(/\{\{\s*domain\s*}}/, domainName) : null;
|
const src = hostName ? url.replace(/\{\{\s*domain\s*}}/, domainName) : null;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useApp, setConfig } from '@/store/app';
|
import { useApp, 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 } = useApp();
|
const { config } = useApp();
|
||||||
|
|
||||||
async function loadConfig() {
|
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 TELEMETRY_PIXEL = 'https://i.umami.is/a.png';
|
||||||
export const FAVICON_URL = 'https://icons.duckduckgo.com/ip3/{{domain}}.ico';
|
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_THEME = 'light';
|
||||||
export const DEFAULT_ANIMATION_DURATION = 300;
|
export const DEFAULT_ANIMATION_DURATION = 300;
|
||||||
export const DEFAULT_DATE_RANGE_VALUE = '24hour';
|
export const DEFAULT_DATE_RANGE_VALUE = '24hour';
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ function getDefaultTheme() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
|
locale: getItem(LOCALE_CONFIG) || process.env.defaultLocale || DEFAULT_LOCALE,
|
||||||
theme: getItem(THEME_CONFIG) || getDefaultTheme() || DEFAULT_THEME,
|
theme: getItem(THEME_CONFIG) || getDefaultTheme() || DEFAULT_THEME,
|
||||||
timezone: getItem(TIMEZONE_CONFIG) || getTimezone(),
|
timezone: getItem(TIMEZONE_CONFIG) || getTimezone(),
|
||||||
dateRangeValue: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE,
|
dateRangeValue: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue