添加 阿拉伯语 和 俄语
This commit is contained in:
@@ -117,7 +117,7 @@ export async function seedIfEmpty() {
|
||||
await execInit(
|
||||
`INSERT INTO admin_users (username, password, name, email, role_id, status, is_built_in, create_time, update_time)
|
||||
VALUES (?, ?, ?, ?, ?, 'active', 1, ?, ?)`,
|
||||
['admin', DEFAULT_ADMIN_PASSWORD_MD5, '超级管理员', 'admin@umedglobal.com', roleResult.insertId, now, now]
|
||||
['admin', DEFAULT_ADMIN_PASSWORD_MD5, '超级管理员', 'Umedchina@outlook.com', roleResult.insertId, now, now]
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
type SiteLang = 'en' | 'zh'
|
||||
import type { SiteLocale } from '~/types/locale'
|
||||
import { toContentLocale } from '~/types/locale'
|
||||
|
||||
const assessmentReportsLabels: Record<string, Record<SiteLang, string>> = {
|
||||
type SiteLang = SiteLocale
|
||||
|
||||
const assessmentReportsLabels: Record<string, Record<'en' | 'zh', string>> = {
|
||||
yes: { zh: '是,我有近期报告/影像', en: 'Yes, I have recent reports/scans' },
|
||||
no: { zh: '否,暂时没有', en: 'No, not yet' },
|
||||
pending: { zh: '我即将获取', en: 'I will obtain them soon' }
|
||||
}
|
||||
|
||||
const partnerCategoryLabels: Record<string, Record<SiteLang, string>> = {
|
||||
const partnerCategoryLabels: Record<string, Record<'en' | 'zh', string>> = {
|
||||
'medical-institution': { zh: '医疗机构', en: 'Medical Institution' },
|
||||
'referral-partner': { zh: '转诊合作伙伴', en: 'Referral Partner' },
|
||||
'travel-concierge': { zh: '旅行服务', en: 'Travel & Concierge' },
|
||||
@@ -14,21 +17,29 @@ const partnerCategoryLabels: Record<string, Record<SiteLang, string>> = {
|
||||
other: { zh: '其他', en: 'Other' }
|
||||
}
|
||||
|
||||
const langLabels: Record<SiteLocale, string> = {
|
||||
en: 'English',
|
||||
zh: '中文',
|
||||
ar: 'العربية',
|
||||
ru: 'Русский'
|
||||
}
|
||||
|
||||
export function formatAssessmentReports(value: string | null | undefined, lang: SiteLang): string {
|
||||
if (!value) return lang === 'zh' ? '(未选择)' : '(Not selected)'
|
||||
return assessmentReportsLabels[value]?.[lang] ?? value
|
||||
const contentLang = toContentLocale(lang)
|
||||
if (!value) return contentLang === 'zh' ? '(未选择)' : '(Not selected)'
|
||||
return assessmentReportsLabels[value]?.[contentLang] ?? value
|
||||
}
|
||||
|
||||
export function formatPartnerCategory(value: string, lang: SiteLang): string {
|
||||
return partnerCategoryLabels[value]?.[lang] ?? value
|
||||
return partnerCategoryLabels[value]?.[toContentLocale(lang)] ?? value
|
||||
}
|
||||
|
||||
export function formatLangLabel(lang: SiteLang): string {
|
||||
return lang === 'zh' ? '中文' : 'English'
|
||||
return langLabels[lang] ?? lang
|
||||
}
|
||||
|
||||
export function formatOptional(value: string | null | undefined, lang: SiteLang): string {
|
||||
const trimmed = value?.trim()
|
||||
if (trimmed) return trimmed
|
||||
return lang === 'zh' ? '(未填写)' : '(Not provided)'
|
||||
return toContentLocale(lang) === 'zh' ? '(未填写)' : '(Not provided)'
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import {
|
||||
formatPartnerCategory
|
||||
} from '~/server/utils/form-mail-labels'
|
||||
import { buildMailHtml, buildMailText, sendMail } from '~/server/utils/mail'
|
||||
import type { SiteLocale } from '~/types/locale'
|
||||
|
||||
type SiteLang = 'en' | 'zh'
|
||||
type SiteLang = SiteLocale
|
||||
|
||||
export async function notifyAssessmentSubmission(input: {
|
||||
lang: SiteLang
|
||||
|
||||
@@ -21,7 +21,7 @@ function getMailConfig() {
|
||||
user: String(config.mailUser || ''),
|
||||
pass: String(config.mailPass || ''),
|
||||
from: String(config.mailFrom || config.mailUser || ''),
|
||||
to: String(config.mailTo || 'umedglobal@umedglobal.cn')
|
||||
to: String(config.mailTo || 'info@umedglobal.com.cn')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,10 @@ export async function execute(sql: string, params: unknown[] = []): Promise<Resu
|
||||
export async function ensureDb(): Promise<void> {
|
||||
if (dbReady) return
|
||||
if (!initPromise) {
|
||||
initPromise = initDatabase()
|
||||
initPromise = initDatabase().catch((error) => {
|
||||
initPromise = null
|
||||
throw error
|
||||
})
|
||||
}
|
||||
await initPromise
|
||||
}
|
||||
@@ -66,7 +69,8 @@ export async function ensureDb(): Promise<void> {
|
||||
async function initDatabase() {
|
||||
const { initSchema, seedIfEmpty, migrateBuiltinAdminPassword, migrateWorkbenchMenu, migrateSeoMenu } =
|
||||
await import('./db-init')
|
||||
const { initPageSeoSchema, seedPageSeoIfEmpty, syncMissingPageSeo } = await import('./page-seo')
|
||||
const { initPageSeoSchema, seedPageSeoIfEmpty, syncMissingPageSeo, syncPolicyPageIndexability } =
|
||||
await import('./page-seo')
|
||||
const { initNewsSchema, migrateNewsMenu } = await import('./news')
|
||||
|
||||
await initSchema()
|
||||
@@ -75,6 +79,7 @@ async function initDatabase() {
|
||||
await seedIfEmpty()
|
||||
await seedPageSeoIfEmpty()
|
||||
await syncMissingPageSeo()
|
||||
await syncPolicyPageIndexability()
|
||||
await migrateBuiltinAdminPassword()
|
||||
await migrateWorkbenchMenu()
|
||||
await migrateSeoMenu()
|
||||
|
||||
@@ -3,6 +3,9 @@ import { newsItems as seedNewsEn, seedVideosEn } from '~/data/news-content'
|
||||
import { newsItemsZh, seedVideosZh } from '~/data/locale/zh/news.zh'
|
||||
import { nowStr } from './auth'
|
||||
import { execInit, execute, query, queryInit, queryOne, queryOneInit } from './mysql'
|
||||
import { isManagedUploadThumbnail, tryDeleteUploadedThumbnail } from './upload'
|
||||
import type { SiteLocale } from '~/types/locale'
|
||||
import { isSiteLocale } from '~/types/locale'
|
||||
|
||||
export type MediaType = 'article' | 'video'
|
||||
|
||||
@@ -25,7 +28,7 @@ export type NewsArticleRow = {
|
||||
|
||||
export type NewsArticleRecord = {
|
||||
id: string
|
||||
locale: 'en' | 'zh'
|
||||
locale: SiteLocale
|
||||
mediaType: MediaType
|
||||
title: string
|
||||
summary: string
|
||||
@@ -41,7 +44,7 @@ export type NewsArticleRecord = {
|
||||
}
|
||||
|
||||
export type NewsArticleInput = {
|
||||
locale: 'en' | 'zh'
|
||||
locale: SiteLocale
|
||||
mediaType: MediaType
|
||||
title: string
|
||||
summary: string
|
||||
@@ -80,7 +83,7 @@ export type PublishedMedia = {
|
||||
function rowToRecord(row: NewsArticleRow): NewsArticleRecord {
|
||||
return {
|
||||
id: String(row.id),
|
||||
locale: row.locale as 'en' | 'zh',
|
||||
locale: isSiteLocale(row.locale) ? row.locale : 'en',
|
||||
mediaType: (row.media_type === 'video' ? 'video' : 'article') as MediaType,
|
||||
title: row.title,
|
||||
summary: row.summary,
|
||||
@@ -137,7 +140,7 @@ export async function initNewsSchema() {
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'published',
|
||||
created_at VARCHAR(32) NOT NULL,
|
||||
updated_at VARCHAR(32) NOT NULL,
|
||||
INDEX idx_news_locale_sort (locale, sort_order, id)
|
||||
INDEX idx_news_locale_sort (locale, sort_order, created_at, id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
`)
|
||||
}
|
||||
@@ -256,7 +259,7 @@ export async function migrateNewsMenu() {
|
||||
}
|
||||
|
||||
export async function listNewsArticles(options?: {
|
||||
locale?: 'en' | 'zh'
|
||||
locale?: SiteLocale
|
||||
mediaType?: MediaType
|
||||
keyword?: string
|
||||
status?: 'published' | 'draft'
|
||||
@@ -264,7 +267,7 @@ export async function listNewsArticles(options?: {
|
||||
pageSize?: number
|
||||
}) {
|
||||
let rows = await query<NewsArticleRow>(
|
||||
'SELECT * FROM news_articles ORDER BY sort_order DESC, created_at DESC'
|
||||
'SELECT * FROM news_articles ORDER BY sort_order ASC, created_at DESC'
|
||||
)
|
||||
|
||||
if (options?.locale) rows = rows.filter((r) => r.locale === options.locale)
|
||||
@@ -287,11 +290,11 @@ export async function listNewsArticles(options?: {
|
||||
return { list: rows.map(rowToRecord), total }
|
||||
}
|
||||
|
||||
export async function listPublishedMedia(locale: 'en' | 'zh'): Promise<PublishedMedia> {
|
||||
export async function listPublishedMedia(locale: SiteLocale): Promise<PublishedMedia> {
|
||||
const rows = await query<NewsArticleRow>(
|
||||
`SELECT * FROM news_articles
|
||||
WHERE locale = ? AND status = 'published'
|
||||
ORDER BY sort_order DESC, created_at DESC`,
|
||||
ORDER BY sort_order ASC, created_at DESC`,
|
||||
[locale]
|
||||
)
|
||||
|
||||
@@ -360,6 +363,8 @@ export async function updateNewsArticle(id: string | number, input: Partial<News
|
||||
|
||||
const mediaType = input.mediaType ?? existing.mediaType
|
||||
const now = nowStr()
|
||||
const previousThumbnail = existing.thumbnail
|
||||
const nextThumbnail = input.thumbnail?.trim() ?? existing.thumbnail
|
||||
|
||||
await execute(
|
||||
`UPDATE news_articles SET
|
||||
@@ -381,7 +386,7 @@ export async function updateNewsArticle(id: string | number, input: Partial<News
|
||||
mediaType,
|
||||
input.title?.trim() ?? existing.title,
|
||||
input.summary?.trim() ?? existing.summary,
|
||||
input.thumbnail?.trim() ?? existing.thumbnail,
|
||||
nextThumbnail,
|
||||
input.thumbnailAlt !== undefined ? input.thumbnailAlt.trim() || null : existing.thumbnailAlt ?? null,
|
||||
mediaType === 'article' ? (input.url?.trim() ?? existing.url ?? '') : '',
|
||||
mediaType === 'video' ? (input.youtubeUrl?.trim() ?? existing.youtubeUrl ?? null) : null,
|
||||
@@ -393,11 +398,45 @@ export async function updateNewsArticle(id: string | number, input: Partial<News
|
||||
]
|
||||
)
|
||||
|
||||
if (previousThumbnail !== nextThumbnail) {
|
||||
await cleanupUnusedUploadedThumbnail(previousThumbnail)
|
||||
}
|
||||
|
||||
return getNewsArticleById(id)
|
||||
}
|
||||
|
||||
async function cleanupUnusedUploadedThumbnail(url?: string | null) {
|
||||
if (!isManagedUploadThumbnail(url)) return
|
||||
|
||||
try {
|
||||
const remaining = await queryOne<{ c: number }>(
|
||||
'SELECT COUNT(*) AS c FROM news_articles WHERE thumbnail = ?',
|
||||
[url]
|
||||
)
|
||||
if ((remaining?.c ?? 0) > 0) return
|
||||
|
||||
await tryDeleteUploadedThumbnail(url)
|
||||
} catch {
|
||||
// 缩略图清理失败不应阻断内容更新或删除
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteNewsArticles(ids: Array<string | number>) {
|
||||
if (!ids.length) return
|
||||
|
||||
const placeholders = ids.map(() => '?').join(', ')
|
||||
const rows = await query<Pick<NewsArticleRow, 'thumbnail'>>(
|
||||
`SELECT thumbnail FROM news_articles WHERE id IN (${placeholders})`,
|
||||
ids
|
||||
)
|
||||
|
||||
for (const id of ids) {
|
||||
await execute('DELETE FROM news_articles WHERE id = ?', [id])
|
||||
}
|
||||
|
||||
const thumbnails = [...new Set(rows.map((row) => row.thumbnail).filter(Boolean))]
|
||||
|
||||
for (const thumbnail of thumbnails) {
|
||||
await cleanupUnusedUploadedThumbnail(thumbnail)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { SEO_REGISTRY, type SeoRegistryEntry } from '../data/seo-registry'
|
||||
import { SEO_AR_RU, buildSeoValuesFromCopy } from '../data/seo-registry-ar-ru'
|
||||
import { nowStr } from './auth'
|
||||
import { execInit, execute, query, queryInit, queryOne, queryOneInit } from './mysql'
|
||||
import { isSiteLocale, type SiteLocale } from '~/types/locale'
|
||||
|
||||
export type PageSeoRow = {
|
||||
id: number
|
||||
@@ -22,7 +24,7 @@ export type PageSeoRow = {
|
||||
export type PageSeoRecord = {
|
||||
id: string
|
||||
routeKey: string
|
||||
locale: 'en' | 'zh'
|
||||
locale: SiteLocale
|
||||
pageLabel: string
|
||||
title: string
|
||||
description: string
|
||||
@@ -51,7 +53,7 @@ function rowToRecord(row: PageSeoRow): PageSeoRecord {
|
||||
return {
|
||||
id: String(row.id),
|
||||
routeKey: row.route_key,
|
||||
locale: row.locale as 'en' | 'zh',
|
||||
locale: isSiteLocale(row.locale) ? row.locale : 'en',
|
||||
pageLabel: row.page_label,
|
||||
title: row.title,
|
||||
description: row.description,
|
||||
@@ -142,6 +144,75 @@ export async function syncMissingPageSeo() {
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
entryToValues(entry, now)
|
||||
)
|
||||
existing.add(routeLocaleKey)
|
||||
}
|
||||
|
||||
// 以阿语 / 俄语正式译文写入或更新 SEO(替换早期英文占位)
|
||||
for (const [routeKey, locales] of Object.entries(SEO_AR_RU)) {
|
||||
for (const locale of ['ar', 'ru'] as const) {
|
||||
const copy = locales[locale]
|
||||
const values = buildSeoValuesFromCopy(routeKey, locale, copy, now)
|
||||
const routeLocaleKey = `${routeKey}::${locale}`
|
||||
|
||||
if (existing.has(routeLocaleKey)) {
|
||||
await execInit(
|
||||
`UPDATE page_seo SET
|
||||
page_label = ?,
|
||||
title = ?,
|
||||
description = ?,
|
||||
keywords = ?,
|
||||
og_title = ?,
|
||||
og_description = ?,
|
||||
og_image = ?,
|
||||
robots = ?,
|
||||
og_type = ?,
|
||||
updated_at = ?
|
||||
WHERE route_key = ? AND locale = ?`,
|
||||
[
|
||||
copy.pageLabel,
|
||||
copy.title,
|
||||
copy.description,
|
||||
copy.keywords ?? null,
|
||||
copy.ogTitle ?? null,
|
||||
copy.ogDescription ?? null,
|
||||
copy.ogImage ?? null,
|
||||
copy.robots ?? 'index,follow',
|
||||
copy.ogType ?? 'website',
|
||||
now,
|
||||
routeKey,
|
||||
locale
|
||||
]
|
||||
)
|
||||
} else {
|
||||
await execInit(
|
||||
`INSERT INTO page_seo (
|
||||
route_key, locale, page_label, title, description,
|
||||
keywords, og_title, og_description, og_image, robots, og_type,
|
||||
updated_at, updated_by
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
values
|
||||
)
|
||||
existing.add(routeLocaleKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const INDEXABLE_POLICY_ROUTES = [
|
||||
'/privacy-policy',
|
||||
'/terms-of-use',
|
||||
'/accessibility-statement',
|
||||
] as const
|
||||
|
||||
/** 将政策页 robots 从 noindex 同步为 index,follow(部署后自动修复线上数据库) */
|
||||
export async function syncPolicyPageIndexability() {
|
||||
const now = nowStr()
|
||||
for (const routeKey of INDEXABLE_POLICY_ROUTES) {
|
||||
await execInit(
|
||||
`UPDATE page_seo SET robots = 'index,follow', updated_at = ?
|
||||
WHERE route_key = ? AND robots = 'noindex,follow'`,
|
||||
[now, routeKey]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +220,7 @@ export async function listPageSeo(params?: { locale?: string; keyword?: string }
|
||||
let sql = 'SELECT * FROM page_seo WHERE 1=1'
|
||||
const args: unknown[] = []
|
||||
|
||||
if (params?.locale === 'en' || params?.locale === 'zh') {
|
||||
if (params?.locale && isSiteLocale(params.locale)) {
|
||||
sql += ' AND locale = ?'
|
||||
args.push(params.locale)
|
||||
}
|
||||
@@ -165,12 +236,22 @@ export async function listPageSeo(params?: { locale?: string; keyword?: string }
|
||||
return rows.map(rowToRecord)
|
||||
}
|
||||
|
||||
export async function getPageSeoByRoute(routeKey: string, locale: 'en' | 'zh') {
|
||||
export async function getPageSeoByRoute(routeKey: string, locale: SiteLocale) {
|
||||
const row = await queryOne<PageSeoRow>(
|
||||
'SELECT * FROM page_seo WHERE route_key = ? AND locale = ?',
|
||||
[routeKey, locale]
|
||||
)
|
||||
return row ? rowToRecord(row) : null
|
||||
if (row) return rowToRecord(row)
|
||||
|
||||
if (locale !== 'en') {
|
||||
const fallback = await queryOne<PageSeoRow>(
|
||||
'SELECT * FROM page_seo WHERE route_key = ? AND locale = ?',
|
||||
[routeKey, 'en']
|
||||
)
|
||||
return fallback ? rowToRecord(fallback) : null
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export async function getPageSeoById(id: string | number) {
|
||||
|
||||
Reference in New Issue
Block a user