官网开发 0810-v2
This commit is contained in:
@@ -29,15 +29,25 @@ router.get('/api/www/global/site', async (_req: Request, res: Response) => {
|
||||
// PUT /api/www/global/site
|
||||
router.put('/api/www/global/site', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { site_title, favicon_url, logo_dark_url, logo_light_url } = req.body;
|
||||
const { site_title, favicon_url, logo_dark_url, logo_light_url, enabled_locales } = req.body;
|
||||
const [existing] = await db.select().from(wwwSiteSettings).limit(1);
|
||||
|
||||
// 多语言:前端可能传数组或逗号分隔字符串,白名单过滤后落库;空值保留原配置
|
||||
let localesValue: string | undefined;
|
||||
if (enabled_locales !== undefined) {
|
||||
const list = (Array.isArray(enabled_locales) ? enabled_locales : String(enabled_locales).split(','))
|
||||
.map((v: unknown) => String(v).trim())
|
||||
.filter(v => v === 'zh' || v === 'en');
|
||||
if (list.length > 0) localesValue = [...new Set(list)].join(',');
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
await db.update(wwwSiteSettings).set({
|
||||
siteTitle: site_title ?? existing.siteTitle,
|
||||
faviconUrl: favicon_url ?? existing.faviconUrl,
|
||||
logoDarkUrl: logo_dark_url ?? existing.logoDarkUrl,
|
||||
logoLightUrl: logo_light_url ?? existing.logoLightUrl,
|
||||
enabledLocales: localesValue ?? existing.enabledLocales,
|
||||
}).where(eq(wwwSiteSettings.id, existing.id));
|
||||
} else {
|
||||
await db.insert(wwwSiteSettings).values({
|
||||
@@ -45,6 +55,7 @@ router.put('/api/www/global/site', async (req: Request, res: Response) => {
|
||||
faviconUrl: favicon_url || '',
|
||||
logoDarkUrl: logo_dark_url || '',
|
||||
logoLightUrl: logo_light_url || '',
|
||||
enabledLocales: localesValue || 'zh,en',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ export const wwwSiteSettings = mysqlTable('www_site_settings', {
|
||||
faviconUrl: varchar('favicon_url', { length: 500 }).notNull().default(''),
|
||||
logoDarkUrl: varchar('logo_dark_url', { length: 500 }).notNull().default(''),
|
||||
logoLightUrl: varchar('logo_light_url', { length: 500 }).notNull().default(''),
|
||||
enabledLocales: varchar('enabled_locales', { length: 20 }).notNull().default('zh,en'),
|
||||
updatedAt: datetime('updated_at').notNull().default(sql`CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user