2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-06-12 03:28:37 +00:00

[refactor] Attachment images (#11961)

* Add new Attachment model fields:

- is_image
- thumbnail

* Cache if the attachment is an image

* Add new setting for controlling max upload size

* Validate uploaded attachment file

* Add tqdm for progress bars

* Refactor migrations

- Don't need is_image field
- Can introspect from the thumbnail

* Data migration for existing attachments

* Bump API version

* Update tests and validators

* Add "is_image" field to the Attachment model

* Offload to background task

* Implement unit tests

* Docs

* Add unit test for data migration

* Additional unit test

* Omit migration tests from code coverage

* Additional unit tests
This commit is contained in:
Oliver
2026-05-22 23:37:32 +10:00
committed by GitHub
parent 74d9ab6d11
commit 27ca0836e7
22 changed files with 624 additions and 8 deletions
@@ -12,6 +12,7 @@ import {
} from '@tabler/icons-react';
import { type ReactNode, useMemo } from 'react';
import { generateUrl } from '../../functions/urls';
import { Thumbnail } from '../images/Thumbnail';
/**
* Return an icon based on the provided filename
@@ -59,9 +60,11 @@ export function attachmentIcon(attachment: string): ReactNode {
*/
export function AttachmentLink({
attachment,
thumbnail,
external
}: Readonly<{
attachment: string;
thumbnail?: string;
external?: boolean;
}>): ReactNode {
const url = useMemo(() => {
@@ -82,7 +85,13 @@ export function AttachmentLink({
return (
<Group justify='left' gap='sm' wrap='nowrap'>
{external ? <IconLink /> : attachmentIcon(attachment)}
{thumbnail ? (
<Thumbnail src={thumbnail} hover size={16} />
) : external ? (
<IconLink />
) : (
attachmentIcon(attachment)
)}
{!!attachment ? (
<Anchor href={url} target='_blank' rel='noopener noreferrer'>
{text}
@@ -57,6 +57,7 @@ export default function SystemSettings() {
'DISPLAY_FULL_NAMES',
'DISPLAY_PROFILE_INFO',
'WEEK_STARTS_ON',
'INVENTREE_UPLOAD_MAX_SIZE',
'INVENTREE_STRICT_URLS'
]}
/>
@@ -49,7 +49,12 @@ function attachmentTableColumns(): TableColumn[] {
noWrap: true,
render: (record: any) => {
if (record.attachment) {
return <AttachmentLink attachment={record.attachment} />;
return (
<AttachmentLink
thumbnail={record.thumbnail}
attachment={record.attachment}
/>
);
} else if (record.link) {
return <AttachmentLink attachment={record.link} external />;
} else {
@@ -300,6 +305,11 @@ export function AttachmentTable({
name: 'is_file',
label: t`Is File`,
description: t`Show file attachments`
},
{
name: 'is_image',
label: t`Is Image`,
description: t`Show image attachments`
}
];
}, []);