feat: 全面升级——后台优化 / 动态配置 / 个人中心 / OSS 存储
- OSS 文件存储(RustFS / S3 v4 兼容,零依赖手写 SigV4): 上传/列表/删除走桶 arcticnewone,/uploads 代理服务 + 本地回退; server/utils/sigv4.ts 纯函数 + AWS 测试向量验证 - 业务动态配置:settings 表 + /api/settings(公开) + /api/admin/settings(PATCH), useSiteSettings 组合式,footer/contact/tools/app.vue/侧边栏/工具页全部接入, 后台 /admin/settings 修改前台即时生效(站点/联系/社交/工具箱/页脚/SEO) - 后台全面优化:Admin* 设计系统(按钮/输入/表单/卡片/徽标/弹窗/确认/空态/骨架/ 分页/页头/Toast)14 组件;Dashboard 增强;各列表页搜索/筛选/批量删除/分页; 布局与侧边栏分组;统一 toast/确认反馈 - 个人中心全新重设计:顶部资料卡 + 统计、精致化改密/删号(二次确认)、 收藏封面网格、评论卡片、移动端适配 - deploy.sh 支持 OSS 凭据注入(NUXT_OSS_*);.env.example 更新 - 测试 17 例全过(含 SigV4 AWS 向量、settings 默认结构)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { getConfig } from '../utils/config'
|
||||
import { getSettings } from '../utils/settings'
|
||||
import { listArticles } from '../utils/content'
|
||||
|
||||
const escapeXml = (s: string) =>
|
||||
@@ -13,6 +14,7 @@ const escapeXml = (s: string) =>
|
||||
*/
|
||||
export default defineEventHandler(() => {
|
||||
const { siteUrl } = getConfig()
|
||||
const { site } = getSettings()
|
||||
const articles = listArticles({ publishedOnly: true })
|
||||
|
||||
const items = articles
|
||||
@@ -36,9 +38,9 @@ export default defineEventHandler(() => {
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>ArcticNewOne</title>
|
||||
<title>${escapeXml(site.name)}</title>
|
||||
<link>${siteUrl}</link>
|
||||
<description>北极新一工作室的最新动态与洞察</description>
|
||||
<description>${escapeXml(site.description.zh)}</description>
|
||||
<language>zh-cn</language>
|
||||
<atom:link href="${siteUrl}/feed.xml" rel="self" type="application/rss+xml"/>
|
||||
${items}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createError } from 'h3'
|
||||
import { readFileSync, existsSync } from 'node:fs'
|
||||
import { join, dirname, normalize } from 'node:path'
|
||||
import { getConfig } from '../../utils/config'
|
||||
import { getOssConfig, getObject } from '../../utils/s3'
|
||||
|
||||
const MIME: Record<string, string> = {
|
||||
png: 'image/png',
|
||||
@@ -13,27 +14,46 @@ const MIME: Record<string, string> = {
|
||||
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))
|
||||
const mimeFromName = (name: string) => MIME[name.split('.').pop()?.toLowerCase() ?? ''] || 'application/octet-stream'
|
||||
|
||||
// 防目录穿越
|
||||
if (!filePath.startsWith(base + '/') && filePath !== base) {
|
||||
/**
|
||||
* 服务上传的图片:
|
||||
* - OSS 已配置 -> 从桶 arcticnewone 拉取(key 为 /uploads/<path> 的 path)
|
||||
* - OSS 无该对象或未配置 -> 回退读取本地 /data/uploads(兼容历史已上传内容)
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const path = getRouterParam(event, 'path') ?? ''
|
||||
|
||||
const oss = getOssConfig()
|
||||
if (oss) {
|
||||
try {
|
||||
const res = await getObject(path)
|
||||
if (res) {
|
||||
return new Response(res.body, {
|
||||
headers: {
|
||||
'Content-Type': res.headers.get('content-type') || mimeFromName(path),
|
||||
'Cache-Control': 'public, max-age=31536000, immutable',
|
||||
},
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[uploads] oss read failed, fallback to local:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// 本地回退
|
||||
const base = normalize(join(dirname(getConfig().dbPath), 'uploads'))
|
||||
const filePath = normalize(join(base, path.split('/').join('/')))
|
||||
if (!filePath.startsWith(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',
|
||||
'Content-Type': mimeFromName(filePath),
|
||||
'Cache-Control': 'public, max-age=31536000, immutable',
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user