This commit is contained in:
seb
2026-10-16 13:51:18 +02:00
parent d851c6e1e9
commit 764d6f850a
12 changed files with 2211 additions and 328 deletions

View File

@@ -9,6 +9,7 @@ import ChatBubbleOutlineRoundedIcon from '@mui/icons-material/ChatBubbleOutlineR
import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined';
import { tileBaseSx, TILE_SIZE } from 'dashgui/tiles';
import SkeleHashImage from '../settings/SkeleHashImage';
import { enqueueSnackbar } from 'notistack';
import { generateTextThumbnail } from '../../utils/textThumbnail';
import chatAutomat from '../../automats/chatAutomat';
import {
@@ -79,20 +80,44 @@ export class Attachment extends PureComponent {
let textContent = attachment.text || '';
if (!textContent && (attachment.file instanceof Blob || attachment.file instanceof File)) {
try {
textContent = await attachment.file.text();
} catch (err) {
console.error('Fehler beim Lesen des Texts:', err);
if (attachment.file.size > 0) {
try {
textContent = await attachment.file.text();
} catch (err) {
console.error('Fehler beim Lesen des Texts:', err);
}
} else {
const docId = this.props.docId ?? attachment.manifestId;
const fileId = attachment.fileId ?? attachment.id;
const kind = this.props.kind || 'delivery';
const prefix = kind === 'delivery' ? 'delivery' : kind === 'quote' ? 'quote' : 'order';
if (docId != null && fileId != null) {
try {
const res = await fetch(`/api/${prefix}/${encodeURIComponent(docId)}/file/${encodeURIComponent(fileId)}`, {
credentials: 'include',
});
if (res.ok) {
textContent = await res.text();
}
} catch (fetchErr) {
console.error('Fehler beim Laden der Datei:', fetchErr);
}
}
}
}
const trimmed = (textContent || '').trim();
if (!trimmed) return;
if (!trimmed) {
enqueueSnackbar('Datei enthält keinen Text zum Erwähnen im Chat.', { variant: 'warning' });
return;
}
const title = attachment.name ? `Text aus „${attachment.name}“:` : 'Text:';
const quote = `${title}\n\`\`\`\n${trimmed}\n\`\`\``;
chatAutomat.actions.insertPrompt(quote);
const size = attachment.size || new Blob([trimmed]).size;
chatAutomat.actions.insertExtractionSnippet({
text: trimmed,
size,
});
enqueueSnackbar('Text im Chat erwähnt', { variant: 'success' });
};
handleDelete = (e) => {
@@ -265,6 +290,7 @@ export class Attachment extends PureComponent {
disabled={disabled}
onClick={this.handleRescan}
aria-label="Zu Text"
title="Zu Text"
sx={{
bgcolor: SCRIM_ACTION,
color: WHITE,
@@ -285,6 +311,7 @@ export class Attachment extends PureComponent {
disabled={disabled}
onClick={this.handleMentionInChat}
aria-label="Im Chat erwähnen"
title="Im Chat erwähnen"
sx={{
bgcolor: SCRIM_ACTION,
color: WHITE,
@@ -304,6 +331,7 @@ export class Attachment extends PureComponent {
disabled={disabled}
onClick={this.handleDelete}
aria-label="Löschen"
title="Löschen"
sx={{
bgcolor: SCRIM_ACTION,
color: WHITE,