From 35652caf35dc43d5102559f9467b4301d813927c Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Thu, 23 Apr 2026 23:44:43 +0800 Subject: [PATCH] refactor: update asset paths and enhance post visibility handling - Changed asset paths from `/public/assets` to `/public/upload` across various files to ensure consistency in media storage. - Introduced visibility handling for posts, allowing for better control over comment visibility based on post status. - Enhanced markdown export functionality with new utilities for exporting unlisted posts and normalizing image URLs. - Updated tests to reflect changes in asset paths and visibility logic. These updates improve the overall media management and user experience in handling post visibility and markdown exports. --- .env.example | 2 +- app/layouts/blank.vue | 2 +- app/pages/@[publicSlug]/posts/[postSlug].vue | 7 ++- app/pages/me/admin/media-storage.vue | 2 +- app/pages/me/posts/[id].vue | 51 +++++++++++++++--- app/pages/me/posts/index.vue | 12 ++--- app/pages/p/[publicSlug]/t/[shareToken].vue | 59 ++++++++++++++++++++- app/utils/markdown-export.test.ts | 8 +-- packages/drizzle-pkg/db.sqlite | Bin 147456 -> 147456 bytes server/api/file/upload.post.ts | 4 +- .../profile/[publicSlug]/posts/[postSlug].get.ts | 5 +- server/constants/media.ts | 4 +- server/service/posts/index.ts | 40 +++++++++++++- server/utils/post-media-urls.test.ts | 20 +++---- server/utils/post-media-urls.ts | 6 +-- 15 files changed, 180 insertions(+), 42 deletions(-) diff --git a/.env.example b/.env.example index 1bab83a..8d5cd60 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # DATABASE_URL=postgresql://postgres:xxxxxx@localhost:6666/postgres DATABASE_URL=file:./db.sqlite NITRO_PORT=3399 -# 站点对外根 URL(含协议与域名,可带端口)。用于:① 媒体库复制绝对链接 ② 文章/资料里绝对地址图片是否计为本站 /public/assets/ 引用。生产环境务必设置,与浏览器访问地址一致。 +# 站点对外根 URL(含协议与域名,可带端口)。用于:① 媒体库复制绝对链接 ② 文章/资料里绝对地址图片是否计为本站 /public/upload/ 引用。生产环境务必设置,与浏览器访问地址一致。 NUXT_PUBLIC_SITE_URL=https://example.com # Optional: first admin for an empty instance. Creates an admin only when no user has role=admin yet (same username/password rules as registration). BOOTSTRAP_ADMIN_USERNAME= diff --git a/app/layouts/blank.vue b/app/layouts/blank.vue index 84888ff..063e8af 100644 --- a/app/layouts/blank.vue +++ b/app/layouts/blank.vue @@ -1,6 +1,6 @@ diff --git a/app/pages/me/admin/media-storage.vue b/app/pages/me/admin/media-storage.vue index c240704..ece5c46 100644 --- a/app/pages/me/admin/media-storage.vue +++ b/app/pages/me/admin/media-storage.vue @@ -195,7 +195,7 @@ onMounted(async () => { 媒体存储校验

- 比对 public/assets 与表 media_assets: + 比对 public/upload 与表 media_assets: 库中有记录但文件缺失、非法 storageKey、以及磁盘上未登记的文件。 「一键清理」仅删除无 media_refs 引用磁盘上确实没有文件的库记录,不会删磁盘文件。 对有引用但缺文件的记录可使用重新上传按原 storage_key 写回 WebP,不破坏文章/资料中的链接。 diff --git a/app/pages/me/posts/[id].vue b/app/pages/me/posts/[id].vue index 8aa1933..0e00bc2 100644 --- a/app/pages/me/posts/[id].vue +++ b/app/pages/me/posts/[id].vue @@ -27,7 +27,7 @@ const bodyLength = computed(() => state.bodyMarkdown.trim().length) const publicPostHref = computed(() => { const ps = user.value?.publicSlug - if (state.visibility !== 'public' || !ps || !state.slug) { + if (!ps || !state.slug) { return '' } return `/@${ps}/posts/${encodeURIComponent(state.slug)}` @@ -119,15 +119,27 @@ async function remove() { } const shareUrl = computed(() => { - const slug = user.value?.publicSlug + const slug = user.value?.publicSlug?.trim() if (state.visibility !== 'unlisted' || !state.shareToken || !slug) { return '' } if (import.meta.client) { - return `${window.location.origin}/p/${slug}/t/${state.shareToken}` + return `${window.location.origin}/p/${encodeURIComponent(slug)}/t/${encodeURIComponent(state.shareToken)}` } return '' }) + +async function copyShareUrl() { + if (!shareUrl.value || !import.meta.client) { + return + } + try { + await navigator.clipboard.writeText(shareUrl.value) + toast.add({ title: '分享链接已复制', color: 'success' }) + } catch { + toast.add({ title: '复制失败,请手动复制', color: 'warning' }) + } +}