mirror of
https://gh-proxy.org/https://github.com/klinsmaya/sub2api.git
synced 2026-11-09 23:56:58 +08:00
28 lines
826 B
TypeScript
28 lines
826 B
TypeScript
export const ADMIN_UI_REQUEST_HEADER = 'X-Admin-UI-Request'
|
|
|
|
function isAdminPath(path: string): boolean {
|
|
return (
|
|
path === '/admin' ||
|
|
path.startsWith('/admin/') ||
|
|
path === '/api/v1/admin' ||
|
|
path.startsWith('/api/v1/admin/')
|
|
)
|
|
}
|
|
|
|
function requestPath(rawURL: string): string {
|
|
const value = rawURL.trim()
|
|
if (!value) return ''
|
|
try {
|
|
const origin = typeof window !== 'undefined' ? window.location.origin : 'http://localhost'
|
|
return new URL(value, origin).pathname
|
|
} catch {
|
|
return value.split(/[?#]/, 1)[0]
|
|
}
|
|
}
|
|
|
|
export function shouldMarkAdminUIRequest(requestURL: string, pagePath?: string): boolean {
|
|
const currentPath =
|
|
pagePath ?? (typeof window !== 'undefined' ? window.location.pathname : '')
|
|
return isAdminPath(requestPath(requestURL)) || isAdminPath(currentPath)
|
|
}
|