feat: make get config sync

This commit is contained in:
shinya
2025-07-13 20:04:30 +08:00
parent 6f4678c32a
commit c325cfaa84
14 changed files with 28 additions and 25 deletions

View File

@@ -26,7 +26,7 @@ export async function GET(request: NextRequest) {
const username = authInfo.username;
try {
const config = getConfig();
const config = await getConfig();
const result: AdminConfigResult = {
Role: 'owner',
Config: config,

View File

@@ -53,7 +53,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: '参数格式错误' }, { status: 400 });
}
const adminConfig = getConfig();
const adminConfig = await getConfig();
const storage = getStorage();
// 权限校验

View File

@@ -44,7 +44,7 @@ export async function POST(request: NextRequest) {
}
// 获取配置与存储
const adminConfig = getConfig();
const adminConfig = await getConfig();
const storage: IStorage | null = getStorage();
// 权限与身份校验

View File

@@ -74,7 +74,7 @@ export async function POST(request: NextRequest) {
}
// 获取配置与存储
const adminConfig = getConfig();
const adminConfig = await getConfig();
const storage: IStorage | null = getStorage();
// 判定操作者角色

View File

@@ -19,7 +19,7 @@ export async function GET(request: Request) {
}
try {
const apiSites = getAvailableApiSites();
const apiSites = await getAvailableApiSites();
const apiSite = apiSites.find((site) => site.key === sourceCode);
if (!apiSite) {

View File

@@ -150,7 +150,7 @@ export async function POST(req: NextRequest) {
return NextResponse.json({ error: '用户名或密码错误' }, { status: 401 });
}
const config = getConfig();
const config = await getConfig();
const user = config.UserConfig.Users.find((u) => u.username === username);
if (user && user.banned) {
return NextResponse.json({ error: '用户被封禁' }, { status: 401 });

View File

@@ -66,7 +66,7 @@ export async function POST(req: NextRequest) {
);
}
const config = getConfig();
const config = await getConfig();
// 校验是否开放注册
if (!config.UserConfig.AllowRegister) {
return NextResponse.json({ error: '当前未开放注册' }, { status: 400 });

View File

@@ -23,7 +23,7 @@ export async function GET(request: Request) {
);
}
const apiSites = getAvailableApiSites();
const apiSites = await getAvailableApiSites();
try {
// 根据 resourceId 查找对应的 API 站点

View File

@@ -10,7 +10,7 @@ export async function GET(request: Request) {
const query = searchParams.get('q');
if (!query) {
const cacheTime = getCacheTime();
const cacheTime = await getCacheTime();
return NextResponse.json(
{ results: [] },
{
@@ -21,7 +21,7 @@ export async function GET(request: Request) {
);
}
const apiSites = getAvailableApiSites();
const apiSites = await getAvailableApiSites();
const searchPromises = apiSites.map((site) => searchFromApi(site, query));
try {

View File

@@ -9,7 +9,7 @@ export const runtime = 'edge';
export async function GET(request: NextRequest) {
console.log('server-config called: ', request.url);
const config = getConfig();
const config = await getConfig();
const result = {
SiteName: config.SiteConfig.SiteName,
StorageType: process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage',

View File

@@ -14,7 +14,7 @@ const inter = Inter({ subsets: ['latin'] });
// 动态生成 metadata支持配置更新后的标题变化
export async function generateMetadata(): Promise<Metadata> {
const config = getConfig();
const config = await getConfig();
return {
title: config.SiteConfig.SiteName,
@@ -27,12 +27,12 @@ export const viewport: Viewport = {
themeColor: '#000000',
};
export default function RootLayout({
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const config = getConfig();
const config = await getConfig();
const siteName = config.SiteConfig.SiteName;
const announcement = config.SiteConfig.Announcement;