fix(plugin-file-manager): fix image url (#6459)

* fix(plugin-file-manager): fix image url

* fix(plugin-file-manager): fix url with search part

* fix(plugin-file-manager): fix lightbox preview url

* fix(plugin-file-manager): encode link url
This commit is contained in:
Junyi 2025-03-14 00:10:00 +08:00 committed by GitHub
parent 3d8c27ff1b
commit 78455c1a5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 11 deletions

View File

@ -43,10 +43,10 @@ attachmentFileTypes.add({
},
getThumbnailURL(file) {
if (file.preview) {
return file.preview;
return encodeFileURL(file.preview);
}
if (file.url) {
return `${file.url}${file.thumbnailRule || ''}`;
return encodeFileURL(`${file.url}${file.thumbnailRule || ''}`);
}
if (file.originFileObj) {
return URL.createObjectURL(file.originFileObj);
@ -65,9 +65,9 @@ attachmentFileTypes.add({
return (
<LightBox
// discourageDownloads={true}
mainSrc={list[index]?.url}
nextSrc={list[(index + 1) % list.length]?.url}
prevSrc={list[(index + list.length - 1) % list.length]?.url}
mainSrc={encodeFileURL(list[index]?.url)}
nextSrc={encodeFileURL(list[(index + 1) % list.length]?.url)}
prevSrc={encodeFileURL(list[(index + list.length - 1) % list.length]?.url)}
onCloseRequest={() => onSwitchIndex(null)}
onMovePrevRequest={() => onSwitchIndex((index + list.length - 1) % list.length)}
onMoveNextRequest={() => onSwitchIndex((index + 1) % list.length)}
@ -264,7 +264,7 @@ function AttachmentListItem(props) {
) : null,
];
const wrappedItem = file.url ? (
<a target="_blank" rel="noopener noreferrer" href={file.url} onClick={handleClick}>
<a target="_blank" rel="noopener noreferrer" href={encodeFileURL(file.url)} onClick={handleClick}>
{item}
</a>
) : (

View File

@ -7,7 +7,7 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
export { attachmentFileTypes } from './shared';
export { attachmentFileTypes, encodeFileURL } from './shared';
export { useUploadStyles } from './style';
export * from './Upload';

View File

@ -273,9 +273,10 @@ export function encodeFileURL(url: string): string {
return url;
}
const parts = url.split('/');
const [base, search = ''] = url.split('?');
const parts = base.split('/');
const filename = parts.pop();
parts.push(encodeURIComponent(filename));
const encodedURL = parts.join('/');
const encodedURL = `${parts.join('/')}${search ? `?${search}` : ''}`;
return encodedURL;
}

View File

@ -7,7 +7,7 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { useAPIClient, useApp, withDynamicSchemaProps } from '@nocobase/client';
import { encodeFileURL, useAPIClient, useApp, withDynamicSchemaProps } from '@nocobase/client';
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import Vditor from 'vditor';
import { defaultToolbar } from '../interfaces/markdown-vditor';
@ -81,7 +81,7 @@ export const Edit = withDynamicSchemaProps((props) => {
data: {
errFiles: [],
succMap: {
[response.data.filename]: response.data.url,
[response.data.filename]: encodeFileURL(response.data.url),
},
},
};