feat: 收官补齐全部未实现功能
- 账号体系:修改密码(/account + PATCH /api/auth/password)、自助删除账号 (DELETE /api/auth/me)、订阅退订(token + /unsubscribe 页) - 前台/SEO:RSS 订阅 /feed.xml、作品详情分享、canonical URL、 文章 Article JSON-LD、品牌化错误页(i18n) - 后台增强:图片管理 /admin/uploads、操作审计日志 /admin/audit(含清空)、 联系消息已读标记、评论列表分页 - 工程:vitest 测试(密码哈希/内容校验器/种子完整性,12 例)+ pnpm test - DB 迁移:contacts.read、subscribers.token、audit_logs(老库 ALTER 兼容) - 密码逻辑抽为 server/utils/password.ts 供测试
This commit is contained in:
+7
-2
@@ -1,21 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead, useSeoMeta, useRuntimeConfig } from '#imports'
|
||||
import { computed } from 'vue'
|
||||
import { useHead, useSeoMeta, useRuntimeConfig, useRoute } from '#imports'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { siteConfig } from '~/config/site'
|
||||
|
||||
const { t } = useI18n()
|
||||
const { public: publicCfg } = useRuntimeConfig()
|
||||
const route = useRoute()
|
||||
const baseUrl = String(publicCfg.siteUrl || '').replace(/\/$/, '')
|
||||
|
||||
// 站点通用基础信息
|
||||
const siteImage = baseUrl ? `${baseUrl}/og-image.png` : '/og-image.png'
|
||||
|
||||
// 配置全局 Title 模板
|
||||
// 配置全局 Title 模板 + canonical(SEO)
|
||||
useHead({
|
||||
titleTemplate: (titleChunk?: string) => {
|
||||
const siteName = t('app.name')
|
||||
return titleChunk ? `${titleChunk} - ${siteName}` : siteName
|
||||
},
|
||||
link: [
|
||||
{ rel: 'canonical', href: computed(() => (baseUrl ? `${baseUrl}${route.path}` : undefined)) },
|
||||
],
|
||||
// JSON-LD 结构化数据(Organization)
|
||||
script: [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 后台左侧导航栏(Dashboard / 动态 / 作品 / 用户 / 评论 / 联系 / 订阅 / 返回前台)。
|
||||
* 后台左侧导航栏(Dashboard / 动态 / 作品 / 用户 / 评论 / 联系 / 订阅 / 图片 / 日志 / 返回前台)。
|
||||
* 高亮当前路由;点击任意导航项时向父级发出 navigate 事件(移动端关闭侧栏)。
|
||||
*/
|
||||
import { useRoute } from '#app'
|
||||
@@ -17,6 +17,8 @@ const items = [
|
||||
{ to: '/admin/comments', label: '评论管理', icon: 'ph:chat-circle-text' },
|
||||
{ to: '/admin/contacts', label: '联系留言', icon: 'ph:envelope-simple' },
|
||||
{ to: '/admin/subscribers', label: '订阅管理', icon: 'ph:paper-plane-tilt' },
|
||||
{ to: '/admin/uploads', label: '图片管理', icon: 'ph:image' },
|
||||
{ to: '/admin/audit', label: '操作日志', icon: 'ph:list-checks' },
|
||||
]
|
||||
|
||||
const isActive = (to: string) => route.path === to
|
||||
|
||||
+14
-13
@@ -1,30 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import type { NuxtError } from '#app'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const props = defineProps<{ error: NuxtError }>()
|
||||
const { t } = useI18n()
|
||||
|
||||
const statusText = computed(() => props.error.statusText || 'Something went wrong.')
|
||||
const statusText = computed(() => {
|
||||
if (props.error.statusCode === 404) return t('error.notFound')
|
||||
if (props.error.statusCode === 500) return t('error.serverError')
|
||||
return t('error.generic')
|
||||
})
|
||||
|
||||
const handleError = () => clearError({ redirect: '/' })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex min-h-screen flex-col items-center justify-center gap-4 bg-slate-950 px-6 text-center text-slate-50">
|
||||
<p class="text-sm font-medium uppercase tracking-[0.35em] text-cyan-300">
|
||||
Error occurred in this page
|
||||
</p>
|
||||
<h1 class="text-6xl font-semibold">
|
||||
{{ error.status }}
|
||||
</h1>
|
||||
<p class="max-w-xl text-slate-300">
|
||||
{{ statusText }}
|
||||
</p>
|
||||
<div class="flex min-h-screen flex-col items-center justify-center gap-6 bg-white px-6 text-center">
|
||||
<p class="text-sm font-semibold uppercase tracking-[0.35em] text-gray-400">{{ t('error.title') }}</p>
|
||||
<h1 class="text-7xl font-bold text-black">{{ error.statusCode }}</h1>
|
||||
<p class="max-w-xl text-gray-500">{{ statusText }}</p>
|
||||
<button
|
||||
class="rounded-md bg-cyan-300 px-5 py-3 text-sm font-semibold text-slate-950 transition hover:bg-cyan-200"
|
||||
class="rounded-full bg-black px-8 py-3 text-sm font-semibold text-white transition-colors hover:bg-gray-800"
|
||||
type="button"
|
||||
@click="handleError"
|
||||
>
|
||||
Go back home
|
||||
{{ t('error.backHome') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -87,6 +87,72 @@
|
||||
{{ saving ? t('account.saving') : t('account.save') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 修改密码 -->
|
||||
<form class="p-6 rounded-2xl bg-white border border-gray-100 shadow-sm space-y-5" @submit.prevent="changePassword">
|
||||
<h3 class="text-lg font-bold text-black">{{ t('account.changePassword.title') }}</h3>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-2">{{ t('account.changePassword.currentPassword') }}</label>
|
||||
<input
|
||||
v-model="pwForm.currentPassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-2">{{ t('account.changePassword.newPassword') }}</label>
|
||||
<input
|
||||
v-model="pwForm.newPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-2">{{ t('account.changePassword.confirmPassword') }}</label>
|
||||
<input
|
||||
v-model="pwForm.confirmPassword"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="pwMessage" class="text-sm" :class="pwFailed ? 'text-red-600' : 'text-green-600'">{{ pwMessage }}</p>
|
||||
<button
|
||||
type="submit"
|
||||
:disabled="pwSaving"
|
||||
class="w-full py-3 rounded-xl bg-black text-white font-semibold flex items-center justify-center gap-2 transition-colors disabled:opacity-50"
|
||||
>
|
||||
<Icon v-if="pwSaving" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
|
||||
{{ pwSaving ? t('account.changePassword.saving') : t('account.changePassword.submit') }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- 删除账号(危险区) -->
|
||||
<div class="p-6 rounded-2xl bg-white border border-red-200 shadow-sm space-y-5">
|
||||
<h3 class="text-lg font-bold text-red-600">{{ t('account.deleteAccount.title') }}</h3>
|
||||
<p class="text-sm text-gray-500">{{ t('account.deleteAccount.hint') }}</p>
|
||||
<div>
|
||||
<input
|
||||
v-model="deletePassword"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
:placeholder="t('account.deleteAccount.passwordPlaceholder')"
|
||||
@keydown.enter.prevent
|
||||
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-red-500 focus:ring-2 focus:ring-red-500/5 outline-none transition-all"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="deleteMessage" class="text-sm" :class="deleteFailed ? 'text-red-600' : 'text-green-600'">{{ deleteMessage }}</p>
|
||||
<button
|
||||
@click="confirmDeleteAccount"
|
||||
:disabled="deleting"
|
||||
class="w-full py-3 rounded-xl bg-red-600 text-white font-semibold flex items-center justify-center gap-2 transition-colors hover:bg-red-700 disabled:opacity-50"
|
||||
>
|
||||
<Icon v-if="deleting" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
|
||||
{{ t('account.deleteAccount.confirmButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 我的收藏 -->
|
||||
@@ -211,6 +277,72 @@ const saveProfile = async () => {
|
||||
saving.value = false
|
||||
}
|
||||
|
||||
// ---- 修改密码 ----
|
||||
const pwForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' })
|
||||
const pwSaving = ref(false)
|
||||
const pwMessage = ref('')
|
||||
const pwFailed = ref(false)
|
||||
|
||||
const changePassword = async () => {
|
||||
pwMessage.value = ''
|
||||
pwFailed.value = false
|
||||
|
||||
if (pwForm.newPassword.length < 8) {
|
||||
pwFailed.value = true
|
||||
pwMessage.value = t('account.changePassword.tooShort')
|
||||
return
|
||||
}
|
||||
if (pwForm.newPassword !== pwForm.confirmPassword) {
|
||||
pwFailed.value = true
|
||||
pwMessage.value = t('account.changePassword.mismatch')
|
||||
return
|
||||
}
|
||||
|
||||
pwSaving.value = true
|
||||
try {
|
||||
await $fetch('/api/auth/password', {
|
||||
method: 'PATCH',
|
||||
body: { currentPassword: pwForm.currentPassword, newPassword: pwForm.newPassword },
|
||||
})
|
||||
pwMessage.value = t('account.changePassword.success')
|
||||
pwForm.currentPassword = ''
|
||||
pwForm.newPassword = ''
|
||||
pwForm.confirmPassword = ''
|
||||
} catch (err) {
|
||||
pwFailed.value = true
|
||||
pwMessage.value =
|
||||
(err as any)?.data?.code === 'WRONG_PASSWORD'
|
||||
? t('account.changePassword.wrongPassword')
|
||||
: apiError(err)
|
||||
}
|
||||
pwSaving.value = false
|
||||
}
|
||||
|
||||
// ---- 删除账号 ----
|
||||
const deletePassword = ref('')
|
||||
const deleting = ref(false)
|
||||
const deleteMessage = ref('')
|
||||
const deleteFailed = ref(false)
|
||||
|
||||
const confirmDeleteAccount = async () => {
|
||||
if (!window.confirm(t('account.deleteAccount.confirmText'))) return
|
||||
deleteMessage.value = ''
|
||||
deleteFailed.value = false
|
||||
deleting.value = true
|
||||
try {
|
||||
await $fetch('/api/auth/me', { method: 'DELETE', body: { password: deletePassword.value } })
|
||||
await userStore.logout()
|
||||
await navigateTo('/')
|
||||
} catch (err) {
|
||||
deleteFailed.value = true
|
||||
deleteMessage.value =
|
||||
(err as any)?.data?.code === 'WRONG_PASSWORD'
|
||||
? t('account.deleteAccount.wrongPassword')
|
||||
: apiError(err)
|
||||
}
|
||||
deleting.value = false
|
||||
}
|
||||
|
||||
// ---- 收藏 ----
|
||||
interface FavedWork { slug: string; titleZh: string; titleEn: string; image: string | null }
|
||||
const favorites = ref<FavedWork[]>([])
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
<template>
|
||||
<section class="p-4 md:p-8 lg:p-10">
|
||||
<header class="mb-8 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-11 h-11 rounded-2xl bg-black text-white flex items-center justify-center flex-shrink-0">
|
||||
<Icon name="ph:list-checks" class="w-6 h-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-black leading-tight">操作日志</h1>
|
||||
<p class="text-sm text-gray-500 mt-1">后台管理员的关键操作审计记录。</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@click="clearLogs"
|
||||
:disabled="!logs.length || clearing"
|
||||
class="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed transition-colors flex-shrink-0"
|
||||
title="清空全部操作日志"
|
||||
>
|
||||
<Icon v-if="clearing" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
<Icon v-else name="ph:trash" class="w-4 h-4" />
|
||||
清空日志
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<!-- 操作反馈 -->
|
||||
<div
|
||||
v-if="flash"
|
||||
class="mb-6 px-4 py-3 rounded-xl text-sm font-medium flex items-center gap-2"
|
||||
:class="flashKind === 'ok' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-red-50 text-red-700 border border-red-200'"
|
||||
>
|
||||
<Icon :name="flashKind === 'ok' ? 'ph:check-circle' : 'ph:warning-circle'" class="w-4 h-4" />
|
||||
{{ flash }}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<span class="text-sm text-gray-500">共 {{ total }} 条日志</span>
|
||||
</div>
|
||||
|
||||
<!-- 加载中 -->
|
||||
<div v-if="loading" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:circle-notch" class="w-8 h-8 animate-spin" />
|
||||
<p class="text-sm">加载中…</p>
|
||||
</div>
|
||||
|
||||
<!-- 加载失败 -->
|
||||
<div v-else-if="loadError" class="py-24 text-center">
|
||||
<div class="inline-flex flex-col items-center gap-3 text-gray-500">
|
||||
<Icon name="ph:warning-circle" class="w-8 h-8 text-red-500" />
|
||||
<p class="text-sm">{{ loadError }}</p>
|
||||
<button @click="loadLogs" class="px-5 py-2 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors">
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空态 -->
|
||||
<div v-else-if="!logs.length" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:list-checks" class="w-10 h-10" />
|
||||
<p class="text-sm">暂无操作日志</p>
|
||||
</div>
|
||||
|
||||
<!-- 日志表格 -->
|
||||
<div v-else class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="text-left text-gray-500 border-b border-gray-100 bg-gray-50">
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">时间</th>
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">操作人</th>
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">操作</th>
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider">对象</th>
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider">详情</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="log in logs"
|
||||
:key="log.id"
|
||||
class="border-b border-gray-100 last:border-b-0 hover:bg-gray-50/70 transition-colors"
|
||||
>
|
||||
<td class="px-6 py-4 text-gray-500 text-xs whitespace-nowrap">{{ formatDate(log.createdAt) }}</td>
|
||||
<td class="px-6 py-4 text-gray-700 whitespace-nowrap">{{ log.actor_name || 'system' }}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap">
|
||||
<span
|
||||
class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold"
|
||||
:class="actionMeta(log.action).cls"
|
||||
>
|
||||
{{ actionMeta(log.action).label }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-6 py-4">
|
||||
<code class="text-xs text-gray-600 bg-gray-50 border border-gray-100 rounded px-2 py-1">{{ log.target }}</code>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-600 max-w-[320px] md:max-w-md truncate" :title="log.detail || undefined">
|
||||
{{ log.detail || '—' }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<div v-if="logs.length < total" class="p-4 border-t border-gray-100 flex justify-center">
|
||||
<button
|
||||
@click="loadMore"
|
||||
:disabled="loadingMore"
|
||||
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 disabled:opacity-60 transition-colors"
|
||||
>
|
||||
<Icon v-if="loadingMore" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
{{ loadingMore ? '加载中…' : '加载更多' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||||
useSeoMeta({ title: '操作日志' })
|
||||
|
||||
interface AuditLog {
|
||||
id: number
|
||||
actor_name: string | null
|
||||
action: string
|
||||
target: string
|
||||
detail: string | null
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
const pageSize = 20
|
||||
const page = ref(0)
|
||||
const total = ref(0)
|
||||
const logs = ref<AuditLog[]>([])
|
||||
const loading = ref(true)
|
||||
const loadingMore = ref(false)
|
||||
const loadError = ref('')
|
||||
|
||||
const ACTION_META: Record<string, { label: string; cls: string }> = {
|
||||
create: { label: '新增', cls: 'bg-green-100 text-green-700' },
|
||||
update: { label: '更新', cls: 'bg-amber-100 text-amber-700' },
|
||||
delete: { label: '删除', cls: 'bg-red-100 text-red-700' },
|
||||
upload: { label: '上传', cls: 'bg-blue-100 text-blue-700' },
|
||||
clear: { label: '清空', cls: 'bg-gray-200 text-gray-600' },
|
||||
}
|
||||
const actionMeta = (action: string) => ACTION_META[action] ?? { label: action, cls: 'bg-gray-100 text-gray-700' }
|
||||
|
||||
const flash = ref('')
|
||||
const flashKind = ref<'ok' | 'err'>('ok')
|
||||
let flashTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const showFlash = (msg: string, kind: 'ok' | 'err' = 'ok') => {
|
||||
flash.value = msg
|
||||
flashKind.value = kind
|
||||
if (flashTimer) clearTimeout(flashTimer)
|
||||
flashTimer = setTimeout(() => {
|
||||
flash.value = ''
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
const loadLogs = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ logs: AuditLog[]; total: number; page: number }>('/api/admin/audit', {
|
||||
query: { page: 1, pageSize },
|
||||
})
|
||||
logs.value = data.logs
|
||||
total.value = data.total
|
||||
page.value = data.page
|
||||
} catch (err) {
|
||||
console.error('load audit error:', err)
|
||||
loadError.value = '加载失败,请重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const loadMore = async () => {
|
||||
if (loadingMore.value || logs.value.length >= total.value) return
|
||||
loadingMore.value = true
|
||||
try {
|
||||
const next = page.value + 1
|
||||
const data = await $fetch<{ logs: AuditLog[]; total: number; page: number }>('/api/admin/audit', {
|
||||
query: { page: next, pageSize },
|
||||
})
|
||||
logs.value.push(...data.logs)
|
||||
page.value = data.page
|
||||
} catch (err) {
|
||||
console.error('load more audit error:', err)
|
||||
showFlash('加载更多失败,请重试', 'err')
|
||||
} finally {
|
||||
loadingMore.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const clearing = ref(false)
|
||||
const clearLogs = async () => {
|
||||
if (!window.confirm('确定清空全部操作日志吗?此操作不可恢复。')) return
|
||||
clearing.value = true
|
||||
try {
|
||||
await $fetch('/api/admin/audit', { method: 'DELETE' })
|
||||
showFlash('日志已清空')
|
||||
await loadLogs()
|
||||
} catch (err) {
|
||||
console.error('clear audit error:', err)
|
||||
showFlash((err as any)?.data?.message || '清空失败,请重试', 'err')
|
||||
} finally {
|
||||
clearing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (raw?: string) => {
|
||||
if (!raw) return ''
|
||||
const d = new Date(String(raw).replace(' ', 'T') + 'Z')
|
||||
if (Number.isNaN(d.getTime())) return raw
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(d)
|
||||
}
|
||||
|
||||
onMounted(loadLogs)
|
||||
</script>
|
||||
@@ -41,7 +41,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<span class="text-sm text-gray-500">共 {{ comments.length }} 条评论</span>
|
||||
<span class="text-sm text-gray-500">共 {{ total }} 条评论</span>
|
||||
<template v-if="keyword">
|
||||
<span class="text-sm text-gray-400">· 匹配 {{ filteredComments.length }} 条</span>
|
||||
</template>
|
||||
@@ -122,6 +122,18 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<div v-if="comments.length < total" class="p-4 border-t border-gray-100 flex justify-center">
|
||||
<button
|
||||
@click="loadMore"
|
||||
:disabled="loadingMore"
|
||||
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 disabled:opacity-60 transition-colors"
|
||||
>
|
||||
<Icon v-if="loadingMore" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
{{ loadingMore ? '加载中…' : '加载更多' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -140,9 +152,13 @@ interface AdminComment {
|
||||
username: string
|
||||
}
|
||||
|
||||
const pageSize = 20
|
||||
const page = ref(0)
|
||||
const total = ref(0)
|
||||
const comments = ref<AdminComment[]>([])
|
||||
const keyword = ref('')
|
||||
const loading = ref(true)
|
||||
const loadingMore = ref(false)
|
||||
const loadError = ref('')
|
||||
|
||||
const filteredComments = computed(() => {
|
||||
@@ -169,8 +185,12 @@ const loadComments = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ comments: AdminComment[] }>('/api/admin/comments')
|
||||
const data = await $fetch<{ comments: AdminComment[]; total: number; page: number }>('/api/admin/comments', {
|
||||
query: { page: 1, pageSize },
|
||||
})
|
||||
comments.value = data.comments
|
||||
total.value = data.total
|
||||
page.value = data.page
|
||||
} catch (err) {
|
||||
console.error('load comments error:', err)
|
||||
loadError.value = '加载失败,请重试'
|
||||
@@ -179,11 +199,30 @@ const loadComments = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadMore = async () => {
|
||||
if (loadingMore.value || comments.value.length >= total.value) return
|
||||
loadingMore.value = true
|
||||
try {
|
||||
const next = page.value + 1
|
||||
const data = await $fetch<{ comments: AdminComment[]; total: number; page: number }>('/api/admin/comments', {
|
||||
query: { page: next, pageSize },
|
||||
})
|
||||
comments.value.push(...data.comments)
|
||||
page.value = data.page
|
||||
} catch (err) {
|
||||
console.error('load more comments error:', err)
|
||||
showFlash('加载更多失败,请重试', 'err')
|
||||
} finally {
|
||||
loadingMore.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeComment = async (c: AdminComment) => {
|
||||
if (!window.confirm('确定删除这条评论吗?此操作不可恢复。')) return
|
||||
try {
|
||||
await $fetch(`/api/admin/comments/${c.id}`, { method: 'DELETE' })
|
||||
comments.value = comments.value.filter((x) => x.id !== c.id)
|
||||
total.value = Math.max(0, total.value - 1)
|
||||
showFlash('评论已删除')
|
||||
} catch (err) {
|
||||
console.error('delete comment error:', err)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<span class="text-sm text-gray-500">共 {{ contacts.length }} 条消息</span>
|
||||
<span class="text-sm text-gray-400">· 已送达 {{ deliveredCount }} 条</span>
|
||||
<span class="text-sm text-gray-400">· 未读 {{ unreadCount }} 条</span>
|
||||
</div>
|
||||
|
||||
<!-- 加载中 -->
|
||||
@@ -80,6 +81,23 @@
|
||||
<Icon :name="Number(c.delivered) === 1 ? 'ph:check' : 'ph:clock'" class="w-3.5 h-3.5" />
|
||||
{{ Number(c.delivered) === 1 ? '已送达' : '未送达' }}
|
||||
</span>
|
||||
<span
|
||||
class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs"
|
||||
:class="Number(c.read) === 1 ? 'bg-gray-100 text-gray-500' : 'bg-black text-white font-bold'"
|
||||
>
|
||||
<Icon :name="Number(c.read) === 1 ? 'ph:envelope-open' : 'ph:envelope-simple'" class="w-3.5 h-3.5" />
|
||||
{{ Number(c.read) === 1 ? '已读' : '未读' }}
|
||||
</span>
|
||||
<button
|
||||
@click="toggleRead(c)"
|
||||
:disabled="togglingId === c.id"
|
||||
class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border text-xs font-semibold transition-colors disabled:opacity-50"
|
||||
:class="Number(c.read) === 1 ? 'border-gray-200 text-gray-500 hover:bg-gray-100' : 'border-black text-black hover:bg-black hover:text-white'"
|
||||
>
|
||||
<Icon v-if="togglingId === c.id" name="ph:circle-notch" class="w-3.5 h-3.5 animate-spin" />
|
||||
<Icon v-else :name="Number(c.read) === 1 ? 'ph:envelope-simple-open' : 'ph:check-circle'" class="w-3.5 h-3.5" />
|
||||
{{ Number(c.read) === 1 ? '标为未读' : '标为已读' }}
|
||||
</button>
|
||||
<button
|
||||
@click="removeContact(c)"
|
||||
class="w-8 h-8 rounded-full flex items-center justify-center text-gray-400 hover:bg-red-50 hover:text-red-600 transition-colors"
|
||||
@@ -111,6 +129,7 @@ interface AdminContact {
|
||||
subject: string
|
||||
message: string
|
||||
delivered: number
|
||||
read: number
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
@@ -119,6 +138,7 @@ const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
|
||||
const deliveredCount = computed(() => contacts.value.filter((c) => Number(c.delivered) === 1).length)
|
||||
const unreadCount = computed(() => contacts.value.filter((c) => Number(c.read) !== 1).length)
|
||||
|
||||
const flash = ref('')
|
||||
const flashKind = ref<'ok' | 'err'>('ok')
|
||||
@@ -146,6 +166,22 @@ const loadContacts = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const togglingId = ref<number | null>(null)
|
||||
const toggleRead = async (c: AdminContact) => {
|
||||
const next = Number(c.read) === 1 ? 0 : 1
|
||||
togglingId.value = c.id
|
||||
try {
|
||||
await $fetch(`/api/admin/contacts/${c.id}`, { method: 'PATCH', body: { read: next } })
|
||||
c.read = next
|
||||
showFlash(next === 1 ? '已标记为已读' : '已标记为未读')
|
||||
} catch (err) {
|
||||
console.error('toggle contact read error:', err)
|
||||
showFlash((err as any)?.data?.message || '操作失败,请重试', 'err')
|
||||
} finally {
|
||||
togglingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const removeContact = async (c: AdminContact) => {
|
||||
if (!window.confirm(`确定删除「${c.name}」的这条消息吗?此操作不可恢复。`)) return
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
<template>
|
||||
<section class="p-4 md:p-8 lg:p-10">
|
||||
<header class="mb-8 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-11 h-11 rounded-2xl bg-black text-white flex items-center justify-center flex-shrink-0">
|
||||
<Icon name="ph:image" class="w-6 h-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-black leading-tight">图片管理</h1>
|
||||
<p class="text-sm text-gray-500 mt-1">站点上传的图片文件,删除前请确认未被动态/作品引用。</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@click="loadFiles"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 rounded-full border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors flex-shrink-0"
|
||||
>
|
||||
<Icon name="ph:arrows-clockwise" class="w-4 h-4" />
|
||||
刷新
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<!-- 操作反馈 -->
|
||||
<div
|
||||
v-if="flash"
|
||||
class="mb-6 px-4 py-3 rounded-xl text-sm font-medium flex items-center gap-2"
|
||||
:class="flashKind === 'ok' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-red-50 text-red-700 border border-red-200'"
|
||||
>
|
||||
<Icon :name="flashKind === 'ok' ? 'ph:check-circle' : 'ph:warning-circle'" class="w-4 h-4" />
|
||||
{{ flash }}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<span class="text-sm text-gray-500">共 {{ files.length }} 张图片</span>
|
||||
</div>
|
||||
|
||||
<!-- 加载中 -->
|
||||
<div v-if="loading" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:circle-notch" class="w-8 h-8 animate-spin" />
|
||||
<p class="text-sm">加载中…</p>
|
||||
</div>
|
||||
|
||||
<!-- 加载失败 -->
|
||||
<div v-else-if="loadError" class="py-24 text-center">
|
||||
<div class="inline-flex flex-col items-center gap-3 text-gray-500">
|
||||
<Icon name="ph:warning-circle" class="w-8 h-8 text-red-500" />
|
||||
<p class="text-sm">{{ loadError }}</p>
|
||||
<button @click="loadFiles" class="px-5 py-2 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors">
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空态 -->
|
||||
<div v-else-if="!files.length" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:image" class="w-10 h-10" />
|
||||
<p class="text-sm">暂无图片</p>
|
||||
</div>
|
||||
|
||||
<!-- 图片网格 -->
|
||||
<div v-else class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4">
|
||||
<div
|
||||
v-for="f in files"
|
||||
:key="f.name"
|
||||
class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden group"
|
||||
>
|
||||
<div class="relative aspect-square bg-gray-50">
|
||||
<img :src="f.url" :alt="f.name" loading="lazy" class="w-full h-full object-cover" />
|
||||
<button
|
||||
@click="removeFile(f)"
|
||||
class="absolute top-2 right-2 w-8 h-8 rounded-full bg-black/60 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-600"
|
||||
title="删除图片"
|
||||
>
|
||||
<Icon name="ph:trash" class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="p-3">
|
||||
<p class="text-xs font-semibold text-gray-800 truncate" :title="f.name">{{ f.name }}</p>
|
||||
<div class="mt-1 flex items-center justify-between gap-2 text-[11px] text-gray-400">
|
||||
<span class="flex-shrink-0">{{ formatSize(f.size) }}</span>
|
||||
<span class="truncate">{{ formatDate(f.modified) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||||
useSeoMeta({ title: '图片管理' })
|
||||
|
||||
interface UploadFile {
|
||||
name: string
|
||||
size: number
|
||||
modified: string
|
||||
url: string
|
||||
}
|
||||
|
||||
const files = ref<UploadFile[]>([])
|
||||
const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
|
||||
const flash = ref('')
|
||||
const flashKind = ref<'ok' | 'err'>('ok')
|
||||
let flashTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const showFlash = (msg: string, kind: 'ok' | 'err' = 'ok') => {
|
||||
flash.value = msg
|
||||
flashKind.value = kind
|
||||
if (flashTimer) clearTimeout(flashTimer)
|
||||
flashTimer = setTimeout(() => {
|
||||
flash.value = ''
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
const loadFiles = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ files: UploadFile[] }>('/api/admin/uploads')
|
||||
files.value = data.files
|
||||
} catch (err) {
|
||||
console.error('load uploads error:', err)
|
||||
loadError.value = '加载失败,请重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeFile = async (f: UploadFile) => {
|
||||
if (!window.confirm(`确定删除图片「${f.name}」吗?此操作不可恢复。`)) return
|
||||
try {
|
||||
await $fetch(`/api/admin/uploads/${encodeURIComponent(f.name)}`, { method: 'DELETE' })
|
||||
files.value = files.value.filter((x) => x.name !== f.name)
|
||||
showFlash('已删除;如被内容引用请同步更新')
|
||||
} catch (err) {
|
||||
console.error('delete upload error:', err)
|
||||
showFlash((err as any)?.data?.message || '删除失败,请重试', 'err')
|
||||
}
|
||||
}
|
||||
|
||||
const formatSize = (bytes: number) => {
|
||||
if (!bytes && bytes !== 0) return ''
|
||||
if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
|
||||
return `${Math.max(1, Math.round(bytes / 1024))} KB`
|
||||
}
|
||||
|
||||
const formatDate = (raw?: string) => {
|
||||
if (!raw) return ''
|
||||
// 兼容 "YYYY-MM-DD HH:MM:SS"(UTC)与 ISO 两种格式
|
||||
const iso = String(raw).includes('T') ? String(raw) : String(raw).replace(' ', 'T') + 'Z'
|
||||
const d = new Date(iso)
|
||||
if (Number.isNaN(d.getTime())) return raw
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(d)
|
||||
}
|
||||
|
||||
onMounted(loadFiles)
|
||||
</script>
|
||||
@@ -151,7 +151,7 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useSeoMeta, createError } from '#imports'
|
||||
import { useSeoMeta, useHead, useRuntimeConfig, createError } from '#imports'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const route = useRoute()
|
||||
@@ -224,6 +224,30 @@ useSeoMeta({
|
||||
description: () => locText(article.value.excerptZh, article.value.excerptEn),
|
||||
})
|
||||
|
||||
// 文章 JSON-LD(Article schema,利于搜索引擎富摘要)
|
||||
const { public: publicCfg } = useRuntimeConfig()
|
||||
const siteBase = String(publicCfg.siteUrl || '').replace(/\/$/, '')
|
||||
useHead({
|
||||
script: [
|
||||
{
|
||||
type: 'application/ld+json',
|
||||
innerHTML: JSON.stringify({
|
||||
'@context': 'https://schema.org',
|
||||
'@type': 'Article',
|
||||
headline: title.value,
|
||||
description: locText(article.value.excerptZh, article.value.excerptEn),
|
||||
image: article.value.image || undefined,
|
||||
datePublished: article.value.date || undefined,
|
||||
author: { '@type': 'Organization', name: 'ArcticNewOne' },
|
||||
mainEntityOfPage: {
|
||||
'@type': 'WebPage',
|
||||
'@id': siteBase ? `${siteBase}/news/${slug}` : undefined,
|
||||
},
|
||||
}),
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// ---- 分享(真实动作) ----
|
||||
const copyFeedback = ref('')
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<template>
|
||||
<main class="min-h-screen flex items-center justify-center px-4 py-32">
|
||||
<div ref="cardRef" class="w-full max-w-md mx-auto p-10 rounded-3xl bg-white border border-gray-100 shadow-xl text-center">
|
||||
<div class="w-16 h-16 mx-auto rounded-full bg-gray-100 flex items-center justify-center mb-6">
|
||||
<Icon name="ph:envelope-simple-duotone" class="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-black mb-3">{{ t('unsubscribe.title') }}</h1>
|
||||
<p class="text-gray-500 mb-8">{{ t('unsubscribe.description') }}</p>
|
||||
|
||||
<!-- 处理中 -->
|
||||
<p v-if="status === 'processing'" class="text-gray-500 flex items-center justify-center gap-2">
|
||||
<Icon name="ph:circle-notch" class="w-5 h-5 animate-spin" />
|
||||
{{ t('unsubscribe.unsubscribe') }}
|
||||
</p>
|
||||
|
||||
<!-- 结果 -->
|
||||
<div v-else class="space-y-8">
|
||||
<p
|
||||
class="text-lg font-semibold"
|
||||
:class="status === 'unsubscribed' ? 'text-green-600' : 'text-gray-700'"
|
||||
>
|
||||
{{ resultText }}
|
||||
</p>
|
||||
<NuxtLink
|
||||
to="/"
|
||||
class="inline-block px-8 py-3 rounded-full bg-black text-white font-semibold hover:bg-gray-800 transition-colors"
|
||||
>
|
||||
{{ t('unsubscribe.backHome') }}
|
||||
</NuxtLink>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useSeoMeta } from '#imports'
|
||||
import gsap from 'gsap'
|
||||
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
|
||||
useSeoMeta({
|
||||
title: () => t('unsubscribe.title'),
|
||||
})
|
||||
|
||||
const status = ref<'processing' | 'unsubscribed' | 'already' | 'invalid'>('processing')
|
||||
|
||||
const resultText = computed(() => {
|
||||
if (status.value === 'unsubscribed') return t('unsubscribe.unsubscribed')
|
||||
if (status.value === 'already') return t('unsubscribe.already')
|
||||
return t('unsubscribe.invalid')
|
||||
})
|
||||
|
||||
const cardRef = ref<HTMLElement | null>(null)
|
||||
|
||||
onMounted(async () => {
|
||||
// 入场淡入(与其他公开页一致的轻量 GSAP 动画)
|
||||
if (cardRef.value) {
|
||||
gsap.fromTo(cardRef.value, { autoAlpha: 0, y: 24 }, { autoAlpha: 1, y: 0, duration: 0.6, ease: 'power3.out' })
|
||||
}
|
||||
|
||||
const token = route.query.token
|
||||
if (!token || Array.isArray(token)) {
|
||||
status.value = 'invalid'
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await $fetch<{ ok: boolean; unsubscribed: boolean }>('/api/newsletter/unsubscribe', {
|
||||
method: 'POST',
|
||||
body: { token },
|
||||
})
|
||||
status.value = data.unsubscribed ? 'unsubscribed' : 'already'
|
||||
} catch (err) {
|
||||
console.error('unsubscribe error:', err)
|
||||
status.value = 'invalid'
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -129,6 +129,38 @@
|
||||
<!-- 收藏 -->
|
||||
<FavoriteButton :work-slug="slug" />
|
||||
</div>
|
||||
|
||||
<!-- 分享 -->
|
||||
<div class="mt-8 pt-6 border-t border-gray-200">
|
||||
<p class="text-sm text-gray-500 mb-3">{{ t('share.article') }}</p>
|
||||
<div class="flex gap-3">
|
||||
<button
|
||||
@click="shareToX"
|
||||
class="w-10 h-10 rounded-full bg-white border border-gray-200 hover:bg-black hover:text-white hover:border-black flex items-center justify-center transition-all duration-300"
|
||||
:title="'X'"
|
||||
aria-label="Share on X"
|
||||
>
|
||||
<Icon name="ph:x-logo" class="w-5 h-5" />
|
||||
</button>
|
||||
<button
|
||||
@click="shareToLinkedIn"
|
||||
class="w-10 h-10 rounded-full bg-white border border-gray-200 hover:bg-black hover:text-white hover:border-black flex items-center justify-center transition-all duration-300"
|
||||
:title="'LinkedIn'"
|
||||
aria-label="Share on LinkedIn"
|
||||
>
|
||||
<Icon name="ph:linkedin-logo" class="w-5 h-5" />
|
||||
</button>
|
||||
<button
|
||||
@click="copyLink"
|
||||
class="w-10 h-10 rounded-full bg-white border border-gray-200 hover:bg-black hover:text-white hover:border-black flex items-center justify-center transition-all duration-300"
|
||||
:title="t('share.copy')"
|
||||
aria-label="Copy link"
|
||||
>
|
||||
<Icon name="ph:link" class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="copyFeedback" class="text-sm mt-3 text-green-600">{{ copyFeedback }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -160,7 +192,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useSeoMeta, createError } from '#imports'
|
||||
@@ -218,4 +250,31 @@ useSeoMeta({
|
||||
title: () => `${title.value} - ${t('work.title')}`,
|
||||
description: () => description.value,
|
||||
})
|
||||
|
||||
// ---- 分享(真实动作) ----
|
||||
const copyFeedback = ref('')
|
||||
|
||||
const shareUrl = () => (typeof window !== 'undefined' ? window.location.href : '')
|
||||
const shareText = () => title.value
|
||||
|
||||
const shareToX = () => {
|
||||
const url = `https://twitter.com/intent/tweet?url=${encodeURIComponent(shareUrl())}&text=${encodeURIComponent(shareText())}`
|
||||
window.open(url, '_blank', 'noopener,noreferrer,width=600,height=480')
|
||||
}
|
||||
|
||||
const shareToLinkedIn = () => {
|
||||
const url = `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareUrl())}`
|
||||
window.open(url, '_blank', 'noopener,noreferrer,width=600,height=480')
|
||||
}
|
||||
|
||||
const copyLink = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(shareUrl())
|
||||
copyFeedback.value = t('share.copied')
|
||||
} catch {
|
||||
// 剪贴板不可用时回退到 prompt 复制
|
||||
window.prompt(t('share.copyFailed'), shareUrl())
|
||||
}
|
||||
setTimeout(() => (copyFeedback.value = ''), 3000)
|
||||
}
|
||||
</script>
|
||||
|
||||
+40
-1
@@ -427,7 +427,30 @@
|
||||
"delivered": "Delivered to inbox",
|
||||
"notDelivered": "Not delivered (SMTP not configured)"
|
||||
},
|
||||
"adminEntry": "Admin Panel"
|
||||
"adminEntry": "Admin Panel",
|
||||
"changePassword": {
|
||||
"title": "Change Password",
|
||||
"currentPassword": "Current Password",
|
||||
"newPassword": "New Password",
|
||||
"confirmPassword": "Confirm New Password",
|
||||
"submit": "Update Password",
|
||||
"saving": "Updating...",
|
||||
"success": "Password updated",
|
||||
"failed": "Failed to update password",
|
||||
"wrongPassword": "Current password is incorrect",
|
||||
"tooShort": "New password must be at least 8 characters",
|
||||
"mismatch": "Passwords do not match"
|
||||
},
|
||||
"deleteAccount": {
|
||||
"title": "Delete Account",
|
||||
"hint": "This cannot be undone. Your comments and favorites will be removed.",
|
||||
"passwordPlaceholder": "Enter your password to confirm",
|
||||
"confirmButton": "Delete",
|
||||
"cancelButton": "Cancel",
|
||||
"success": "Account deleted",
|
||||
"wrongPassword": "Incorrect password",
|
||||
"confirmText": "Delete your account permanently? This cannot be undone."
|
||||
}
|
||||
},
|
||||
"comments": {
|
||||
"title": "Comments",
|
||||
@@ -466,5 +489,21 @@
|
||||
"subscribed": "Subscribed! Thank you for joining.",
|
||||
"alreadySubscribed": "You are already subscribed",
|
||||
"error": "Subscription failed. Please try again."
|
||||
},
|
||||
"error": {
|
||||
"title": "Something went wrong",
|
||||
"notFound": "Page not found",
|
||||
"serverError": "Server error",
|
||||
"generic": "An error occurred",
|
||||
"backHome": "Back to Home"
|
||||
},
|
||||
"unsubscribe": {
|
||||
"title": "Unsubscribe",
|
||||
"description": "Unsubscribe from ArcticNewOne newsletter:",
|
||||
"unsubscribe": "Unsubscribe",
|
||||
"unsubscribed": "You've been unsubscribed. Thanks for following along!",
|
||||
"already": "This address is no longer subscribed.",
|
||||
"invalid": "The unsubscribe link is invalid or has expired.",
|
||||
"backHome": "Back to Home"
|
||||
}
|
||||
}
|
||||
|
||||
+40
-1
@@ -427,7 +427,30 @@
|
||||
"delivered": "已送达邮箱",
|
||||
"notDelivered": "未送达(SMTP 未配置)"
|
||||
},
|
||||
"adminEntry": "进入后台管理"
|
||||
"adminEntry": "进入后台管理",
|
||||
"changePassword": {
|
||||
"title": "修改密码",
|
||||
"currentPassword": "当前密码",
|
||||
"newPassword": "新密码",
|
||||
"confirmPassword": "确认新密码",
|
||||
"submit": "确认修改",
|
||||
"saving": "提交中...",
|
||||
"success": "密码已修改",
|
||||
"failed": "修改失败,请重试",
|
||||
"wrongPassword": "当前密码不正确",
|
||||
"tooShort": "新密码至少需要 8 位",
|
||||
"mismatch": "两次输入的新密码不一致"
|
||||
},
|
||||
"deleteAccount": {
|
||||
"title": "删除账号",
|
||||
"hint": "删除后无法恢复,将同时清除你的评论与收藏。",
|
||||
"passwordPlaceholder": "输入当前密码确认",
|
||||
"confirmButton": "确认删除",
|
||||
"cancelButton": "取消",
|
||||
"success": "账号已删除",
|
||||
"wrongPassword": "密码不正确",
|
||||
"confirmText": "确定要永久删除账号吗?此操作不可撤销。"
|
||||
}
|
||||
},
|
||||
"comments": {
|
||||
"title": "评论",
|
||||
@@ -466,5 +489,21 @@
|
||||
"subscribed": "订阅成功,感谢关注!",
|
||||
"alreadySubscribed": "您已在订阅列表中",
|
||||
"error": "订阅失败,请稍后再试"
|
||||
},
|
||||
"error": {
|
||||
"title": "出了点问题",
|
||||
"notFound": "页面不存在",
|
||||
"serverError": "服务器开小差了",
|
||||
"generic": "发生了一个错误",
|
||||
"backHome": "返回首页"
|
||||
},
|
||||
"unsubscribe": {
|
||||
"title": "退订",
|
||||
"description": "确认退订 ArcticNewOne 资讯邮件:",
|
||||
"unsubscribe": "确认退订",
|
||||
"unsubscribed": "已成功退订。感谢你曾经的关注!",
|
||||
"already": "该地址已不在订阅列表中。",
|
||||
"invalid": "退订链接无效或已失效。",
|
||||
"backHome": "返回首页"
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -8,7 +8,8 @@
|
||||
"generate": "nuxt generate",
|
||||
"preview": "nuxt preview",
|
||||
"postinstall": "nuxt prepare",
|
||||
"start": "node .output/server/index.mjs"
|
||||
"start": "node .output/server/index.mjs",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nuxt/hints": "1.0.3",
|
||||
@@ -28,6 +29,7 @@
|
||||
"@iconify-json/ph": "1.2.2",
|
||||
"@nuxtjs/tailwindcss": "6.14.0",
|
||||
"@types/better-sqlite3": "^7.6.13",
|
||||
"@types/nodemailer": "^6.4.17"
|
||||
"@types/nodemailer": "^6.4.17",
|
||||
"vitest": "^4.1.10"
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+214
-4
@@ -10,7 +10,7 @@ importers:
|
||||
dependencies:
|
||||
'@nuxt/hints':
|
||||
specifier: 1.0.3
|
||||
version: 1.0.3(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)(better-sqlite3@13.0.2)(db0@0.3.4(better-sqlite3@13.0.2))(ioredis@5.10.1(supports-color@10.2.2))(magicast@0.5.2)(srvx@0.11.15)(supports-color@10.2.2)(typescript@6.0.3)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))(vue@3.5.33(typescript@6.0.3))
|
||||
version: 1.0.3(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)(better-sqlite3@13.0.2)(db0@0.3.4(better-sqlite3@13.0.2))(ioredis@5.10.1(supports-color@10.2.2))(magicast@0.5.2)(srvx@0.11.15)(supports-color@10.2.2)(typescript@6.0.3)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))(vitest@4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)))(vue@3.5.33(typescript@6.0.3))
|
||||
'@nuxt/icon':
|
||||
specifier: 2.2.1
|
||||
version: 2.2.1(magicast@0.5.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))(vue@3.5.33(typescript@6.0.3))
|
||||
@@ -57,6 +57,9 @@ importers:
|
||||
'@types/nodemailer':
|
||||
specifier: ^6.4.17
|
||||
version: 6.4.24
|
||||
vitest:
|
||||
specifier: ^4.1.10
|
||||
version: 4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))
|
||||
|
||||
packages:
|
||||
|
||||
@@ -2005,12 +2008,21 @@ packages:
|
||||
'@speed-highlight/core@1.2.15':
|
||||
resolution: {integrity: sha512-BMq1K3DsElxDWawkX6eLg9+CKJrTVGCBAWVuHXVUV2u0s2711qiChLSId6ikYPfxhdYocLNt3wWwSvDiTvFabw==}
|
||||
|
||||
'@standard-schema/spec@1.1.0':
|
||||
resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==}
|
||||
|
||||
'@tybys/wasm-util@0.10.1':
|
||||
resolution: {integrity: sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==}
|
||||
|
||||
'@types/better-sqlite3@7.6.13':
|
||||
resolution: {integrity: sha512-NMv9ASNARoKksWtsq/SHakpYAYnhBrQgGD8zkLYk/jaK8jUGn08CfEdTRgYhMypUQAfzSP8W6gNLe0q19/t4VA==}
|
||||
|
||||
'@types/chai@5.2.3':
|
||||
resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==}
|
||||
|
||||
'@types/deep-eql@4.0.2':
|
||||
resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
|
||||
|
||||
'@types/esrecurse@4.3.1':
|
||||
resolution: {integrity: sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==}
|
||||
|
||||
@@ -2086,6 +2098,35 @@ packages:
|
||||
vite: ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
vue: ^3.2.25
|
||||
|
||||
'@vitest/expect@4.1.10':
|
||||
resolution: {integrity: sha512-YsCn+qAk1GWjQOWFEsEcL2gNQ0zmVmQu3T03qP6UyjhtmdtwtbuI+DASn/7iQB3HGTXkdBwGddzxPlmiql5vlA==}
|
||||
|
||||
'@vitest/mocker@4.1.10':
|
||||
resolution: {integrity: sha512-v0xaezt+DKEmKfaxg133ldzADrwLGd7Ze1MfQQTYfvs8OqZIwbxyxaYURivwV7sWy5fqn3rH5uOrSp07bp44Ow==}
|
||||
peerDependencies:
|
||||
msw: ^2.4.9
|
||||
vite: ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
peerDependenciesMeta:
|
||||
msw:
|
||||
optional: true
|
||||
vite:
|
||||
optional: true
|
||||
|
||||
'@vitest/pretty-format@4.1.10':
|
||||
resolution: {integrity: sha512-W1HsjSH4MXQ9YfmmhLAoIYf1HRfekQCGngeIgcei6MP5QQGWUe0gkopdZQaVCFO+JDJMrAJGwa5pRpNpvy4P8Q==}
|
||||
|
||||
'@vitest/runner@4.1.10':
|
||||
resolution: {integrity: sha512-IKI6kpIH+LmpROplyLwBBaCfMgOZOMsygVa6BARD6ahA04VRuJSa6OaVG7kRvSEMD870Vd91rSSw0eegtWyLGg==}
|
||||
|
||||
'@vitest/snapshot@4.1.10':
|
||||
resolution: {integrity: sha512-xRkfOT1qpTAi/Ti4Y1LtfRc3kEuqxGw59eN2jN9pRWMtS/XDevekhcFSqvQqjUNGksfjMJu3Y+oJ+4Ypn2OaJw==}
|
||||
|
||||
'@vitest/spy@4.1.10':
|
||||
resolution: {integrity: sha512-PLf/Ugvoq5wO/b4rwYCR1h2PSIdXz7wnkQFMiUpLdtM7l6pqVFcQIBEHyT1+l+cj7mNwAfZHzqXqDyjvOuwbDw==}
|
||||
|
||||
'@vitest/utils@4.1.10':
|
||||
resolution: {integrity: sha512-fy9am/HWxbaGt/Sawrp90vt6Y6jQwf1RX77cz3uwoJwJVMli/e1IEwRPnMNJ7vKfPTwo0diXifkpPvwH9v7nGA==}
|
||||
|
||||
'@vue-macros/common@3.1.2':
|
||||
resolution: {integrity: sha512-h9t4ArDdniO9ekYHAD95t9AZcAbb19lEGK+26iAjUODOIJKmObDNBSe4+6ELQAA3vtYiFPPBtHh7+cQCKi3Dng==}
|
||||
engines: {node: '>=20.19.0'}
|
||||
@@ -2244,6 +2285,10 @@ packages:
|
||||
argparse@2.0.1:
|
||||
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
||||
|
||||
assertion-error@2.0.1:
|
||||
resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
ast-kit@2.2.0:
|
||||
resolution: {integrity: sha512-m1Q/RaVOnTp9JxPX+F+Zn7IcLYMzM8kZofDImfsKZd8MbR+ikdOzTeztStWqfrqIxZnYWryyI9ePm3NGjnZgGw==}
|
||||
engines: {node: '>=20.19.0'}
|
||||
@@ -2420,6 +2465,10 @@ packages:
|
||||
caniuse-lite@1.0.30001790:
|
||||
resolution: {integrity: sha512-bOoxfJPyYo+ds6W0YfptaCWbFnJYjh2Y1Eow5lRv+vI2u8ganPZqNm1JwNh0t2ELQCqIWg4B3dWEusgAmsoyOw==}
|
||||
|
||||
chai@6.2.2:
|
||||
resolution: {integrity: sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
chalk@4.1.2:
|
||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -2913,6 +2962,10 @@ packages:
|
||||
resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==}
|
||||
engines: {node: '>=16.17'}
|
||||
|
||||
expect-type@1.4.0:
|
||||
resolution: {integrity: sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
exsolve@1.0.8:
|
||||
resolution: {integrity: sha512-LmDxfWXwcTArk8fUEnOfSZpHOJ6zOMUJKOtFLFqJLoKJetuQG874Uc7/Kki7zFLzYybmZhp1M7+98pfMqeX8yA==}
|
||||
|
||||
@@ -4313,6 +4366,9 @@ packages:
|
||||
resolution: {integrity: sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
siginfo@2.0.0:
|
||||
resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==}
|
||||
|
||||
signal-exit@4.1.0:
|
||||
resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==}
|
||||
engines: {node: '>=14'}
|
||||
@@ -4359,6 +4415,9 @@ packages:
|
||||
engines: {node: '>=20.16.0'}
|
||||
hasBin: true
|
||||
|
||||
stackback@0.0.2:
|
||||
resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==}
|
||||
|
||||
standard-as-callback@2.1.0:
|
||||
resolution: {integrity: sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A==}
|
||||
|
||||
@@ -4495,6 +4554,9 @@ packages:
|
||||
tiny-invariant@1.3.3:
|
||||
resolution: {integrity: sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==}
|
||||
|
||||
tinybench@2.9.0:
|
||||
resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==}
|
||||
|
||||
tinyclip@0.1.12:
|
||||
resolution: {integrity: sha512-Ae3OVUqifDw0wBriIBS7yVaW44Dp6eSHQcyq4Igc7eN2TJH/2YsicswaW+J/OuMvhpDPOKEgpAZCjkb4hpoyeA==}
|
||||
engines: {node: ^16.14.0 || >= 17.3.0}
|
||||
@@ -4507,6 +4569,10 @@ packages:
|
||||
resolution: {integrity: sha512-pn99VhoACYR8nFHhxqix+uvsbXineAasWm5ojXoN8xEwK5Kd3/TrhNn1wByuD52UxWRLy8pu+kRMniEi6Eq9Zg==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
tinyrainbow@3.1.1:
|
||||
resolution: {integrity: sha512-yau8yJdTt989Mm0Bd/236QnzEiPf2xLLTqUZRUJOo/3CB078LSwzei343DgtJVmfJKJE3TMINY1u42SQsP6mXw==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
|
||||
to-regex-range@5.0.1:
|
||||
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
|
||||
engines: {node: '>=8.0'}
|
||||
@@ -4822,6 +4888,47 @@ packages:
|
||||
yaml:
|
||||
optional: true
|
||||
|
||||
vitest@4.1.10:
|
||||
resolution: {integrity: sha512-R9jUTe5S4Qb0HCd4TNqpC7oGcrMssMRGXLW80ubjWsW9VH5GF8y1Y0SFLY9AbqSk6nt0PnOx4H4WNJYZ13GUPw==}
|
||||
engines: {node: ^20.0.0 || ^22.0.0 || >=24.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@edge-runtime/vm': '*'
|
||||
'@opentelemetry/api': ^1.9.0
|
||||
'@types/node': ^20.0.0 || ^22.0.0 || >=24.0.0
|
||||
'@vitest/browser-playwright': 4.1.10
|
||||
'@vitest/browser-preview': 4.1.10
|
||||
'@vitest/browser-webdriverio': 4.1.10
|
||||
'@vitest/coverage-istanbul': 4.1.10
|
||||
'@vitest/coverage-v8': 4.1.10
|
||||
'@vitest/ui': 4.1.10
|
||||
happy-dom: '*'
|
||||
jsdom: '*'
|
||||
vite: ^6.0.0 || ^7.0.0 || ^8.0.0
|
||||
peerDependenciesMeta:
|
||||
'@edge-runtime/vm':
|
||||
optional: true
|
||||
'@opentelemetry/api':
|
||||
optional: true
|
||||
'@types/node':
|
||||
optional: true
|
||||
'@vitest/browser-playwright':
|
||||
optional: true
|
||||
'@vitest/browser-preview':
|
||||
optional: true
|
||||
'@vitest/browser-webdriverio':
|
||||
optional: true
|
||||
'@vitest/coverage-istanbul':
|
||||
optional: true
|
||||
'@vitest/coverage-v8':
|
||||
optional: true
|
||||
'@vitest/ui':
|
||||
optional: true
|
||||
happy-dom:
|
||||
optional: true
|
||||
jsdom:
|
||||
optional: true
|
||||
|
||||
vscode-uri@3.1.0:
|
||||
resolution: {integrity: sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ==}
|
||||
|
||||
@@ -4882,6 +4989,11 @@ packages:
|
||||
engines: {node: ^20.17.0 || >=22.9.0}
|
||||
hasBin: true
|
||||
|
||||
why-is-node-running@2.3.0:
|
||||
resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==}
|
||||
engines: {node: '>=8'}
|
||||
hasBin: true
|
||||
|
||||
word-wrap@1.2.5:
|
||||
resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -5710,7 +5822,7 @@ snapshots:
|
||||
- utf-8-validate
|
||||
- vue
|
||||
|
||||
'@nuxt/hints@1.0.3(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)(better-sqlite3@13.0.2)(db0@0.3.4(better-sqlite3@13.0.2))(ioredis@5.10.1(supports-color@10.2.2))(magicast@0.5.2)(srvx@0.11.15)(supports-color@10.2.2)(typescript@6.0.3)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))(vue@3.5.33(typescript@6.0.3))':
|
||||
'@nuxt/hints@1.0.3(@emnapi/core@1.10.0)(@emnapi/runtime@1.10.0)(better-sqlite3@13.0.2)(db0@0.3.4(better-sqlite3@13.0.2))(ioredis@5.10.1(supports-color@10.2.2))(magicast@0.5.2)(srvx@0.11.15)(supports-color@10.2.2)(typescript@6.0.3)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))(vitest@4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)))(vue@3.5.33(typescript@6.0.3))':
|
||||
dependencies:
|
||||
'@nuxt/devtools-kit': 3.2.4(magicast@0.5.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))
|
||||
'@nuxt/kit': 4.4.2(magicast@0.5.2)
|
||||
@@ -5718,7 +5830,7 @@ snapshots:
|
||||
defu: 6.1.7
|
||||
devalue: 5.7.1
|
||||
h3: 1.15.11
|
||||
html-validate: 10.13.1
|
||||
html-validate: 10.13.1(vitest@4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)))
|
||||
knitwork: 1.3.0
|
||||
magic-string: 0.30.21
|
||||
nitropack: 2.13.3(better-sqlite3@13.0.2)(srvx@0.11.15)(supports-color@10.2.2)
|
||||
@@ -6733,6 +6845,8 @@ snapshots:
|
||||
|
||||
'@speed-highlight/core@1.2.15': {}
|
||||
|
||||
'@standard-schema/spec@1.1.0': {}
|
||||
|
||||
'@tybys/wasm-util@0.10.1':
|
||||
dependencies:
|
||||
tslib: 2.8.1
|
||||
@@ -6742,6 +6856,13 @@ snapshots:
|
||||
dependencies:
|
||||
'@types/node': 26.1.2
|
||||
|
||||
'@types/chai@5.2.3':
|
||||
dependencies:
|
||||
'@types/deep-eql': 4.0.2
|
||||
assertion-error: 2.0.1
|
||||
|
||||
'@types/deep-eql@4.0.2': {}
|
||||
|
||||
'@types/esrecurse@4.3.1': {}
|
||||
|
||||
'@types/estree@1.0.8': {}
|
||||
@@ -6843,6 +6964,47 @@ snapshots:
|
||||
vite: 7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)
|
||||
vue: 3.5.33(typescript@6.0.3)
|
||||
|
||||
'@vitest/expect@4.1.10':
|
||||
dependencies:
|
||||
'@standard-schema/spec': 1.1.0
|
||||
'@types/chai': 5.2.3
|
||||
'@vitest/spy': 4.1.10
|
||||
'@vitest/utils': 4.1.10
|
||||
chai: 6.2.2
|
||||
tinyrainbow: 3.1.1
|
||||
|
||||
'@vitest/mocker@4.1.10(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))':
|
||||
dependencies:
|
||||
'@vitest/spy': 4.1.10
|
||||
estree-walker: 3.0.3
|
||||
magic-string: 0.30.21
|
||||
optionalDependencies:
|
||||
vite: 7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)
|
||||
|
||||
'@vitest/pretty-format@4.1.10':
|
||||
dependencies:
|
||||
tinyrainbow: 3.1.1
|
||||
|
||||
'@vitest/runner@4.1.10':
|
||||
dependencies:
|
||||
'@vitest/utils': 4.1.10
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/snapshot@4.1.10':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 4.1.10
|
||||
'@vitest/utils': 4.1.10
|
||||
magic-string: 0.30.21
|
||||
pathe: 2.0.3
|
||||
|
||||
'@vitest/spy@4.1.10': {}
|
||||
|
||||
'@vitest/utils@4.1.10':
|
||||
dependencies:
|
||||
'@vitest/pretty-format': 4.1.10
|
||||
convert-source-map: 2.0.0
|
||||
tinyrainbow: 3.1.1
|
||||
|
||||
'@vue-macros/common@3.1.2(vue@3.5.33(typescript@6.0.3))':
|
||||
dependencies:
|
||||
'@vue/compiler-sfc': 3.5.33
|
||||
@@ -7059,6 +7221,8 @@ snapshots:
|
||||
|
||||
argparse@2.0.1: {}
|
||||
|
||||
assertion-error@2.0.1: {}
|
||||
|
||||
ast-kit@2.2.0:
|
||||
dependencies:
|
||||
'@babel/parser': 7.29.2
|
||||
@@ -7225,6 +7389,8 @@ snapshots:
|
||||
|
||||
caniuse-lite@1.0.30001790: {}
|
||||
|
||||
chai@6.2.2: {}
|
||||
|
||||
chalk@4.1.2:
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
@@ -7733,6 +7899,8 @@ snapshots:
|
||||
signal-exit: 4.1.0
|
||||
strip-final-newline: 3.0.0
|
||||
|
||||
expect-type@1.4.0: {}
|
||||
|
||||
exsolve@1.0.8: {}
|
||||
|
||||
exsolve@1.1.1: {}
|
||||
@@ -7941,7 +8109,7 @@ snapshots:
|
||||
|
||||
hookable@6.1.1: {}
|
||||
|
||||
html-validate@10.13.1:
|
||||
html-validate@10.13.1(vitest@4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))):
|
||||
dependencies:
|
||||
'@html-validate/stylish': 5.2.0
|
||||
'@sidvind/better-ajv-errors': 5.0.0(ajv@8.20.0)
|
||||
@@ -7951,6 +8119,8 @@ snapshots:
|
||||
minimist: 1.2.8
|
||||
prompts: 2.4.2
|
||||
semver: 7.7.4
|
||||
optionalDependencies:
|
||||
vitest: 4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))
|
||||
|
||||
http-assert@1.5.0:
|
||||
dependencies:
|
||||
@@ -9433,6 +9603,8 @@ snapshots:
|
||||
|
||||
shell-quote@1.8.3: {}
|
||||
|
||||
siginfo@2.0.0: {}
|
||||
|
||||
signal-exit@4.1.0: {}
|
||||
|
||||
simple-git@3.36.0(supports-color@10.2.2):
|
||||
@@ -9472,6 +9644,8 @@ snapshots:
|
||||
|
||||
srvx@0.11.15: {}
|
||||
|
||||
stackback@0.0.2: {}
|
||||
|
||||
standard-as-callback@2.1.0: {}
|
||||
|
||||
statuses@1.5.0: {}
|
||||
@@ -9669,6 +9843,8 @@ snapshots:
|
||||
|
||||
tiny-invariant@1.3.3: {}
|
||||
|
||||
tinybench@2.9.0: {}
|
||||
|
||||
tinyclip@0.1.12: {}
|
||||
|
||||
tinyexec@1.1.1: {}
|
||||
@@ -9678,6 +9854,8 @@ snapshots:
|
||||
fdir: 6.5.0(picomatch@4.0.4)
|
||||
picomatch: 4.0.4
|
||||
|
||||
tinyrainbow@3.1.1: {}
|
||||
|
||||
to-regex-range@5.0.1:
|
||||
dependencies:
|
||||
is-number: 7.0.0
|
||||
@@ -9932,6 +10110,33 @@ snapshots:
|
||||
terser: 5.46.2
|
||||
yaml: 2.8.3
|
||||
|
||||
vitest@4.1.10(@types/node@26.1.2)(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)):
|
||||
dependencies:
|
||||
'@vitest/expect': 4.1.10
|
||||
'@vitest/mocker': 4.1.10(vite@7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3))
|
||||
'@vitest/pretty-format': 4.1.10
|
||||
'@vitest/runner': 4.1.10
|
||||
'@vitest/snapshot': 4.1.10
|
||||
'@vitest/spy': 4.1.10
|
||||
'@vitest/utils': 4.1.10
|
||||
es-module-lexer: 2.1.0
|
||||
expect-type: 1.4.0
|
||||
magic-string: 0.30.21
|
||||
obug: 2.1.1
|
||||
pathe: 2.0.3
|
||||
picomatch: 4.0.4
|
||||
std-env: 4.1.0
|
||||
tinybench: 2.9.0
|
||||
tinyexec: 1.1.1
|
||||
tinyglobby: 0.2.16
|
||||
tinyrainbow: 3.1.1
|
||||
vite: 7.3.2(@types/node@26.1.2)(jiti@2.6.1)(terser@5.46.2)(yaml@2.8.3)
|
||||
why-is-node-running: 2.3.0
|
||||
optionalDependencies:
|
||||
'@types/node': 26.1.2
|
||||
transitivePeerDependencies:
|
||||
- msw
|
||||
|
||||
vscode-uri@3.1.0: {}
|
||||
|
||||
vue-bundle-renderer@2.2.0:
|
||||
@@ -10001,6 +10206,11 @@ snapshots:
|
||||
dependencies:
|
||||
isexe: 4.0.0
|
||||
|
||||
why-is-node-running@2.3.0:
|
||||
dependencies:
|
||||
siginfo: 2.0.0
|
||||
stackback: 0.0.2
|
||||
|
||||
word-wrap@1.2.5: {}
|
||||
|
||||
wrap-ansi@7.0.0:
|
||||
|
||||
@@ -2,6 +2,7 @@ import { readBody, createError } from 'h3'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getDb } from '../../utils/db'
|
||||
import { getArticleBySlug } from '../../utils/content'
|
||||
import { writeAudit } from '../../utils/audit'
|
||||
import { normalizeSlug, isValidSlug, isValidArticleCategory, normalizeBlocks } from '../../utils/validateContent'
|
||||
|
||||
/**
|
||||
@@ -48,5 +49,7 @@ export default defineEventHandler(async (event) => {
|
||||
body?.published ? 1 : 0,
|
||||
)
|
||||
|
||||
writeAudit(event, 'create', `article:${slug}`)
|
||||
|
||||
return { ok: true, article: getArticleBySlug(slug, { publishedOnly: false }) }
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台删除动态(连带删除其评论)
|
||||
@@ -21,5 +22,6 @@ export default defineEventHandler((event) => {
|
||||
})
|
||||
tx()
|
||||
|
||||
writeAudit(event, 'delete', `article:${row.slug}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { getArticleBySlug } from '../../../utils/content'
|
||||
import { normalizeSlug, isValidSlug, isValidArticleCategory, normalizeBlocks } from '../../../utils/validateContent'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台更新动态(部分字段)
|
||||
@@ -69,6 +70,7 @@ export default defineEventHandler(async (event) => {
|
||||
db.prepare(`UPDATE articles SET ${sets.join(', ')} WHERE id = ?`).run(...params, id)
|
||||
|
||||
const row = db.prepare('SELECT slug FROM articles WHERE id = ?').get(id) as { slug: string }
|
||||
writeAudit(event, 'update', `article:${id}`)
|
||||
return { ok: true, article: getArticleBySlug(row.slug, { publishedOnly: false }) }
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getDb } from '../../utils/db'
|
||||
import { writeAudit } from '../../utils/audit'
|
||||
|
||||
/**
|
||||
* 清空审计日志
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
getDb().prepare('DELETE FROM audit_logs').run()
|
||||
writeAudit(event, 'clear', 'audit')
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
import { getQuery } from 'h3'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getDb } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 后台操作审计日志(分页)
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const q = getQuery(event)
|
||||
const page = Math.max(1, Number(q?.page) || 1)
|
||||
const pageSize = Math.min(100, Math.max(1, Number(q?.pageSize) || 20))
|
||||
|
||||
const db = getDb()
|
||||
const total = (db.prepare('SELECT COUNT(*) AS c FROM audit_logs').get() as { c: number }).c
|
||||
const logs = db
|
||||
.prepare(
|
||||
`SELECT id, actor_id, actor_name, action, target, detail, created_at AS createdAt
|
||||
FROM audit_logs ORDER BY created_at DESC LIMIT ? OFFSET ?`,
|
||||
)
|
||||
.all(pageSize, (page - 1) * pageSize)
|
||||
|
||||
return { logs, total, page, pageSize }
|
||||
})
|
||||
@@ -1,18 +1,26 @@
|
||||
import { getQuery } from 'h3'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getDb } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 后台全站评论列表(含文章 slug 与作者)
|
||||
* 后台全站评论列表(分页)
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const comments = getDb()
|
||||
const q = getQuery(event)
|
||||
const page = Math.max(1, Number(q?.page) || 1)
|
||||
const pageSize = Math.min(100, Math.max(1, Number(q?.pageSize) || 20))
|
||||
|
||||
const db = getDb()
|
||||
const total = (db.prepare('SELECT COUNT(*) AS c FROM comments').get() as { c: number }).c
|
||||
const comments = db
|
||||
.prepare(
|
||||
`SELECT c.id, c.news_slug AS newsSlug, c.content, c.created_at AS createdAt, u.username
|
||||
FROM comments c
|
||||
JOIN users u ON u.id = c.user_id
|
||||
ORDER BY c.created_at DESC`,
|
||||
ORDER BY c.created_at DESC LIMIT ? OFFSET ?`,
|
||||
)
|
||||
.all()
|
||||
return { comments }
|
||||
.all(pageSize, (page - 1) * pageSize)
|
||||
|
||||
return { comments, total, page, pageSize }
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台删除评论
|
||||
@@ -14,5 +15,6 @@ export default defineEventHandler((event) => {
|
||||
throw createError({ statusCode: 404, message: '评论不存在', data: { code: 'NOT_FOUND' } })
|
||||
}
|
||||
db.prepare('DELETE FROM comments WHERE id = ?').run(id)
|
||||
writeAudit(event, 'delete', `comment:${id}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getDb } from '../../utils/db'
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const contacts = getDb()
|
||||
.prepare('SELECT id, name, email, subject, message, delivered, created_at AS createdAt FROM contacts ORDER BY created_at DESC')
|
||||
.prepare('SELECT id, name, email, subject, message, delivered, read, created_at AS createdAt FROM contacts ORDER BY created_at DESC')
|
||||
.all()
|
||||
return { contacts }
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台删除联系消息
|
||||
@@ -14,5 +15,6 @@ export default defineEventHandler((event) => {
|
||||
throw createError({ statusCode: 404, message: '消息不存在', data: { code: 'NOT_FOUND' } })
|
||||
}
|
||||
db.prepare('DELETE FROM contacts WHERE id = ?').run(id)
|
||||
writeAudit(event, 'delete', `contact:${id}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { readBody, createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台更新联系消息(已读/未读标记)
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
requireAdmin(event)
|
||||
const id = Number(getRouterParam(event, 'id'))
|
||||
const body = await readBody(event)
|
||||
const db = getDb()
|
||||
|
||||
const target = db.prepare('SELECT id FROM contacts WHERE id = ?').get(id)
|
||||
if (!target) {
|
||||
throw createError({ statusCode: 404, message: '消息不存在', data: { code: 'NOT_FOUND' } })
|
||||
}
|
||||
|
||||
if (body?.read !== undefined) {
|
||||
db.prepare('UPDATE contacts SET read = ? WHERE id = ?').run(body.read ? 1 : 0, id)
|
||||
writeAudit(event, 'update', `contact:${id}`, `read=${body.read ? 1 : 0}`)
|
||||
}
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台删除订阅
|
||||
@@ -14,5 +15,6 @@ export default defineEventHandler((event) => {
|
||||
throw createError({ statusCode: 404, message: '订阅不存在', data: { code: 'NOT_FOUND' } })
|
||||
}
|
||||
db.prepare('DELETE FROM subscribers WHERE id = ?').run(id)
|
||||
writeAudit(event, 'delete', `subscriber:${id}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import { dirname, join } from 'node:path'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getConfig } from '../../utils/config'
|
||||
import { writeAudit } from '../../utils/audit'
|
||||
|
||||
const MAX_SIZE = 8 * 1024 * 1024 // 8MB
|
||||
const EXT_BY_TYPE: Record<string, string> = {
|
||||
@@ -42,5 +43,6 @@ export default defineEventHandler(async (event) => {
|
||||
mkdirSync(dir, { recursive: true })
|
||||
writeFileSync(join(dir, name), file.data)
|
||||
|
||||
writeAudit(event, 'upload', `upload:${name}`)
|
||||
return { ok: true, url: `/uploads/${name}` }
|
||||
})
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getConfig } from '../../utils/config'
|
||||
import { readdirSync, statSync } from 'node:fs'
|
||||
import { join, dirname } from 'node:path'
|
||||
|
||||
/**
|
||||
* 后台图片管理:列出 /data/uploads 下的文件
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const dir = join(dirname(getConfig().dbPath), 'uploads')
|
||||
|
||||
const files: Array<{ name: string; size: number; modified: string; url: string }> = []
|
||||
try {
|
||||
for (const name of readdirSync(dir)) {
|
||||
const p = join(dir, name)
|
||||
const st = statSync(p)
|
||||
if (!st.isFile()) continue
|
||||
files.push({ name, size: st.size, modified: st.mtime.toISOString(), url: `/uploads/${name}` })
|
||||
}
|
||||
} catch {
|
||||
// 目录可能尚不存在
|
||||
}
|
||||
|
||||
files.sort((a, b) => b.modified.localeCompare(a.modified))
|
||||
return { files }
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { createError } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getConfig } from '../../../utils/config'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
import { unlinkSync, existsSync } from 'node:fs'
|
||||
import { join, dirname } from 'node:path'
|
||||
|
||||
/**
|
||||
* 后台删除上传的图片
|
||||
*/
|
||||
export default defineEventHandler((event) => {
|
||||
requireAdmin(event)
|
||||
const name = getRouterParam(event, 'name') ?? ''
|
||||
|
||||
// 防目录穿越:仅允许纯文件名
|
||||
if (!name || name.includes('/') || name.includes('\\') || name.includes('..')) {
|
||||
throw createError({ statusCode: 400, message: '非法文件名', data: { code: 'VALIDATION_ERROR' } })
|
||||
}
|
||||
|
||||
const filePath = join(dirname(getConfig().dbPath), 'uploads', name)
|
||||
if (!existsSync(filePath)) {
|
||||
throw createError({ statusCode: 404, message: '文件不存在', data: { code: 'NOT_FOUND' } })
|
||||
}
|
||||
|
||||
unlinkSync(filePath)
|
||||
writeAudit(event, 'delete', `upload:${name}`)
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台删除用户(连带删除其会话/评论/收藏)
|
||||
@@ -18,5 +19,6 @@ export default defineEventHandler((event) => {
|
||||
throw createError({ statusCode: 404, message: '用户不存在', data: { code: 'NOT_FOUND' } })
|
||||
}
|
||||
db.prepare('DELETE FROM users WHERE id = ?').run(id) // 外键级联:sessions/comments/favorites
|
||||
writeAudit(event, 'delete', `user:${id}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { readBody, createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台更新用户(角色切换)
|
||||
@@ -24,5 +25,6 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
db.prepare('UPDATE users SET role = ? WHERE id = ?').run(body.role, id)
|
||||
}
|
||||
writeAudit(event, 'update', `user:${id}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import { readBody, createError } from 'h3'
|
||||
import { requireAdmin } from '../../utils/auth'
|
||||
import { getDb } from '../../utils/db'
|
||||
import { getWorkBySlug } from '../../utils/content'
|
||||
import { writeAudit } from '../../utils/audit'
|
||||
import {
|
||||
normalizeSlug,
|
||||
isValidSlug,
|
||||
@@ -65,5 +66,6 @@ export default defineEventHandler(async (event) => {
|
||||
body?.published ? 1 : 0,
|
||||
)
|
||||
|
||||
writeAudit(event, 'create', `work:${slug}`)
|
||||
return { ok: true, work: getWorkBySlug(slug, { publishedOnly: false }) }
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
|
||||
/**
|
||||
* 后台删除作品(连带清理用户收藏)
|
||||
@@ -21,5 +22,6 @@ export default defineEventHandler((event) => {
|
||||
})
|
||||
tx()
|
||||
|
||||
writeAudit(event, 'delete', `work:${row.slug}`)
|
||||
return { ok: true }
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import { readBody, createError, getRouterParam } from 'h3'
|
||||
import { requireAdmin } from '../../../utils/auth'
|
||||
import { getDb } from '../../../utils/db'
|
||||
import { getWorkBySlug } from '../../../utils/content'
|
||||
import { writeAudit } from '../../../utils/audit'
|
||||
import {
|
||||
normalizeSlug,
|
||||
isValidSlug,
|
||||
@@ -77,6 +78,7 @@ export default defineEventHandler(async (event) => {
|
||||
db.prepare(`UPDATE works SET ${sets.join(', ')} WHERE id = ?`).run(...params, id)
|
||||
|
||||
const row = db.prepare('SELECT slug FROM works WHERE id = ?').get(id) as { slug: string }
|
||||
writeAudit(event, 'update', `work:${id}`)
|
||||
return { ok: true, work: getWorkBySlug(row.slug, { publishedOnly: false }) }
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { readBody, createError } from 'h3'
|
||||
import { getDb } from '../../utils/db'
|
||||
import { requireUser, verifyPassword, clearSessionCookie } from '../../utils/auth'
|
||||
|
||||
/**
|
||||
* 自助删除账号(需验证当前密码;删除后登出,级联清理会话/评论/收藏)
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireUser(event)
|
||||
const body = await readBody(event)
|
||||
const password = String(body?.password ?? '')
|
||||
|
||||
const row = getDb().prepare('SELECT password_hash FROM users WHERE id = ?').get(user.id) as
|
||||
| { password_hash: string }
|
||||
| undefined
|
||||
if (!row || !(await verifyPassword(password, row.password_hash))) {
|
||||
throw createError({ statusCode: 400, message: '密码不正确', data: { code: 'WRONG_PASSWORD' } })
|
||||
}
|
||||
|
||||
getDb().prepare('DELETE FROM users WHERE id = ?').run(user.id) // 外键级联:sessions/comments/favorites
|
||||
clearSessionCookie(event)
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { readBody, createError } from 'h3'
|
||||
import { getDb } from '../../utils/db'
|
||||
import { requireUser, verifyPassword, hashPassword } from '../../utils/auth'
|
||||
import { isValidPassword } from '../../utils/validation'
|
||||
|
||||
/**
|
||||
* 修改密码:校验当前密码 -> 新密码强度 -> 更新
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireUser(event)
|
||||
const body = await readBody(event)
|
||||
const currentPassword = String(body?.currentPassword ?? '')
|
||||
const newPassword = String(body?.newPassword ?? '')
|
||||
|
||||
const row = getDb().prepare('SELECT password_hash FROM users WHERE id = ?').get(user.id) as
|
||||
| { password_hash: string }
|
||||
| undefined
|
||||
if (!row || !(await verifyPassword(currentPassword, row.password_hash))) {
|
||||
throw createError({ statusCode: 400, message: '当前密码不正确', data: { code: 'WRONG_PASSWORD' } })
|
||||
}
|
||||
if (!isValidPassword(newPassword)) {
|
||||
throw createError({ statusCode: 400, message: '新密码至少需要 8 位', data: { code: 'VALIDATION_ERROR' } })
|
||||
}
|
||||
|
||||
const passwordHash = await hashPassword(newPassword)
|
||||
getDb().prepare('UPDATE users SET password_hash = ? WHERE id = ?').run(passwordHash, user.id)
|
||||
return { ok: true }
|
||||
})
|
||||
@@ -1,10 +1,12 @@
|
||||
import { readBody, createError } from 'h3'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { getDb } from '../utils/db'
|
||||
import { getConfig } from '../utils/config'
|
||||
import { sendMail } from '../utils/email'
|
||||
import { isValidEmail } from '../utils/validation'
|
||||
|
||||
/**
|
||||
* 邮箱订阅:去重落库 + 尽力发送欢迎邮件
|
||||
* 邮箱订阅:去重落库(生成退订 token)+ 尽力发送欢迎邮件
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
@@ -20,13 +22,16 @@ export default defineEventHandler(async (event) => {
|
||||
throw createError({ statusCode: 400, message: '您已在订阅列表中', data: { code: 'ALREADY_SUBSCRIBED' } })
|
||||
}
|
||||
|
||||
db.prepare('INSERT INTO subscribers (email) VALUES (?)').run(email)
|
||||
const token = randomBytes(24).toString('hex')
|
||||
db.prepare('INSERT INTO subscribers (email, token) VALUES (?, ?)').run(email, token)
|
||||
|
||||
const { siteUrl } = getConfig()
|
||||
const unsubscribeUrl = siteUrl ? `${siteUrl}/unsubscribe?token=${token}` : ''
|
||||
await sendMail(
|
||||
email,
|
||||
'欢迎订阅 ArcticNewOne 资讯',
|
||||
'感谢订阅 ArcticNewOne!我们会不定期发送精选更新,助您把握设计、开发与行业动态。',
|
||||
`感谢订阅 ArcticNewOne!我们会不定期发送精选更新,助您把握设计、开发与行业动态。\n\n如需退订:${unsubscribeUrl || '请联系管理员'}`,
|
||||
)
|
||||
|
||||
return { ok: true }
|
||||
return { ok: true, token }
|
||||
})
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { readBody, createError } from 'h3'
|
||||
import { getDb } from '../../utils/db'
|
||||
|
||||
/**
|
||||
* 订阅退订(基于订阅时生成的 token;幂等,无效 token 不报错避免泄露)
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody(event)
|
||||
const token = String(body?.token ?? '')
|
||||
if (!token) {
|
||||
throw createError({ statusCode: 400, message: '缺少退订标识', data: { code: 'VALIDATION_ERROR' } })
|
||||
}
|
||||
|
||||
const db = getDb()
|
||||
const sub = db.prepare('SELECT id FROM subscribers WHERE token = ?').get(token) as
|
||||
| { id: number }
|
||||
| undefined
|
||||
|
||||
if (!sub) {
|
||||
return { ok: true, unsubscribed: false }
|
||||
}
|
||||
db.prepare('DELETE FROM subscribers WHERE id = ?').run(sub.id)
|
||||
return { ok: true, unsubscribed: true }
|
||||
})
|
||||
@@ -0,0 +1,51 @@
|
||||
import { getConfig } from '../utils/config'
|
||||
import { listArticles } from '../utils/content'
|
||||
|
||||
const escapeXml = (s: string) =>
|
||||
String(s ?? '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
|
||||
/**
|
||||
* RSS 2.0 订阅源 /feed.xml(动态全部已发布)
|
||||
*/
|
||||
export default defineEventHandler(() => {
|
||||
const { siteUrl } = getConfig()
|
||||
const articles = listArticles({ publishedOnly: true })
|
||||
|
||||
const items = articles
|
||||
.map((a) => {
|
||||
const title = a.titleZh || a.titleEn
|
||||
const desc = a.excerptZh || a.excerptEn
|
||||
const link = `${siteUrl}/news/${a.slug}`
|
||||
const date = a.date ? new Date(`${a.date}T00:00:00Z`).toUTCString() : new Date().toUTCString()
|
||||
return [
|
||||
' <item>',
|
||||
` <title>${escapeXml(title)}</title>`,
|
||||
` <link>${link}</link>`,
|
||||
` <guid isPermaLink="true">${link}</guid>`,
|
||||
` <description>${escapeXml(desc)}</description>`,
|
||||
` <pubDate>${date}</pubDate>`,
|
||||
' </item>',
|
||||
].join('\n')
|
||||
})
|
||||
.join('\n')
|
||||
|
||||
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>
|
||||
<link>${siteUrl}</link>
|
||||
<description>北极新一工作室的最新动态与洞察</description>
|
||||
<language>zh-cn</language>
|
||||
<atom:link href="${siteUrl}/feed.xml" rel="self" type="application/rss+xml"/>
|
||||
${items}
|
||||
</channel>
|
||||
</rss>`
|
||||
|
||||
return new Response(xml, {
|
||||
headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' },
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { H3Event } from 'h3'
|
||||
import { getDb } from './db'
|
||||
import { getCurrentUser } from './auth'
|
||||
|
||||
/**
|
||||
* 记录后台操作审计日志(增删改内容/用户/评论/联系/订阅/上传等)。
|
||||
* 写入失败不影响主流程(仅记录日志)。
|
||||
*/
|
||||
export function writeAudit(event: H3Event, action: string, target: string, detail?: string): void {
|
||||
try {
|
||||
const user = getCurrentUser(event)
|
||||
getDb()
|
||||
.prepare('INSERT INTO audit_logs (actor_id, actor_name, action, target, detail) VALUES (?, ?, ?, ?, ?)')
|
||||
.run(user?.id ?? null, user?.username ?? 'system', action, target, detail ?? null)
|
||||
} catch (err) {
|
||||
console.error('[audit] write failed:', err)
|
||||
}
|
||||
}
|
||||
+3
-23
@@ -1,14 +1,10 @@
|
||||
import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto'
|
||||
import { promisify } from 'node:util'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { createError, getCookie, setCookie, deleteCookie } from 'h3'
|
||||
import type { H3Event } from 'h3'
|
||||
import { getDb } from './db'
|
||||
import { hashPassword, verifyPassword } from './password'
|
||||
|
||||
const scryptAsync = promisify(scrypt) as (
|
||||
password: string,
|
||||
salt: string,
|
||||
keylen: number,
|
||||
) => Promise<Buffer>
|
||||
export { hashPassword, verifyPassword }
|
||||
|
||||
export interface UserRow {
|
||||
id: number
|
||||
@@ -22,22 +18,6 @@ export interface UserRow {
|
||||
export const SESSION_COOKIE = 'an_session'
|
||||
const SESSION_TTL_SECONDS = 30 * 24 * 60 * 60 // 30 天
|
||||
|
||||
// ---------- 密码哈希(scrypt,盐 + 哈希以冒号分隔存储) ----------
|
||||
|
||||
export async function hashPassword(password: string): Promise<string> {
|
||||
const salt = randomBytes(16).toString('hex')
|
||||
const key = await scryptAsync(password, salt, 64)
|
||||
return `${salt}:${key.toString('hex')}`
|
||||
}
|
||||
|
||||
export async function verifyPassword(password: string, stored: string): Promise<boolean> {
|
||||
const [salt, hash] = stored.split(':')
|
||||
if (!salt || !hash) return false
|
||||
const key = await scryptAsync(password, salt, 64)
|
||||
const expected = Buffer.from(hash, 'hex')
|
||||
return key.length === expected.length && timingSafeEqual(key, expected)
|
||||
}
|
||||
|
||||
// ---------- 会话 ----------
|
||||
|
||||
export function createSession(userId: number): string {
|
||||
|
||||
@@ -70,12 +70,14 @@ function migrate(db: Database.Database): void {
|
||||
subject TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
delivered INTEGER NOT NULL DEFAULT 0,
|
||||
read INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS subscribers (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
token TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
@@ -152,7 +154,32 @@ function migrate(db: Database.Database): void {
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_works_category ON works(category);
|
||||
CREATE INDEX IF NOT EXISTS idx_works_published ON works(published);
|
||||
|
||||
-- 后台操作审计日志
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
actor_id INTEGER,
|
||||
actor_name TEXT,
|
||||
action TEXT NOT NULL,
|
||||
target TEXT NOT NULL,
|
||||
detail TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_created ON audit_logs(created_at);
|
||||
`)
|
||||
|
||||
// 老库迁移:为已存在的表补充新增列(SQLite 不支持 ADD COLUMN IF NOT EXISTS)
|
||||
ensureColumn(db, 'contacts', 'read', 'INTEGER NOT NULL DEFAULT 0')
|
||||
ensureColumn(db, 'subscribers', 'token', 'TEXT')
|
||||
}
|
||||
|
||||
/** 若表中缺少某列则补上(用于老库升级) */
|
||||
function ensureColumn(db: Database.Database, table: string, column: string, ddl: string): void {
|
||||
const cols = db.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name: string }>
|
||||
if (!cols.some((c) => c.name === column)) {
|
||||
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${ddl}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { randomBytes, scrypt, timingSafeEqual } from 'node:crypto'
|
||||
import { promisify } from 'node:util'
|
||||
|
||||
/**
|
||||
* 密码哈希/校验(scrypt,盐 + 哈希以冒号分隔存储)。
|
||||
* 独立于 Nuxt/Nitro 依赖,便于单元测试。
|
||||
*/
|
||||
const scryptAsync = promisify(scrypt) as (
|
||||
password: string,
|
||||
salt: string,
|
||||
keylen: number,
|
||||
) => Promise<Buffer>
|
||||
|
||||
export async function hashPassword(password: string): Promise<string> {
|
||||
const salt = randomBytes(16).toString('hex')
|
||||
const key = await scryptAsync(password, salt, 64)
|
||||
return `${salt}:${key.toString('hex')}`
|
||||
}
|
||||
|
||||
export async function verifyPassword(password: string, stored: string): Promise<boolean> {
|
||||
const [salt, hash] = stored.split(':')
|
||||
if (!salt || !hash) return false
|
||||
const key = await scryptAsync(password, salt, 64)
|
||||
const expected = Buffer.from(hash, 'hex')
|
||||
return key.length === expected.length && timingSafeEqual(key, expected)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { hashPassword, verifyPassword } from '../server/utils/password'
|
||||
|
||||
describe('password hashing (scrypt)', () => {
|
||||
it('hashes and verifies the correct password', async () => {
|
||||
const hash = await hashPassword('secret123')
|
||||
expect(hash).toContain(':')
|
||||
expect(await verifyPassword('secret123', hash)).toBe(true)
|
||||
})
|
||||
|
||||
it('rejects a wrong password', async () => {
|
||||
const hash = await hashPassword('secret123')
|
||||
expect(await verifyPassword('wrong-pass', hash)).toBe(false)
|
||||
})
|
||||
|
||||
it('rejects a malformed stored hash', async () => {
|
||||
expect(await verifyPassword('secret123', 'no-separator')).toBe(false)
|
||||
expect(await verifyPassword('secret123', '')).toBe(false)
|
||||
})
|
||||
|
||||
it('produces a unique salt per call', async () => {
|
||||
const a = await hashPassword('secret123')
|
||||
const b = await hashPassword('secret123')
|
||||
expect(a).not.toBe(b)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { articlesSeed, worksSeed } from '../server/utils/seed'
|
||||
|
||||
describe('seed data integrity', () => {
|
||||
it('has 6 articles and 6 works', () => {
|
||||
expect(articlesSeed).toHaveLength(6)
|
||||
expect(worksSeed).toHaveLength(6)
|
||||
})
|
||||
|
||||
it('slugs are unique', () => {
|
||||
const articleSlugs = articlesSeed.map((a) => a.slug)
|
||||
expect(new Set(articleSlugs).size).toBe(articleSlugs.length)
|
||||
const workSlugs = worksSeed.map((w) => w.slug)
|
||||
expect(new Set(workSlugs).size).toBe(workSlugs.length)
|
||||
})
|
||||
|
||||
it('bilingual fields are complete for articles', () => {
|
||||
for (const a of articlesSeed) {
|
||||
expect(a.slug).toBeTruthy()
|
||||
expect(a.titleZh).toBeTruthy()
|
||||
expect(a.titleEn).toBeTruthy()
|
||||
expect(a.excerptZh).toBeTruthy()
|
||||
expect(a.excerptEn).toBeTruthy()
|
||||
expect(a.contentZh.length).toBeGreaterThan(0)
|
||||
expect(a.contentEn.length).toBeGreaterThan(0)
|
||||
expect(a.image).toBeTruthy()
|
||||
expect(a.published).toBe(1)
|
||||
}
|
||||
})
|
||||
|
||||
it('bilingual fields are complete for works', () => {
|
||||
for (const w of worksSeed) {
|
||||
expect(w.slug).toBeTruthy()
|
||||
expect(w.titleZh).toBeTruthy()
|
||||
expect(w.titleEn).toBeTruthy()
|
||||
expect(w.descriptionZh).toBeTruthy()
|
||||
expect(w.descriptionEn).toBeTruthy()
|
||||
expect(w.overviewZh).toBeTruthy()
|
||||
expect(w.overviewEn).toBeTruthy()
|
||||
expect(w.gallery.length).toBeGreaterThan(0)
|
||||
expect(w.tags.length).toBeGreaterThan(0)
|
||||
expect(w.published).toBe(1)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
isValidSlug,
|
||||
isValidArticleCategory,
|
||||
isValidWorkCategory,
|
||||
normalizeBlocks,
|
||||
normalizeTags,
|
||||
normalizeGallery,
|
||||
} from '../server/utils/validateContent'
|
||||
|
||||
describe('content validation', () => {
|
||||
it('validates slugs', () => {
|
||||
expect(isValidSlug('design-trends-2026')).toBe(true)
|
||||
expect(isValidSlug('a')).toBe(false)
|
||||
expect(isValidSlug('')).toBe(false)
|
||||
expect(isValidSlug('with space')).toBe(false)
|
||||
expect(isValidSlug('UPPER')).toBe(false)
|
||||
expect(isValidSlug('x'.repeat(65))).toBe(false)
|
||||
})
|
||||
|
||||
it('validates article/work categories', () => {
|
||||
expect(isValidArticleCategory('insights')).toBe(true)
|
||||
expect(isValidArticleCategory('projects')).toBe(true)
|
||||
expect(isValidArticleCategory('bogus')).toBe(false)
|
||||
expect(isValidWorkCategory('webDesign')).toBe(true)
|
||||
expect(isValidWorkCategory('development')).toBe(true)
|
||||
expect(isValidWorkCategory('insights')).toBe(false)
|
||||
})
|
||||
|
||||
it('normalizes content blocks (filters invalid)', () => {
|
||||
const input = [
|
||||
{ type: 'paragraph', text: 'hi' },
|
||||
{ type: 'heading', text: 'title' },
|
||||
{ type: 'quote', text: 'quote' },
|
||||
{ type: 'image', text: 'https://x/a.png' },
|
||||
{ type: 'bogus', text: 'x' },
|
||||
{ text: 'no-type' },
|
||||
null,
|
||||
'string',
|
||||
]
|
||||
expect(normalizeBlocks(input as never[])).toEqual([
|
||||
{ type: 'paragraph', text: 'hi' },
|
||||
{ type: 'heading', text: 'title' },
|
||||
{ type: 'quote', text: 'quote' },
|
||||
{ type: 'image', text: 'https://x/a.png' },
|
||||
])
|
||||
expect(normalizeBlocks(undefined)).toEqual([])
|
||||
})
|
||||
|
||||
it('normalizes tags and gallery', () => {
|
||||
expect(normalizeTags([' a ', 'b', '', 5])).toEqual(['a', 'b'])
|
||||
expect(normalizeTags('not-array' as never)).toEqual([])
|
||||
expect(normalizeGallery(['/x.png', ' ', '/y.png'])).toEqual(['/x.png', '/y.png'])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
environment: 'node',
|
||||
include: ['tests/**/*.test.ts'],
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user