fix(file): 解决OSS图片处理参数导致的文件访问问题
- 在SelectFile组件中为文件链接添加stripOssImageProcess处理 - 从common工具库导入并使用stripOssImageProcess函数 - 在creditMpCustomer编辑页面对文件URL进行图片处理参数清理 - 在creditMpCustomer列表页面添加sanitizeFileUrl函数处理文件URL - 修改文件规范化逻辑以确保非图片文件移除OSS处理参数
This commit is contained in:
@@ -49,7 +49,7 @@
|
||||
/>
|
||||
<a
|
||||
v-else
|
||||
:href="file.url"
|
||||
:href="sanitizeFileUrl(file.url, file.isImage)"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
@@ -108,6 +108,7 @@ import {
|
||||
} from '@/api/credit/creditMpCustomer';
|
||||
import type {CreditMpCustomer, CreditMpCustomerParam} from '@/api/credit/creditMpCustomer/model';
|
||||
import {exportCreditData} from '../utils/export';
|
||||
import { stripOssImageProcess } from '@/utils/common';
|
||||
|
||||
type NormalizedFile = {
|
||||
name?: string;
|
||||
@@ -213,6 +214,10 @@ const tryParseJson = (value: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const sanitizeFileUrl = (url: string, isImage: boolean) => {
|
||||
return isImage ? url : (stripOssImageProcess(url) as string);
|
||||
};
|
||||
|
||||
const filesCache = new Map<string, NormalizedFile[]>();
|
||||
|
||||
const normalizeFiles = (raw: unknown): NormalizedFile[] => {
|
||||
@@ -223,19 +228,21 @@ const normalizeFiles = (raw: unknown): NormalizedFile[] => {
|
||||
.map((item: any) => {
|
||||
if (!item) return null;
|
||||
if (typeof item === 'string') {
|
||||
const url = sanitizeFileUrl(item, isImageUrl(item));
|
||||
return {
|
||||
url: item,
|
||||
thumbnail: item,
|
||||
name: guessNameFromUrl(item),
|
||||
isImage: isImageUrl(item)
|
||||
url,
|
||||
thumbnail: url,
|
||||
name: guessNameFromUrl(url),
|
||||
isImage: isImageUrl(url)
|
||||
} satisfies NormalizedFile;
|
||||
}
|
||||
const url = item.url || item.path || item.href;
|
||||
if (!url || typeof url !== 'string') return null;
|
||||
const rawUrl = item.url || item.path || item.href;
|
||||
const url = typeof rawUrl === 'string' ? rawUrl : undefined;
|
||||
if (!url) return null;
|
||||
const thumbnail = typeof item.thumbnail === 'string' ? item.thumbnail : undefined;
|
||||
const name = typeof item.name === 'string' ? item.name : guessNameFromUrl(url);
|
||||
const isImage = typeof item.isImage === 'boolean' ? item.isImage : isImageUrl(url);
|
||||
return {url, thumbnail, name, isImage} satisfies NormalizedFile;
|
||||
return {url: sanitizeFileUrl(url, isImage), thumbnail, name, isImage} satisfies NormalizedFile;
|
||||
})
|
||||
.filter(Boolean) as NormalizedFile[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user