Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DSL/Resql/analytics/POST/overview-total-chats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ SELECT ts.ended,
FROM (
SELECT date_trunc(:group_period, period) AS ended
FROM generate_series(
date_trunc(:group_period, (current_date AT TIME ZONE :timezone - concat('1 ', :group_period)::INTERVAL)),
date_trunc(:group_period, (current_date AT TIME ZONE :timezone)),
date_trunc(:group_period, (NOW() AT TIME ZONE :timezone) - concat('1 ', :group_period)::INTERVAL),
date_trunc(:group_period, (NOW() AT TIME ZONE :timezone)),
concat('1 ', :group_period)::INTERVAL
) AS period
) ts
Expand Down
2 changes: 1 addition & 1 deletion GUI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@buerokratt-ria/header": "^0.1.47",
"@buerokratt-ria/menu": "^0.2.10",
"@buerokratt-ria/styles": "^0.0.1",
"@buerokratt-ria/common-gui-components": "^0.0.42",
"@buerokratt-ria/common-gui-components": "^0.0.43",
"@fontsource/roboto": "^4.5.8",
"@formkit/auto-animate": "^1.0.0-beta.6",
"@hookform/resolvers": "^2.9.11",
Expand Down
63 changes: 51 additions & 12 deletions GUI/src/components/ChatEvent/Markdownify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ interface MarkdownifyProps {
sanitizeLinks?: boolean;
}

const isValidImageUrl = (s: string): boolean => {
try {
const u = new URL(s);
if (!/^(https?|data):$/i.test(u.protocol)) return false;
if (s.startsWith('data:image/')) {
return /^data:image\/(png|jpe?g|gif|webp|svg\+xml|bmp);(base64,|charset=utf-8;)/i.test(s);
}
const path = u.pathname.toLowerCase();
const search = u.search.toLowerCase();
if (/\.(png|jpe?g|gif|webp|svg|ico|bmp|tiff?|avif|heic|heif|apng)([?#]|$)/i.test(path)) {
return true;
}
if (/\/(images?|img|photos?|pictures?|media|uploads?|thumb|avatar)\//i.test(path)) {
return true;
}
return /[?&](format|type|image|img|photo)=(png|jpe?g|gif|webp|svg|ico)/i.test(search);
} catch {
return false;
}
};

const LinkPreview: React.FC<{
href: string;
children: React.ReactNode;
Expand All @@ -31,21 +52,33 @@ const LinkPreview: React.FC<{
);
}

return !hasError ? (
<img
src={href}
alt={typeof children === 'string' ? children : 'Preview'}
style={{ maxWidth: '100%', height: 'auto', borderRadius: '20px' }}
onError={() => setHasError(true)}
/>
) : (
if (!isValidImageUrl(href)) {
return (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
>
{children}
</a>
);
}

return hasError ? (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
>
{children}
</a>
) : (
<img
src={href}
alt={typeof children === 'string' ? children : 'Preview'}
style={{ maxWidth: '100%', height: 'auto', borderRadius: '20px' }}
onError={() => setHasError(true)}
/>
);
};

Expand All @@ -61,16 +94,22 @@ function formatMessage(message?: string): string {
.replaceAll(/\\?\$v\w*/g, '')
.replaceAll(/\\?\$g\w*/g, '');

return filteredMessage
.replaceAll(/&#x([0-9A-Fa-f]+);/g, (_, hex: string) => String.fromCharCode(parseInt(hex, 16)))
const dataImagePattern = /((?:^|\s))(data:image\/[a-z0-9+]+;[^)\s]+)/gi;
const finalMessage = filteredMessage.replaceAll(
dataImagePattern,
(_, prefix, dataUrl) => `${prefix}[image](${dataUrl})`
);

return finalMessage
.replaceAll(/&#x([0-9A-F]+);/gi, (_, hex: string) => String.fromCharCode(parseInt(hex, 16)))
.replaceAll('&amp;', '&')
.replaceAll('&gt;', '>')
.replaceAll('&lt;', '<')
.replaceAll('&quot;', '"')
.replaceAll('&#39;', "'")
.replaceAll('&apos;', "'")
.replaceAll(/(^|\n)(\d{4})\.\s/g, (match, prefix, year) => {
const remainingText = filteredMessage.substring(filteredMessage.indexOf(match) + match.length);
const remainingText = finalMessage.substring(finalMessage.indexOf(match) + match.length);
const sentenceEnd = remainingText.indexOf('\n\n');
if (sentenceEnd !== -1) {
const currentSentence = remainingText.substring(0, sentenceEnd);
Expand All @@ -80,7 +119,7 @@ function formatMessage(message?: string): string {
}
return `${prefix}${year}\\. `;
})
.replaceAll(/(?<=\n)\d+\.\s/g, hasSpecialFormat(filteredMessage) ? '\n\n$&' : '$&')
.replaceAll(/(?<=\n)\d+\.\s/g, hasSpecialFormat(finalMessage) ? '\n\n$&' : '$&')
.replaceAll(/^(\s+)/g, (match) => match.replaceAll(' ', '&nbsp;'));
}

Expand Down
16 changes: 8 additions & 8 deletions GUI/src/components/services/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {DomainSelection} from "../../types/widgetModels";
import {api} from "./api";
import { DomainSelection } from '../../types/widgetModels';
import { api } from './api';

export async function getWidgetData(userId: string) {
const { data } = await api.get<DomainSelection[]>('accounts/widget-data', {
params: {
user_id: userId,
},
});
return data;
const { data } = await api.get<DomainSelection[]>('accounts/widget-data', {
params: {
user_id: userId,
},
});
return data;
}
Loading