用户组增加权限控制

This commit is contained in:
mtvpls
2026-04-22 16:22:17 +08:00
parent 2734de0c85
commit 0916e4ff08
61 changed files with 617 additions and 165 deletions
+33 -10
View File
@@ -1,11 +1,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Metadata, Viewport } from 'next';
import { cookies } from 'next/headers';
import { Inter } from 'next/font/google';
import './globals.css';
import { getConfig } from '@/lib/config';
import { parseAuthInfo } from '@/lib/auth';
import { getUserFeatureAccess } from '@/lib/permissions';
import { listEnabledSourceScripts } from '@/lib/source-script';
import { StartupCacheCleanup } from '../components/DanmakuCacheCleanup';
@@ -92,18 +95,27 @@ export default async function RootLayout({
let aiDefaultMessageNoVideo = '';
let aiDefaultMessageWithVideo = '';
let enableMovieRequest = true;
let liveEnabled = true;
let webLiveEnabled = false;
let customAdFilterVersion = 0;
let tuneHubEnabled = false;
let musicFeatureEnabled = false;
let suwayomiEnabled = false;
let musicProxyEnabled = true;
let advancedRecommendationEnabled = false;
let userFeatureAccess =
storageType === 'localstorage'
? await getUserFeatureAccess(process.env.USERNAME || 'localstorage-owner')
: await getUserFeatureAccess(null);
let customCategories = [] as {
name: string;
type: 'movie' | 'tv';
query: string;
}[];
if (storageType !== 'localstorage') {
const cookieStore = await cookies();
const authInfo = parseAuthInfo(cookieStore.get('auth')?.value);
userFeatureAccess = await getUserFeatureAccess(authInfo?.username);
const config = await getConfig();
siteName = config.SiteConfig.SiteName;
announcement = config.SiteConfig.Announcement;
@@ -149,11 +161,12 @@ export default async function RootLayout({
// 求片功能配置
enableMovieRequest = config.SiteConfig.EnableMovieRequest ?? true;
// 网络直播功能配置
liveEnabled = (config.LiveConfig || []).some((source) => !source.disabled);
webLiveEnabled = config.WebLiveEnabled ?? false;
// 自定义去广告代码版本号
customAdFilterVersion = config.SiteConfig?.CustomAdFilterVersion || 0;
// 音乐功能配置
tuneHubEnabled = config.MusicConfig?.Enabled || false;
musicFeatureEnabled = config.MusicConfig?.Enabled || false;
musicProxyEnabled = config.MusicConfig?.ProxyEnabled ?? true;
// 漫画功能配置
suwayomiEnabled = !!(
@@ -204,10 +217,13 @@ export default async function RootLayout({
ENABLE_TVBOX_SUBSCRIBE: process.env.ENABLE_TVBOX_SUBSCRIBE === 'true',
ENABLE_OFFLINE_DOWNLOAD: process.env.NEXT_PUBLIC_ENABLE_OFFLINE_DOWNLOAD === 'true',
VOICE_CHAT_STRATEGY: process.env.NEXT_PUBLIC_VOICE_CHAT_STRATEGY || 'webrtc-fallback',
OPENLIST_ENABLED: openListEnabled,
EMBY_ENABLED: embyEnabled,
XIAOYA_ENABLED: xiaoyaEnabled,
PRIVATE_LIBRARY_ENABLED: openListEnabled || embyEnabled || xiaoyaEnabled,
OPENLIST_ENABLED: openListEnabled && userFeatureAccess.private_library,
EMBY_ENABLED: embyEnabled && userFeatureAccess.emby,
XIAOYA_ENABLED: xiaoyaEnabled && userFeatureAccess.xiaoya,
PRIVATE_LIBRARY_ENABLED:
(openListEnabled && userFeatureAccess.private_library) ||
(embyEnabled && userFeatureAccess.emby) ||
(xiaoyaEnabled && userFeatureAccess.xiaoya),
LOGIN_BACKGROUND_IMAGE: loginBackgroundImage,
REGISTER_BACKGROUND_IMAGE: registerBackgroundImage,
PROGRESS_THUMB_TYPE: progressThumbType,
@@ -221,7 +237,7 @@ export default async function RootLayout({
ENABLE_OIDC_LOGIN: enableOIDCLogin,
ENABLE_OIDC_REGISTRATION: enableOIDCRegistration,
OIDC_BUTTON_TEXT: oidcButtonText,
AI_ENABLED: aiEnabled,
AI_ENABLED: aiEnabled && userFeatureAccess.ai_ask,
AI_ENABLE_HOMEPAGE_ENTRY: aiEnableHomepageEntry,
AI_ENABLE_VIDEOCARD_ENTRY: aiEnableVideoCardEntry,
AI_ENABLE_PLAYPAGE_ENTRY: aiEnablePlayPageEntry,
@@ -231,12 +247,19 @@ export default async function RootLayout({
AI_DEFAULT_MESSAGE_NO_VIDEO: aiDefaultMessageNoVideo,
AI_DEFAULT_MESSAGE_WITH_VIDEO: aiDefaultMessageWithVideo,
ENABLE_MOVIE_REQUEST: enableMovieRequest,
WEB_LIVE_ENABLED: webLiveEnabled,
LIVE_ENABLED: liveEnabled && userFeatureAccess.live,
WEB_LIVE_ENABLED: webLiveEnabled && userFeatureAccess.web_live,
ADVANCED_RECOMMENDATION_ENABLED: advancedRecommendationEnabled,
CUSTOM_AD_FILTER_VERSION: customAdFilterVersion,
MUSIC_ENABLED: tuneHubEnabled,
MUSIC_ENABLED: musicFeatureEnabled && userFeatureAccess.music,
MUSIC_PROXY_ENABLED: musicProxyEnabled,
SUWAYOMI_ENABLED: suwayomiEnabled,
SUWAYOMI_ENABLED: suwayomiEnabled && userFeatureAccess.manga,
NETDISK_SEARCH_ENABLED: userFeatureAccess.netdisk_search,
MAGNET_SEARCH_ENABLED: userFeatureAccess.magnet_search,
MAGNET_SAVE_PRIVATE_LIBRARY_ENABLED:
userFeatureAccess.magnet_save_private_library,
NETDISK_TRANSFER_ENABLED: userFeatureAccess.netdisk_transfer,
NETDISK_TEMP_PLAY_ENABLED: userFeatureAccess.netdisk_temp_play,
FESTIVE_EFFECT_ENABLED:
process.env.FESTIVE_EFFECT_ENABLED === 'true',
};