no redux
This commit is contained in:
@@ -8,8 +8,43 @@ import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
|
||||
import SyncIcon from '@mui/icons-material/Sync';
|
||||
import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined';
|
||||
import { tileBaseSx, TILE_SIZE } from 'dashgui/tiles';
|
||||
import { generateTextThumbnail } from '../../utils/textThumbnail';
|
||||
|
||||
export class Attachment extends PureComponent {
|
||||
state = {
|
||||
generatedThumbnail: null,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.ensureThumbnail();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.attachment !== prevProps.attachment) {
|
||||
this.ensureThumbnail();
|
||||
}
|
||||
}
|
||||
|
||||
async ensureThumbnail() {
|
||||
const { attachment } = this.props;
|
||||
if (!attachment || attachment.thumbnail) return;
|
||||
const isCsv = attachment.type === 'text/csv' || attachment.name?.toLowerCase().endsWith('.csv');
|
||||
const isText = attachment.type?.startsWith('text/') || attachment.name?.toLowerCase().endsWith('.txt') || isCsv;
|
||||
if (!isText) return;
|
||||
|
||||
const source = attachment.text || attachment.file;
|
||||
if (!source) return;
|
||||
|
||||
try {
|
||||
const thumb = await generateTextThumbnail(source);
|
||||
if (thumb && this.props.attachment === attachment) {
|
||||
this.setState({ generatedThumbnail: thumb });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fehler beim Generieren des Text-Thumbnails:', err);
|
||||
}
|
||||
}
|
||||
|
||||
handleRescan = (e) => {
|
||||
e?.stopPropagation?.();
|
||||
const { attachment, onRescan } = this.props;
|
||||
@@ -56,7 +91,7 @@ export class Attachment extends PureComponent {
|
||||
|
||||
render() {
|
||||
const { attachment, disabled, sx } = this.props;
|
||||
const thumbnail = attachment?.thumbnail;
|
||||
const thumbnail = attachment?.thumbnail || this.state.generatedThumbnail;
|
||||
const name = attachment?.name || 'Dokument';
|
||||
const size = attachment?.size;
|
||||
const isPdf = attachment?.type === 'application/pdf' || name.toLowerCase().endsWith('.pdf');
|
||||
|
||||
@@ -341,10 +341,18 @@ export function collectFilesForUpload(attachments = [], { onlyNew = false } = {}
|
||||
}
|
||||
}
|
||||
|
||||
let thumbavif = null;
|
||||
if (attachment.thumbnail) {
|
||||
thumbavif = attachment.thumbnail.includes(',')
|
||||
? attachment.thumbnail.split(',')[1]
|
||||
: attachment.thumbnail;
|
||||
}
|
||||
|
||||
files.push({
|
||||
file: fileToUpload,
|
||||
name: attachment.name || fileToUpload.name,
|
||||
mimetype: attachment.type || fileToUpload.type,
|
||||
thumbavif,
|
||||
});
|
||||
}
|
||||
return files;
|
||||
@@ -389,6 +397,10 @@ export async function buildManifestBody(
|
||||
const filesToUpload = collectFilesForUpload(form.attachments, { onlyNew: isUpdate });
|
||||
if (filesToUpload.length > 0) {
|
||||
const formData = new FormData();
|
||||
body.filesMeta = filesToUpload.map((item) => ({
|
||||
name: item.name,
|
||||
thumbavif: item.thumbavif ?? null,
|
||||
}));
|
||||
formData.append('data', JSON.stringify(body));
|
||||
for (const item of filesToUpload) {
|
||||
formData.append('files', item.file, item.name);
|
||||
|
||||
Reference in New Issue
Block a user