1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00

fix: Set limit for displaying attachment content

Closes #1141
This commit is contained in:
Maksim Eltyshev 2025-05-26 14:35:23 +02:00
parent a7c1d4ca11
commit 978b2a7402
4 changed files with 21 additions and 7 deletions

View file

@ -11,6 +11,7 @@ import { useTranslation } from 'react-i18next';
import { Item as GalleryItem } from 'react-photoswipe-gallery'; import { Item as GalleryItem } from 'react-photoswipe-gallery';
import selectors from '../../../selectors'; import selectors from '../../../selectors';
import Config from '../../../constants/Config';
import Encodings from '../../../constants/Encodings'; import Encodings from '../../../constants/Encodings';
import { AttachmentTypes } from '../../../constants/Enums'; import { AttachmentTypes } from '../../../constants/Enums';
import ItemContent from './ItemContent'; import ItemContent from './ItemContent';
@ -70,13 +71,21 @@ const Item = React.memo(({ id, isVisible }) => {
break; break;
default: default:
if (attachment.data.encoding === Encodings.UTF8) { if (attachment.data.encoding === Encodings.UTF8) {
content = ( if (attachment.data.sizeInBytes <= Config.MAX_SIZE_IN_BYTES_TO_DISPLAY_CONTENT) {
<ContentViewer content = (
src={attachment.data.url} <ContentViewer
filename={attachment.data.filename} src={attachment.data.url}
className={classNames(styles.content, styles.contentViewer)} filename={attachment.data.filename}
/> className={classNames(styles.content, styles.contentViewer)}
); />
);
} else {
content = (
<span className={classNames(styles.content, styles.contentError)}>
{t('common.contentOfThisAttachmentIsTooBigToDisplay')}
</span>
);
}
} else { } else {
content = ( content = (
<span className={classNames(styles.content, styles.contentError)}> <span className={classNames(styles.content, styles.contentError)}>

View file

@ -15,6 +15,8 @@ const CARDS_LIMIT = 50;
const COMMENTS_LIMIT = 50; const COMMENTS_LIMIT = 50;
const ACTIVITIES_LIMIT = 50; const ACTIVITIES_LIMIT = 50;
const MAX_SIZE_IN_BYTES_TO_DISPLAY_CONTENT = 256 * 1024;
const IS_MAC = navigator.platform.startsWith('Mac'); const IS_MAC = navigator.platform.startsWith('Mac');
export default { export default {
@ -26,5 +28,6 @@ export default {
CARDS_LIMIT, CARDS_LIMIT,
COMMENTS_LIMIT, COMMENTS_LIMIT,
ACTIVITIES_LIMIT, ACTIVITIES_LIMIT,
MAX_SIZE_IN_BYTES_TO_DISPLAY_CONTENT,
IS_MAC, IS_MAC,
}; };

View file

@ -115,6 +115,7 @@ export default {
color: 'Color', color: 'Color',
comments: 'Comments', comments: 'Comments',
contentExceedsLimit: 'Content exceeds {{limit}}', contentExceedsLimit: 'Content exceeds {{limit}}',
contentOfThisAttachmentIsTooBigToDisplay: 'Content of this attachment is too big to display.',
copy_inline: 'copy', copy_inline: 'copy',
createBoard_title: 'Create Board', createBoard_title: 'Create Board',
createCustomFieldGroup_title: 'Create Custom Field Group', createCustomFieldGroup_title: 'Create Custom Field Group',

View file

@ -110,6 +110,7 @@ export default {
color: 'Color', color: 'Color',
comments: 'Comments', comments: 'Comments',
contentExceedsLimit: 'Content exceeds {{limit}}', contentExceedsLimit: 'Content exceeds {{limit}}',
contentOfThisAttachmentIsTooBigToDisplay: 'Content of this attachment is too big to display.',
copy_inline: 'copy', copy_inline: 'copy',
createBoard_title: 'Create Board', createBoard_title: 'Create Board',
createCustomFieldGroup_title: 'Create Custom Field Group', createCustomFieldGroup_title: 'Create Custom Field Group',