fix: 修复本地上传资源路径解析
This commit is contained in:
@@ -210,3 +210,4 @@
|
|||||||
- i18n 响应结构(2026-07-06):共享 `ApiResponse` 扩展 `messageKey`/`params`,后端 `BusinessException` 和全局异常过滤器返回稳定 `error.*` key,前端请求统一带 `Accept-Language`,后台错误提示优先按 `messageKey` 翻译、再按错误码兜底。后台 locales 已补 `error.*` 中英文别名,避免英文模式直接显示中文后端消息。
|
- i18n 响应结构(2026-07-06):共享 `ApiResponse` 扩展 `messageKey`/`params`,后端 `BusinessException` 和全局异常过滤器返回稳定 `error.*` key,前端请求统一带 `Accept-Language`,后台错误提示优先按 `messageKey` 翻译、再按错误码兜底。后台 locales 已补 `error.*` 中英文别名,避免英文模式直接显示中文后端消息。
|
||||||
- 发布包与存储迁移收口(2026-07-06):非 Docker 发布包新增 `install-deps.sh` / `install-deps.ps1`,标准安装流程为 `pnpm install --prod --frozen-lockfile` 后在 `apps/api` 目录执行 `prisma generate --schema ./prisma/schema.prisma`,避免生产包启动时报缺 `.prisma/client/default`。发布包只复制 shared 的 `dist` 与 `package.json`,不再带源码和局部 node_modules。存储迁移状态只保存脱敏目标配置和 `storageMigrationFingerprint`,确认切换前必须匹配同目标迁移记录;OSS/Tianhe Secret 继续 AES-GCM 加密保存,接口返回脱敏,备份使用 raw 设置值。最终验证过发布包安装脚本、安装模式 `/api/install/status` 200、未安装 `/admin` 404、单端口监听正常。
|
- 发布包与存储迁移收口(2026-07-06):非 Docker 发布包新增 `install-deps.sh` / `install-deps.ps1`,标准安装流程为 `pnpm install --prod --frozen-lockfile` 后在 `apps/api` 目录执行 `prisma generate --schema ./prisma/schema.prisma`,避免生产包启动时报缺 `.prisma/client/default`。发布包只复制 shared 的 `dist` 与 `package.json`,不再带源码和局部 node_modules。存储迁移状态只保存脱敏目标配置和 `storageMigrationFingerprint`,确认切换前必须匹配同目标迁移记录;OSS/Tianhe Secret 继续 AES-GCM 加密保存,接口返回脱敏,备份使用 raw 设置值。最终验证过发布包安装脚本、安装模式 `/api/install/status` 200、未安装 `/admin` 404、单端口监听正常。
|
||||||
- 子路径默认图标与操作日志映射修复(2026-07-07):单端口路径部署下默认图标必须使用前后台各自子路径,后台默认 `/admin/app-icon.svg`,客户端默认 `/trace/app-icon.svg`;后端 `appIconUrl` 默认保持空值,由前端按所在端回退默认图标,并兼容历史设置值 `/app-icon.svg` 为空,避免设置页、登录页、侧边栏和 favicon 断图。操作日志后端不再用粗略 `path.includes('/backup')` 判定动作,改为按路径段明确识别备份创建/删除/下载/恢复预检/恢复确认、批量删除追溯码、出库导入、存储迁移、修改密码、区块链确认/重试等动作;新增单测覆盖备份删除不再显示为创建备份。后台操作日志页会按 `method + path` 推导有效动作和摘要,兼容已写入错误 `action=backup` 的历史删除备份日志,并补齐存储、证书、溯源节点、区块链存证等模块和路径摘要的中英文 i18n。已验证 API 单测、API/admin/client 构建和浏览器烟测:默认图标无断图,历史删除备份日志在“操作/操作摘要”均显示为删除。
|
- 子路径默认图标与操作日志映射修复(2026-07-07):单端口路径部署下默认图标必须使用前后台各自子路径,后台默认 `/admin/app-icon.svg`,客户端默认 `/trace/app-icon.svg`;后端 `appIconUrl` 默认保持空值,由前端按所在端回退默认图标,并兼容历史设置值 `/app-icon.svg` 为空,避免设置页、登录页、侧边栏和 favicon 断图。操作日志后端不再用粗略 `path.includes('/backup')` 判定动作,改为按路径段明确识别备份创建/删除/下载/恢复预检/恢复确认、批量删除追溯码、出库导入、存储迁移、修改密码、区块链确认/重试等动作;新增单测覆盖备份删除不再显示为创建备份。后台操作日志页会按 `method + path` 推导有效动作和摘要,兼容已写入错误 `action=backup` 的历史删除备份日志,并补齐存储、证书、溯源节点、区块链存证等模块和路径摘要的中英文 i18n。已验证 API 单测、API/admin/client 构建和浏览器烟测:默认图标无断图,历史删除备份日志在“操作/操作摘要”均显示为删除。
|
||||||
|
- 本地上传资源路径收口(2026-07-07):本地存储驱动在未配置 CDN 时只返回相对公开路径 `/uploads/{key}`,不再拼接 `BASE_URL`、localhost 或旧域名;配置 `cdnBaseUrl` 时仍返回 CDN 完整 URL。后台和客户端 dev server 都代理 `/uploads` 到 API,保证开发环境相对路径可访问。前后台新增 `resolveMediaUrl` 工具,统一把历史 `localhost/127.0.0.1/同源 /uploads/...` 规整为 `/uploads/...`,并把本地存储 key(`YYYY/MM/DD/...`)兜底映射为 `/uploads/...`,OSS/CDN 外链保持原样。媒体上传组件、作品列表/审核/出库预览、作品编辑页、客户端追溯页和 PhotoSwipe 预览入口均使用该工具;新建/编辑保存时优先保存存储 key,展示时再动态解析 URL。新增 `LocalDriver` 单测覆盖本地相对 URL、前缀尾斜杠和 CDN URL 行为。验证:API 单测通过,shared/API/admin/client 构建通过。
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
@drop="onDrop(i)"
|
@drop="onDrop(i)"
|
||||||
@dragend="onDragEnd"
|
@dragend="onDragEnd"
|
||||||
>
|
>
|
||||||
<video v-if="isVideo(m)" class="thumb" :src="m.url" muted preload="metadata" />
|
<video v-if="isVideo(m)" class="thumb" :src="mediaSrc(m)" muted preload="metadata" />
|
||||||
<img v-else class="thumb" :src="m.url" :alt="m.name" loading="lazy" />
|
<img v-else class="thumb" :src="mediaSrc(m)" :alt="m.name" loading="lazy" />
|
||||||
<div v-if="isVideo(m)" class="play"><n-icon :component="PlayCircleOutline" :size="26" /></div>
|
<div v-if="isVideo(m)" class="play"><n-icon :component="PlayCircleOutline" :size="26" /></div>
|
||||||
<div class="order">{{ i + 1 }}</div>
|
<div class="order">{{ i + 1 }}</div>
|
||||||
<button class="del" type="button" :title="t('common.action.delete')" @click.stop="remove(i)">×</button>
|
<button class="del" type="button" :title="t('common.action.delete')" @click.stop="remove(i)">×</button>
|
||||||
@@ -52,6 +52,7 @@ import { AddOutline, PlayCircleOutline } from '@vicons/ionicons5';
|
|||||||
import { post } from '@/api/request';
|
import { post } from '@/api/request';
|
||||||
import { message } from '@/utils/feedback';
|
import { message } from '@/utils/feedback';
|
||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
interface MediaItem {
|
interface MediaItem {
|
||||||
key: string;
|
key: string;
|
||||||
@@ -77,8 +78,12 @@ function updateCaption(i: number, v: string) {
|
|||||||
emit('update:modelValue', arr);
|
emit('update:modelValue', arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mediaSrc(m: MediaItem) {
|
||||||
|
return resolveMediaUrl(m.url || m.key);
|
||||||
|
}
|
||||||
|
|
||||||
function isVideo(m: MediaItem) {
|
function isVideo(m: MediaItem) {
|
||||||
return m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || m.key || '');
|
return m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(mediaSrc(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onPick(e: Event) {
|
async function onPick(e: Event) {
|
||||||
@@ -104,7 +109,7 @@ async function uploadOne(file: File) {
|
|||||||
const res: any = await post(`/upload?type=${type}`, fd);
|
const res: any = await post(`/upload?type=${type}`, fd);
|
||||||
emit('update:modelValue', [
|
emit('update:modelValue', [
|
||||||
...list.value,
|
...list.value,
|
||||||
{ key: res.key, url: res.url, name: props.captionable ? '' : res.name, type },
|
{ key: res.key, url: resolveMediaUrl(res.url), name: props.captionable ? '' : res.name, type },
|
||||||
]);
|
]);
|
||||||
} catch {
|
} catch {
|
||||||
message.error(t('common.msg.uploadFailed'));
|
message.error(t('common.msg.uploadFailed'));
|
||||||
@@ -118,7 +123,7 @@ function remove(i: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toViewerItem(m: MediaItem) {
|
function toViewerItem(m: MediaItem) {
|
||||||
return { url: m.url || m.key, name: m.name || m.key, type: m.type };
|
return { url: mediaSrc(m), name: m.name || m.key, type: m.type };
|
||||||
}
|
}
|
||||||
|
|
||||||
function preview(index: number) {
|
function preview(index: number) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="media-upload" :class="{ text: listType === 'text' }">
|
<div class="media-upload" :class="{ text: listType === 'text' }">
|
||||||
<div v-if="listType === 'image-card'" class="image-grid">
|
<div v-if="listType === 'image-card'" class="image-grid">
|
||||||
<div v-for="(m, i) in items" :key="m.key" class="image-item previewable" @click="preview(i)">
|
<div v-for="(m, i) in items" :key="m.key" class="image-item previewable" @click="preview(i)">
|
||||||
<img v-if="isImage(m)" class="image-thumb" :src="m.url || m.key" :alt="m.name || m.key" loading="lazy" />
|
<img v-if="isImage(m)" class="image-thumb" :src="mediaSrc(m)" :alt="m.name || m.key" loading="lazy" />
|
||||||
<div v-else class="file-thumb">{{ fileExt(m) }}</div>
|
<div v-else class="file-thumb">{{ fileExt(m) }}</div>
|
||||||
<button class="remove" type="button" :title="t('common.action.delete')" @click.stop="remove(m.key)">×</button>
|
<button class="remove" type="button" :title="t('common.action.delete')" @click.stop="remove(m.key)">×</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -46,6 +46,7 @@ import { AddOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
|||||||
import { post } from '@/api/request';
|
import { post } from '@/api/request';
|
||||||
import { message } from '@/utils/feedback';
|
import { message } from '@/utils/feedback';
|
||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
interface MediaItem {
|
interface MediaItem {
|
||||||
key: string;
|
key: string;
|
||||||
@@ -72,8 +73,12 @@ const accept = computed(() =>
|
|||||||
const allowMultiple = computed(() => props.max > 1);
|
const allowMultiple = computed(() => props.max > 1);
|
||||||
const canUpload = computed(() => items.value.length + uploading.value.length < props.max);
|
const canUpload = computed(() => items.value.length + uploading.value.length < props.max);
|
||||||
|
|
||||||
|
function mediaSrc(m: MediaItem) {
|
||||||
|
return resolveMediaUrl(m.url || m.key);
|
||||||
|
}
|
||||||
|
|
||||||
function isImage(m: MediaItem) {
|
function isImage(m: MediaItem) {
|
||||||
return props.type === 'image' || /^image\//.test(m.type || '') || /\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(m.url || m.key);
|
return props.type === 'image' || /^image\//.test(m.type || '') || /\.(png|jpe?g|gif|webp|bmp|svg)$/i.test(mediaSrc(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
function fileExt(m: MediaItem) {
|
function fileExt(m: MediaItem) {
|
||||||
@@ -104,7 +109,7 @@ async function uploadOne(file: File) {
|
|||||||
const res: any = await post(`/upload?type=${props.type}`, fd);
|
const res: any = await post(`/upload?type=${props.type}`, fd);
|
||||||
emit('update:modelValue', [
|
emit('update:modelValue', [
|
||||||
...items.value,
|
...items.value,
|
||||||
{ key: res.key, url: res.url, name: res.name || file.name, type: props.type },
|
{ key: res.key, url: resolveMediaUrl(res.url), name: res.name || file.name, type: props.type },
|
||||||
]);
|
]);
|
||||||
} catch {
|
} catch {
|
||||||
message.error(t('common.msg.uploadFailed'));
|
message.error(t('common.msg.uploadFailed'));
|
||||||
@@ -119,7 +124,7 @@ function remove(key: string) {
|
|||||||
|
|
||||||
function preview(index: number) {
|
function preview(index: number) {
|
||||||
void openMediaViewer(
|
void openMediaViewer(
|
||||||
items.value.map((m) => ({ url: m.url || m.key, name: m.name || m.key, type: m.type })),
|
items.value.map((m) => ({ url: mediaSrc(m), name: m.name || m.key, type: m.type })),
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import PhotoSwipe from 'photoswipe';
|
|||||||
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
||||||
import 'photoswipe/style.css';
|
import 'photoswipe/style.css';
|
||||||
import { i18n } from '@/locales';
|
import { i18n } from '@/locales';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
export interface MediaViewerItem {
|
export interface MediaViewerItem {
|
||||||
url?: string;
|
url?: string;
|
||||||
@@ -308,7 +309,9 @@ function registerToolbar(lightbox: PhotoSwipeLightbox): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openMediaViewer(items: MediaViewerItem[], index = 0): Promise<void> {
|
export async function openMediaViewer(items: MediaViewerItem[], index = 0): Promise<void> {
|
||||||
const list = (items || []).filter((item) => item.url);
|
const list = (items || [])
|
||||||
|
.map((item) => ({ ...item, url: resolveMediaUrl(item.url) }))
|
||||||
|
.filter((item) => item.url);
|
||||||
if (!list.length) return;
|
if (!list.length) return;
|
||||||
const start = Math.min(Math.max(index, 0), list.length - 1);
|
const start = Math.min(Math.max(index, 0), list.length - 1);
|
||||||
const dataSource = await Promise.all(
|
const dataSource = await Promise.all(
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export function resolveMediaUrl(url?: string | null): string {
|
||||||
|
const value = String(url || '').trim();
|
||||||
|
if (!value) return '';
|
||||||
|
if (/^\d{4}\/\d{2}\/\d{2}\/[^?#]+$/i.test(value)) {
|
||||||
|
return `/uploads/${value}`;
|
||||||
|
}
|
||||||
|
if (/^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/uploads\//i.test(value)) {
|
||||||
|
return value.replace(/^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?/i, '');
|
||||||
|
}
|
||||||
|
if (typeof window !== 'undefined' && /^https?:\/\//i.test(value)) {
|
||||||
|
try {
|
||||||
|
const parsed = new URL(value);
|
||||||
|
if (parsed.origin === window.location.origin && parsed.pathname.startsWith('/uploads/')) {
|
||||||
|
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
@@ -130,14 +130,14 @@
|
|||||||
:model-value="toMedia(form.dynamicFields[f.fieldKey])"
|
:model-value="toMedia(form.dynamicFields[f.fieldKey])"
|
||||||
type="image"
|
type="image"
|
||||||
:max="1"
|
:max="1"
|
||||||
@update:model-value="(v) => (form.dynamicFields[f.fieldKey] = v[0]?.url || '')"
|
@update:model-value="(v) => (form.dynamicFields[f.fieldKey] = mediaKey(v[0]) || '')"
|
||||||
/>
|
/>
|
||||||
<media-upload
|
<media-upload
|
||||||
v-else-if="f.type === 'FILE'"
|
v-else-if="f.type === 'FILE'"
|
||||||
:model-value="toMedia(form.dynamicFields[f.fieldKey])"
|
:model-value="toMedia(form.dynamicFields[f.fieldKey])"
|
||||||
type="file"
|
type="file"
|
||||||
:max="1"
|
:max="1"
|
||||||
@update:model-value="(v) => (form.dynamicFields[f.fieldKey] = v[0]?.url || '')"
|
@update:model-value="(v) => (form.dynamicFields[f.fieldKey] = mediaKey(v[0]) || '')"
|
||||||
/>
|
/>
|
||||||
<n-input v-else v-model:value="form.dynamicFields[f.fieldKey]" />
|
<n-input v-else v-model:value="form.dynamicFields[f.fieldKey]" />
|
||||||
</n-form-item-gi>
|
</n-form-item-gi>
|
||||||
@@ -176,7 +176,7 @@
|
|||||||
<template v-for="m in n.media" :key="m.url || m.key">
|
<template v-for="m in n.media" :key="m.url || m.key">
|
||||||
<video
|
<video
|
||||||
v-if="isVideoMedia(m)"
|
v-if="isVideoMedia(m)"
|
||||||
:src="m.url"
|
:src="mediaUrl(m)"
|
||||||
controls
|
controls
|
||||||
preload="metadata"
|
preload="metadata"
|
||||||
style="max-height: 90px; border-radius: 6px; background: #000"
|
style="max-height: 90px; border-radius: 6px; background: #000"
|
||||||
@@ -184,7 +184,7 @@
|
|||||||
<img
|
<img
|
||||||
v-else
|
v-else
|
||||||
class="node-media-image"
|
class="node-media-image"
|
||||||
:src="m.url"
|
:src="mediaUrl(m)"
|
||||||
:alt="m.name || n.title"
|
:alt="m.name || n.title"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@click="previewNodeImage(n.media, m)"
|
@click="previewNodeImage(n.media, m)"
|
||||||
@@ -213,7 +213,7 @@
|
|||||||
<img
|
<img
|
||||||
v-if="c.watermarkUrl || c.originUrl"
|
v-if="c.watermarkUrl || c.originUrl"
|
||||||
class="cert-preview-image"
|
class="cert-preview-image"
|
||||||
:src="c.watermarkUrl || c.originUrl"
|
:src="certUrl(c)"
|
||||||
:alt="c.name"
|
:alt="c.name"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@click="previewCert(c)"
|
@click="previewCert(c)"
|
||||||
@@ -341,6 +341,7 @@ import MediaSorter from '@/components/MediaSorter.vue';
|
|||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
import { message, dialog } from '@/utils/feedback';
|
import { message, dialog } from '@/utils/feedback';
|
||||||
import { fmtDate, fmtSecond } from '@/utils/format';
|
import { fmtDate, fmtSecond } from '@/utils/format';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -415,7 +416,7 @@ function onTemplateChange() {
|
|||||||
|
|
||||||
// 动态字段 IMAGE/FILE 适配:dynamicFields 存 url 字符串,MediaUpload 需要 MediaItem[]
|
// 动态字段 IMAGE/FILE 适配:dynamicFields 存 url 字符串,MediaUpload 需要 MediaItem[]
|
||||||
function toMedia(url: unknown) {
|
function toMedia(url: unknown) {
|
||||||
return url ? [{ key: String(url), url: String(url), name: String(url) }] : [];
|
return url ? [{ key: String(url), url: resolveMediaUrl(String(url)), name: String(url) }] : [];
|
||||||
}
|
}
|
||||||
function auditTagType(s?: string) {
|
function auditTagType(s?: string) {
|
||||||
return s === 'APPROVED' ? 'success' : s === 'REJECTED' ? 'error' : 'warning';
|
return s === 'APPROVED' ? 'success' : s === 'REJECTED' ? 'error' : 'warning';
|
||||||
@@ -514,7 +515,7 @@ function normalizeNode(n: any) {
|
|||||||
...n,
|
...n,
|
||||||
media: media.map((m: any) => ({
|
media: media.map((m: any) => ({
|
||||||
key: m.key || m.url,
|
key: m.key || m.url,
|
||||||
url: m.url,
|
url: resolveMediaUrl(m.url || m.key),
|
||||||
name: m.name,
|
name: m.name,
|
||||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||||
})),
|
})),
|
||||||
@@ -527,8 +528,8 @@ function normalizeCert(c: any) {
|
|||||||
originKey: c.originKey ?? c.originFileUrl,
|
originKey: c.originKey ?? c.originFileUrl,
|
||||||
watermarkKey: c.watermarkKey ?? c.watermarkFileUrl,
|
watermarkKey: c.watermarkKey ?? c.watermarkFileUrl,
|
||||||
issuedAt: c.issuedAt,
|
issuedAt: c.issuedAt,
|
||||||
originUrl: c.originUrl,
|
originUrl: resolveMediaUrl(c.originUrl || c.originKey || c.originFileUrl),
|
||||||
watermarkUrl: c.watermarkUrl,
|
watermarkUrl: resolveMediaUrl(c.watermarkUrl || c.watermarkKey || c.watermarkFileUrl),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,10 +673,10 @@ const editingNode = ref<number | null>(null);
|
|||||||
const editingNodeLocalId = ref<string | null>(null);
|
const editingNodeLocalId = ref<string | null>(null);
|
||||||
const nodeForm = reactive<any>({ nodeType: NodeType.CREATE, title: '', occurredAt: null, location: '', description: '', media: [] });
|
const nodeForm = reactive<any>({ nodeType: NodeType.CREATE, title: '', occurredAt: null, location: '', description: '', media: [] });
|
||||||
function isVideoMedia(m: any) {
|
function isVideoMedia(m: any) {
|
||||||
return m.type === 'video' || /\.(mp4|webm|mov|m4v)$/i.test(m.url || m.key || '');
|
return m.type === 'video' || /\.(mp4|webm|mov|m4v)$/i.test(mediaUrl(m));
|
||||||
}
|
}
|
||||||
function toViewerItem(m: any) {
|
function toViewerItem(m: any) {
|
||||||
return { url: m.url || m.key, name: m.name || m.key, type: m.type };
|
return { url: mediaUrl(m), name: m.name || m.key, type: m.type };
|
||||||
}
|
}
|
||||||
function previewNodeImage(media: any[] = [], current: any) {
|
function previewNodeImage(media: any[] = [], current: any) {
|
||||||
const images = (media || []).filter((item) => !isVideoMedia(item) && (item.url || item.key));
|
const images = (media || []).filter((item) => !isVideoMedia(item) && (item.url || item.key));
|
||||||
@@ -683,10 +684,19 @@ function previewNodeImage(media: any[] = [], current: any) {
|
|||||||
void openMediaViewer(images.map(toViewerItem), Math.max(index, 0));
|
void openMediaViewer(images.map(toViewerItem), Math.max(index, 0));
|
||||||
}
|
}
|
||||||
function previewCert(cert: any) {
|
function previewCert(cert: any) {
|
||||||
const url = cert.watermarkUrl || cert.originUrl;
|
const url = certUrl(cert);
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
void openMediaViewer([{ url, name: cert.name || cert.originKey || cert.watermarkKey }]);
|
void openMediaViewer([{ url, name: cert.name || cert.originKey || cert.watermarkKey }]);
|
||||||
}
|
}
|
||||||
|
function mediaUrl(item?: any) {
|
||||||
|
return resolveMediaUrl(item?.url || item?.key);
|
||||||
|
}
|
||||||
|
function mediaKey(item?: any) {
|
||||||
|
return item?.key || item?.url || '';
|
||||||
|
}
|
||||||
|
function certUrl(cert?: any) {
|
||||||
|
return resolveMediaUrl(cert?.watermarkUrl || cert?.originUrl || cert?.watermarkKey || cert?.originKey);
|
||||||
|
}
|
||||||
function openNode(n?: any) {
|
function openNode(n?: any) {
|
||||||
editingNode.value = n?.id ?? null;
|
editingNode.value = n?.id ?? null;
|
||||||
editingNodeLocalId.value = n?.localId ?? null;
|
editingNodeLocalId.value = n?.localId ?? null;
|
||||||
@@ -698,7 +708,7 @@ function openNode(n?: any) {
|
|||||||
description: n?.description ?? '',
|
description: n?.description ?? '',
|
||||||
media: (n?.media ?? []).map((m: any) => ({
|
media: (n?.media ?? []).map((m: any) => ({
|
||||||
key: m.key || m.url,
|
key: m.key || m.url,
|
||||||
url: m.url,
|
url: resolveMediaUrl(m.url || m.key),
|
||||||
name: m.name,
|
name: m.name,
|
||||||
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
type: m.type || (isVideoMedia(m) ? 'video' : 'image'),
|
||||||
})),
|
})),
|
||||||
@@ -780,7 +790,7 @@ async function saveCert() {
|
|||||||
normalizeCert({
|
normalizeCert({
|
||||||
...payload,
|
...payload,
|
||||||
localId: nextLocalId('cert'),
|
localId: nextLocalId('cert'),
|
||||||
originUrl: certForm.files[0].url,
|
originUrl: resolveMediaUrl(certForm.files[0].url || certForm.files[0].key),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
message.success(t('common.msg.created'));
|
message.success(t('common.msg.created'));
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import { dialog, message } from '@/utils/feedback';
|
|||||||
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
import { useRemoteSort } from '@/utils/tableSort';
|
import { useRemoteSort } from '@/utils/tableSort';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -78,7 +79,7 @@ const columns: DataTableColumns<any> = [
|
|||||||
render: (r) =>
|
render: (r) =>
|
||||||
r.images?.[0]?.url
|
r.images?.[0]?.url
|
||||||
? h(NAvatar, {
|
? h(NAvatar, {
|
||||||
src: r.images[0].url,
|
src: mediaUrl(r.images[0]),
|
||||||
size: 44,
|
size: 44,
|
||||||
style: 'border-radius:8px;cursor:zoom-in',
|
style: 'border-radius:8px;cursor:zoom-in',
|
||||||
onClick: () => previewArtworkImages(r.images),
|
onClick: () => previewArtworkImages(r.images),
|
||||||
@@ -228,9 +229,12 @@ function auditDisplay(r: any) {
|
|||||||
function goCreate() {
|
function goCreate() {
|
||||||
router.push('/artworks/new');
|
router.push('/artworks/new');
|
||||||
}
|
}
|
||||||
|
function mediaUrl(item: any) {
|
||||||
|
return resolveMediaUrl(item?.url || item?.key);
|
||||||
|
}
|
||||||
function previewArtworkImages(images: any[]) {
|
function previewArtworkImages(images: any[]) {
|
||||||
void openMediaViewer(
|
void openMediaViewer(
|
||||||
(images || []).map((item) => ({ url: item.url || item.key, name: item.name || item.key, type: item.type || 'image' })),
|
(images || []).map((item) => ({ url: mediaUrl(item), name: item.name || item.key, type: item.type || 'image' })),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ import { useTablePage } from '@/composables/useTablePage';
|
|||||||
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
import { renderTableFilterTitle } from '@/utils/tableFilter';
|
||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
import { useRemoteSort } from '@/utils/tableSort';
|
import { useRemoteSort } from '@/utils/tableSort';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -92,7 +93,7 @@ const columns: DataTableColumns<any> = [
|
|||||||
render: (r) =>
|
render: (r) =>
|
||||||
r.images?.[0]?.url
|
r.images?.[0]?.url
|
||||||
? h(NAvatar, {
|
? h(NAvatar, {
|
||||||
src: r.images[0].url,
|
src: mediaUrl(r.images[0]),
|
||||||
size: 40,
|
size: 40,
|
||||||
style: 'border-radius:8px;cursor:zoom-in',
|
style: 'border-radius:8px;cursor:zoom-in',
|
||||||
onClick: () => previewArtworkImages(r.images),
|
onClick: () => previewArtworkImages(r.images),
|
||||||
@@ -173,9 +174,12 @@ function onSearch() {
|
|||||||
resetPage();
|
resetPage();
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
function mediaUrl(item: any) {
|
||||||
|
return resolveMediaUrl(item?.url || item?.key);
|
||||||
|
}
|
||||||
function previewArtworkImages(images: any[]) {
|
function previewArtworkImages(images: any[]) {
|
||||||
void openMediaViewer(
|
void openMediaViewer(
|
||||||
(images || []).map((item) => ({ url: item.url || item.key, name: item.name || item.key, type: item.type || 'image' })),
|
(images || []).map((item) => ({ url: mediaUrl(item), name: item.name || item.key, type: item.type || 'image' })),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ import { fmt, statusType } from '@/utils/format';
|
|||||||
import { useTablePage } from '@/composables/useTablePage';
|
import { useTablePage } from '@/composables/useTablePage';
|
||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
import { useRemoteSort } from '@/utils/tableSort';
|
import { useRemoteSort } from '@/utils/tableSort';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
@@ -150,7 +151,7 @@ function renderImages(row: any) {
|
|||||||
width: 38,
|
width: 38,
|
||||||
height: 38,
|
height: 38,
|
||||||
objectFit: 'cover',
|
objectFit: 'cover',
|
||||||
src: item.url || item.key,
|
src: mediaUrl(item),
|
||||||
previewDisabled: true,
|
previewDisabled: true,
|
||||||
onClick: () => previewImages(images, index),
|
onClick: () => previewImages(images, index),
|
||||||
}),
|
}),
|
||||||
@@ -167,11 +168,15 @@ function renderImages(row: any) {
|
|||||||
|
|
||||||
function previewImages(images: any[], index: number) {
|
function previewImages(images: any[], index: number) {
|
||||||
void openMediaViewer(
|
void openMediaViewer(
|
||||||
images.map((item) => ({ url: item.url || item.key, name: item.name || item.key, type: item.type || 'image' })),
|
images.map((item) => ({ url: mediaUrl(item), name: item.name || item.key, type: item.type || 'image' })),
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mediaUrl(item: any) {
|
||||||
|
return resolveMediaUrl(item?.url || item?.key);
|
||||||
|
}
|
||||||
|
|
||||||
async function downloadTemplate() {
|
async function downloadTemplate() {
|
||||||
await downloadFile('/outbound/import/template', 'outbound-import-template.zip');
|
await downloadFile('/outbound/import/template', 'outbound-import-template.zip');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ export default defineConfig({
|
|||||||
target: 'http://localhost:3000',
|
target: 'http://localhost:3000',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
'/uploads': {
|
||||||
|
target: 'http://localhost:3000',
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { mkdtempSync, rmSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { tmpdir } from 'os';
|
||||||
|
import { LocalDriver } from './local.driver';
|
||||||
|
|
||||||
|
describe('LocalDriver', () => {
|
||||||
|
const tempDirs: string[] = [];
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const dir of tempDirs.splice(0)) {
|
||||||
|
rmSync(dir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function createDriver(publicPrefix = '/uploads', cdnBaseUrl = '') {
|
||||||
|
const localDir = mkdtempSync(join(tmpdir(), 'artveris-storage-'));
|
||||||
|
tempDirs.push(localDir);
|
||||||
|
return new LocalDriver({
|
||||||
|
localDir,
|
||||||
|
publicPrefix,
|
||||||
|
cdnBaseUrl,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('returns a relative public URL for local uploads without CDN', () => {
|
||||||
|
expect(createDriver().getPublicUrl('2026/07/file.jpg')).toBe('/uploads/2026/07/file.jpg');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('normalizes trailing slash in public prefix', () => {
|
||||||
|
expect(createDriver('/uploads/').getPublicUrl('2026/07/file.jpg')).toBe('/uploads/2026/07/file.jpg');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('normalizes missing leading slash in public prefix', () => {
|
||||||
|
expect(createDriver('uploads').getPublicUrl('2026/07/file.jpg')).toBe('/uploads/2026/07/file.jpg');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses CDN base URL when configured', () => {
|
||||||
|
expect(createDriver('/uploads', 'https://cdn.example.com/assets/').getPublicUrl('2026/07/file.jpg')).toBe(
|
||||||
|
'https://cdn.example.com/assets/2026/07/file.jpg',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -6,7 +6,6 @@ export interface LocalDriverOptions {
|
|||||||
localDir: string;
|
localDir: string;
|
||||||
publicPrefix: string;
|
publicPrefix: string;
|
||||||
cdnBaseUrl: string;
|
cdnBaseUrl: string;
|
||||||
baseUrl: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本地磁盘存储驱动(默认)。文件经 Nest 静态目录对外访问。
|
// 本地磁盘存储驱动(默认)。文件经 Nest 静态目录对外访问。
|
||||||
@@ -61,10 +60,17 @@ export class LocalDriver implements StorageDriver {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getPublicPrefix(): string {
|
||||||
|
const raw = (this.opts.publicPrefix || '/uploads').trim();
|
||||||
|
if (raw === '/') return '';
|
||||||
|
return `/${raw.replace(/^\/+|\/+$/g, '')}`;
|
||||||
|
}
|
||||||
|
|
||||||
getPublicUrl(key: string): string {
|
getPublicUrl(key: string): string {
|
||||||
|
const publicPath = `${this.getPublicPrefix()}/${key}`;
|
||||||
if (this.opts.cdnBaseUrl) {
|
if (this.opts.cdnBaseUrl) {
|
||||||
return `${this.opts.cdnBaseUrl.replace(/\/$/, '')}/${key}`;
|
return `${this.opts.cdnBaseUrl.replace(/\/$/, '')}/${key}`;
|
||||||
}
|
}
|
||||||
return `${this.opts.baseUrl.replace(/\/$/, '')}${this.opts.publicPrefix}/${key}`;
|
return publicPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ export class StorageAdminService {
|
|||||||
localDir: dto.localDir || this.config.get<string>('storage.localDir') || './storage',
|
localDir: dto.localDir || this.config.get<string>('storage.localDir') || './storage',
|
||||||
publicPrefix: '/uploads',
|
publicPrefix: '/uploads',
|
||||||
cdnBaseUrl: dto.cdnBaseUrl || '',
|
cdnBaseUrl: dto.cdnBaseUrl || '',
|
||||||
baseUrl: this.config.get<string>('baseUrl') || 'http://localhost:3000',
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ export class StorageService implements OnModuleInit {
|
|||||||
localDir: s.localDir,
|
localDir: s.localDir,
|
||||||
publicPrefix: s.publicPrefix,
|
publicPrefix: s.publicPrefix,
|
||||||
cdnBaseUrl: s.cdnBaseUrl,
|
cdnBaseUrl: s.cdnBaseUrl,
|
||||||
baseUrl: this.config.get<string>('baseUrl') || 'http://localhost:3000',
|
|
||||||
});
|
});
|
||||||
this.logger.log('存储驱动:本地磁盘');
|
this.logger.log('存储驱动:本地磁盘');
|
||||||
return driver;
|
return driver;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import PhotoSwipe from 'photoswipe';
|
import PhotoSwipe from 'photoswipe';
|
||||||
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
import PhotoSwipeLightbox from 'photoswipe/lightbox';
|
||||||
import 'photoswipe/style.css';
|
import 'photoswipe/style.css';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
|
|
||||||
export interface MediaItem {
|
export interface MediaItem {
|
||||||
url?: string;
|
url?: string;
|
||||||
@@ -67,7 +68,9 @@ function bindWheelZoom(lightbox: PhotoSwipeLightbox): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openMediaViewer(items: MediaItem[], index = 0): Promise<void> {
|
export async function openMediaViewer(items: MediaItem[], index = 0): Promise<void> {
|
||||||
const list = (items || []).filter((item) => item.url);
|
const list = (items || [])
|
||||||
|
.map((item) => ({ ...item, url: resolveMediaUrl(item.url) }))
|
||||||
|
.filter((item) => item.url);
|
||||||
if (!list.length) return;
|
if (!list.length) return;
|
||||||
const start = Math.min(Math.max(index, 0), list.length - 1);
|
const start = Math.min(Math.max(index, 0), list.length - 1);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
export function resolveMediaUrl(url?: string | null): string {
|
||||||
|
const value = String(url || '').trim();
|
||||||
|
if (!value) return '';
|
||||||
|
if (/^\d{4}\/\d{2}\/\d{2}\/[^?#]+$/i.test(value)) {
|
||||||
|
return `/uploads/${value}`;
|
||||||
|
}
|
||||||
|
if (/^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?\/uploads\//i.test(value)) {
|
||||||
|
return value.replace(/^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?/i, '');
|
||||||
|
}
|
||||||
|
if (typeof window !== 'undefined' && /^https?:\/\//i.test(value)) {
|
||||||
|
try {
|
||||||
|
const parsed = new URL(value);
|
||||||
|
if (parsed.origin === window.location.origin && parsed.pathname.startsWith('/uploads/')) {
|
||||||
|
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
@@ -81,13 +81,13 @@
|
|||||||
>
|
>
|
||||||
<video
|
<video
|
||||||
v-if="isVideo(s.media)"
|
v-if="isVideo(s.media)"
|
||||||
:src="s.media.url"
|
:src="mediaUrl(s.media)"
|
||||||
class="carousel-media"
|
class="carousel-media"
|
||||||
muted
|
muted
|
||||||
playsinline
|
playsinline
|
||||||
preload="metadata"
|
preload="metadata"
|
||||||
/>
|
/>
|
||||||
<img v-else :src="s.media.url" :alt="s.media.name" class="carousel-media" loading="lazy" />
|
<img v-else :src="mediaUrl(s.media)" :alt="s.media.name" class="carousel-media" loading="lazy" />
|
||||||
<div v-if="isVideo(s.media)" class="play-overlay">
|
<div v-if="isVideo(s.media)" class="play-overlay">
|
||||||
<svg viewBox="0 0 64 64" width="56" height="56" aria-hidden="true">
|
<svg viewBox="0 0 64 64" width="56" height="56" aria-hidden="true">
|
||||||
<circle cx="32" cy="32" r="30" fill="rgba(0,0,0,0.42)" />
|
<circle cx="32" cy="32" r="30" fill="rgba(0,0,0,0.42)" />
|
||||||
@@ -176,10 +176,10 @@
|
|||||||
<span class="field-value">
|
<span class="field-value">
|
||||||
<img
|
<img
|
||||||
v-if="f.type === 'IMAGE' && f.value"
|
v-if="f.type === 'IMAGE' && f.value"
|
||||||
:src="f.value"
|
:src="mediaUrl(f.value)"
|
||||||
class="field-img"
|
class="field-img"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@click="openViewer([{ url: f.value, type: 'image', name: f.label }], 0)"
|
@click="openViewer([{ url: mediaUrl(f.value), type: 'image', name: f.label }], 0)"
|
||||||
/>
|
/>
|
||||||
<a v-else-if="(f.type === 'LINK' || f.type === 'FILE') && safeUrl(f.value)" :href="safeUrl(f.value)" target="_blank" rel="noopener" class="field-link">
|
<a v-else-if="(f.type === 'LINK' || f.type === 'FILE') && safeUrl(f.value)" :href="safeUrl(f.value)" target="_blank" rel="noopener" class="field-link">
|
||||||
{{ f.type === 'FILE' ? t('field.viewFile') : f.value }}
|
{{ f.type === 'FILE' ? t('field.viewFile') : f.value }}
|
||||||
@@ -208,8 +208,8 @@
|
|||||||
<div v-if="expanded.has(i)" class="tl-media">
|
<div v-if="expanded.has(i)" class="tl-media">
|
||||||
<div v-for="(m, j) in n.media" :key="j" class="tl-media-item" @click="openViewer(n.media, j)">
|
<div v-for="(m, j) in n.media" :key="j" class="tl-media-item" @click="openViewer(n.media, j)">
|
||||||
<div class="tl-media-thumb">
|
<div class="tl-media-thumb">
|
||||||
<video v-if="isVideo(m)" :src="m.url" muted playsinline preload="metadata" />
|
<video v-if="isVideo(m)" :src="mediaUrl(m)" muted playsinline preload="metadata" />
|
||||||
<img v-else :src="m.url" loading="lazy" />
|
<img v-else :src="mediaUrl(m)" loading="lazy" />
|
||||||
<div v-if="isVideo(m)" class="tl-play">▶</div>
|
<div v-if="isVideo(m)" class="tl-play">▶</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="m.name" class="tl-cap text-ellipsis">{{ m.name }}</div>
|
<div v-if="m.name" class="tl-cap text-ellipsis">{{ m.name }}</div>
|
||||||
@@ -237,9 +237,9 @@
|
|||||||
<div v-if="currentCert" class="cert">
|
<div v-if="currentCert" class="cert">
|
||||||
<img
|
<img
|
||||||
v-if="currentCert.url"
|
v-if="currentCert.url"
|
||||||
:src="currentCert.url"
|
:src="mediaUrl(currentCert)"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@click="openViewer(data.certificates.map((c) => ({ url: c.url, name: c.name, type: 'image' })), certIndex)"
|
@click="openViewer(data.certificates.map((c) => ({ url: mediaUrl(c), name: c.name, type: 'image' })), certIndex)"
|
||||||
/>
|
/>
|
||||||
<div v-else class="cert-placeholder">{{ currentCert.name }}</div>
|
<div v-else class="cert-placeholder">{{ currentCert.name }}</div>
|
||||||
<div class="cert-head">
|
<div class="cert-head">
|
||||||
@@ -380,6 +380,7 @@ import { fetchTrace, fetchAppInfo } from '@/api';
|
|||||||
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
|
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
|
||||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||||
|
import { resolveMediaUrl } from '@/utils/mediaUrl';
|
||||||
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -428,16 +429,20 @@ function ellipsis(s?: string) {
|
|||||||
if (!s) return '-';
|
if (!s) return '-';
|
||||||
return s.length > 16 ? `${s.slice(0, 8)}…${s.slice(-6)}` : s;
|
return s.length > 16 ? `${s.slice(0, 8)}…${s.slice(-6)}` : s;
|
||||||
}
|
}
|
||||||
function isVideo(m: { type?: string; url?: string }) {
|
function mediaUrl(value?: string | { url?: string; key?: string } | null): string {
|
||||||
return m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || '');
|
if (typeof value === 'string') return resolveMediaUrl(value);
|
||||||
|
return resolveMediaUrl(value?.url || value?.key);
|
||||||
|
}
|
||||||
|
function isVideo(m: { type?: string; url?: string; key?: string }) {
|
||||||
|
return m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(mediaUrl(m));
|
||||||
}
|
}
|
||||||
// 仅允许 http(s) 或站内相对路径作为外链,过滤 javascript:/data: 等危险协议
|
// 仅允许 http(s) 或站内相对路径作为外链,过滤 javascript:/data: 等危险协议
|
||||||
function safeUrl(v?: string): string {
|
function safeUrl(v?: string): string {
|
||||||
if (!v) return '';
|
const url = mediaUrl(v);
|
||||||
return /^(https?:\/\/|\/)/i.test(v) ? v : '';
|
return /^(https?:\/\/|\/)/i.test(url) ? url : '';
|
||||||
}
|
}
|
||||||
function openViewer(items: any[], index: number) {
|
function openViewer(items: any[], index: number) {
|
||||||
openMediaViewer(items.filter((item) => item?.url), index);
|
openMediaViewer(items.map((item) => ({ ...item, url: mediaUrl(item) })).filter((item) => item?.url), index);
|
||||||
}
|
}
|
||||||
function switchCert(step: number) {
|
function switchCert(step: number) {
|
||||||
const total = data.value?.certificates?.length || 0;
|
const total = data.value?.certificates?.length || 0;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export default defineConfig({
|
|||||||
host: true,
|
host: true,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': { target: 'http://localhost:3000', changeOrigin: true },
|
'/api': { target: 'http://localhost:3000', changeOrigin: true },
|
||||||
|
'/uploads': { target: 'http://localhost:3000', changeOrigin: true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user