🐛 fix(subscribe): Extract Domain
This commit is contained in:
parent
a451f44c81
commit
40d61a9843
@ -6,10 +6,7 @@ export default async function DashboardLayout({ children }: { children: React.Re
|
|||||||
return (
|
return (
|
||||||
<SidebarProvider className='container'>
|
<SidebarProvider className='container'>
|
||||||
<SidebarLeft className='sticky top-[84px] hidden w-52 border-r-0 bg-transparent lg:flex' />
|
<SidebarLeft className='sticky top-[84px] hidden w-52 border-r-0 bg-transparent lg:flex' />
|
||||||
<SidebarInset className='relative p-4'>
|
<SidebarInset className='relative p-4'>{children}</SidebarInset>
|
||||||
{/* <Header /> */}
|
|
||||||
{children}
|
|
||||||
</SidebarInset>
|
|
||||||
<SidebarRight className='sticky top-[84px] hidden w-52 border-r-0 bg-transparent 2xl:flex' />
|
<SidebarRight className='sticky top-[84px] hidden w-52 border-r-0 bg-transparent 2xl:flex' />
|
||||||
</SidebarProvider>
|
</SidebarProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -64,6 +64,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data);
|
config = await getGlobalConfig({ skipErrorHandler: true }).then((res) => res.data.data);
|
||||||
|
console.log(config);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
/* empty */
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,10 @@
|
|||||||
|
|
||||||
import useGlobalStore from '@/config/use-global';
|
import useGlobalStore from '@/config/use-global';
|
||||||
import { buttonVariants } from '@shadcn/ui/button';
|
import { buttonVariants } from '@shadcn/ui/button';
|
||||||
|
import { useTranslations } from 'next-intl';
|
||||||
import Image from 'next/legacy/image';
|
import Image from 'next/legacy/image';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import LanguageSwitch from './language-switch';
|
import LanguageSwitch from './language-switch';
|
||||||
// import { MobileSidebar } from './mobile-sidebar';
|
|
||||||
import { useTranslations } from 'next-intl';
|
|
||||||
import ThemeSwitch from './theme-switch';
|
import ThemeSwitch from './theme-switch';
|
||||||
import { UserNav } from './user-nav';
|
import { UserNav } from './user-nav';
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ export const useGlobalStore = create<GlobalStore>((set, get) => ({
|
|||||||
const { pan_domain, subscribe_domain, subscribe_path } = get().common.subscribe || {};
|
const { pan_domain, subscribe_domain, subscribe_path } = get().common.subscribe || {};
|
||||||
const domains = subscribe_domain
|
const domains = subscribe_domain
|
||||||
? subscribe_domain.split('\n')
|
? subscribe_domain.split('\n')
|
||||||
: [extractDomain(NEXT_PUBLIC_API_URL || NEXT_PUBLIC_SITE_URL || '')];
|
: [extractDomain(NEXT_PUBLIC_API_URL || NEXT_PUBLIC_SITE_URL || '', pan_domain)];
|
||||||
|
|
||||||
return domains.map((domain) => {
|
return domains.map((domain) => {
|
||||||
const enc_type = type ? Base64.stringify(UTF8.parse(type)) : '';
|
const enc_type = type ? Base64.stringify(UTF8.parse(type)) : '';
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export * from './unit-conversions';
|
|||||||
export const isBrowser = () => typeof window !== 'undefined';
|
export const isBrowser = () => typeof window !== 'undefined';
|
||||||
|
|
||||||
export function getNextResetDate(startDate: Date | number) {
|
export function getNextResetDate(startDate: Date | number) {
|
||||||
let time = new Date(startDate);
|
const time = new Date(startDate);
|
||||||
const resetDay = time.getDate();
|
const resetDay = time.getDate();
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
if (isNaN(time.getTime())) {
|
if (isNaN(time.getTime())) {
|
||||||
@ -27,21 +27,23 @@ export function getNextResetDate(startDate: Date | number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractDomain(url: string): string | null {
|
/**
|
||||||
|
* Extracts the full domain or root domain from a URL.
|
||||||
|
*
|
||||||
|
* @param url - The URL to extract the domain from.
|
||||||
|
* @param extractRoot - If true, extracts the root domain (e.g., example.com). If false, extracts the full domain (e.g., sub.example.com).
|
||||||
|
* @returns The extracted domain or root domain, or null if the URL is invalid.
|
||||||
|
*/
|
||||||
|
export function extractDomain(url: string, extractRoot = true): string | null {
|
||||||
try {
|
try {
|
||||||
const hostname = new URL(url).hostname;
|
const { hostname } = new URL(url);
|
||||||
|
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)) {
|
||||||
if (hostname.match(/^\d{1,3}(\.\d{1,3}){3}$/)) {
|
|
||||||
return hostname;
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
const domainParts = hostname.split('.').filter(Boolean);
|
const domainParts = hostname.split('.').filter(Boolean);
|
||||||
|
if (extractRoot && domainParts.length > 2) {
|
||||||
if (domainParts.length >= 2) {
|
return domainParts.slice(-2).join('.');
|
||||||
const topLevelDomain = domainParts.slice(-2).join('.');
|
|
||||||
return topLevelDomain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hostname;
|
return hostname;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Invalid URL:', error);
|
console.error('Invalid URL:', error);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user