feat: 后台管理系统(Admin Backend + 全量 CMS)
- 内容迁入数据库:articles/works 表(中英双语 + 内容块), server/utils/seed.ts 灌入现有 6 动态 + 6 作品,站点初始内容不变 - 前台内容 API:/api/news、/api/work(列表/详情,仅已发布), 页面/首页组件改为 useFetch 拉取并按 locale 选 zh/en 字段 - 后台管理 /admin(admin 中间件守卫): - Dashboard 统计、动态/作品增删改(块编辑器、图片上传 /api/admin/upload) - 用户管理(角色切换/删除)、评论审核、联系/订阅管理(导出 CSV) - 预置管理员:NUXT_ADMIN_INITIAL_PASSWORD 首次初始化创建 admin 账号 - 图片自托管:上传存 PVC /data/uploads,/uploads/[...] 路由服务 - sitemap 改查 DB;i18n 移除内容键(305 键对齐);删除 app/data 冗余模块 - 角色以数据库为准(后台可切换);admin 中间件 + 客户端会话恢复插件
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { getConfig } from '../utils/config'
|
||||
import { newsItems } from '../../app/data/news'
|
||||
import { workItems } from '../../app/data/work'
|
||||
import { listArticles, listWorks } from '../utils/content'
|
||||
|
||||
/**
|
||||
* 动态站点地图 /sitemap.xml。
|
||||
* 路由与数据均来自单一事实源(app/data/*),内容更新无需手工同步。
|
||||
* 内容来自数据库(后台可维护),路由自动跟随。
|
||||
*/
|
||||
export default defineEventHandler(() => {
|
||||
const { siteUrl } = getConfig()
|
||||
const articles = listArticles({ publishedOnly: true })
|
||||
const works = listWorks({ publishedOnly: true })
|
||||
|
||||
const urls: Array<{ loc: string; changefreq: string; priority: string }> = [
|
||||
{ loc: '/', changefreq: 'weekly', priority: '1.0' },
|
||||
@@ -18,10 +19,10 @@ export default defineEventHandler(() => {
|
||||
{ loc: '/contact', changefreq: 'monthly', priority: '0.6' },
|
||||
]
|
||||
|
||||
for (const item of workItems) {
|
||||
for (const item of works) {
|
||||
urls.push({ loc: `/work/${item.slug}`, changefreq: 'monthly', priority: '0.7' })
|
||||
}
|
||||
for (const item of newsItems) {
|
||||
for (const item of articles) {
|
||||
urls.push({ loc: `/news/${item.slug}`, changefreq: 'weekly', priority: '0.7' })
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { createError } from 'h3'
|
||||
import { readFileSync, existsSync } from 'node:fs'
|
||||
import { join, dirname, normalize } from 'node:path'
|
||||
import { getConfig } from '../../utils/config'
|
||||
|
||||
const MIME: Record<string, string> = {
|
||||
png: 'image/png',
|
||||
jpg: 'image/jpeg',
|
||||
jpeg: 'image/jpeg',
|
||||
gif: 'image/gif',
|
||||
webp: 'image/webp',
|
||||
svg: 'image/svg+xml',
|
||||
avif: 'image/avif',
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务上传的图片(存于 PVC uploads 目录)
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
const path = getRouterParam(event, 'path') ?? ''
|
||||
const base = normalize(join(dirname(getConfig().dbPath), 'uploads'))
|
||||
const filePath = normalize(join(base, path))
|
||||
|
||||
// 防目录穿越
|
||||
if (!filePath.startsWith(base + '/') && filePath !== base) {
|
||||
throw createError({ statusCode: 403, message: 'Forbidden' })
|
||||
}
|
||||
if (!existsSync(filePath)) {
|
||||
throw createError({ statusCode: 404, message: 'Not Found' })
|
||||
}
|
||||
|
||||
const ext = filePath.split('.').pop()?.toLowerCase() ?? ''
|
||||
const data = readFileSync(filePath)
|
||||
return new Response(new Uint8Array(data), {
|
||||
headers: {
|
||||
'Content-Type': MIME[ext] || 'application/octet-stream',
|
||||
'Cache-Control': 'public, max-age=31536000, immutable',
|
||||
},
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user