mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-14 21:35:19 +00:00
refactor: refactor PDF export logic
This commit is contained in:
parent
333cbb8a27
commit
4d80bf889d
3 changed files with 8 additions and 8 deletions
|
|
@ -77,6 +77,7 @@
|
||||||
await downloadChatPdf({
|
await downloadChatPdf({
|
||||||
title: chat.chat.title,
|
title: chat.chat.title,
|
||||||
stylizedPdfExport: $settings?.stylizedPdfExport ?? true,
|
stylizedPdfExport: $settings?.stylizedPdfExport ?? true,
|
||||||
|
containerElementId: 'full-messages-container',
|
||||||
chatText: await getChatAsText(),
|
chatText: await getChatAsText(),
|
||||||
async onBeforeRender() {
|
async onBeforeRender() {
|
||||||
showFullMessages = true;
|
showFullMessages = true;
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@
|
||||||
await downloadChatPdf({
|
await downloadChatPdf({
|
||||||
title: chat.chat.title,
|
title: chat.chat.title,
|
||||||
stylizedPdfExport: $settings?.stylizedPdfExport ?? true,
|
stylizedPdfExport: $settings?.stylizedPdfExport ?? true,
|
||||||
|
containerElementId: 'full-messages-container',
|
||||||
chatText: await getChatAsText(chat),
|
chatText: await getChatAsText(chat),
|
||||||
async onBeforeRender() {
|
async onBeforeRender() {
|
||||||
showFullMessages = true;
|
showFullMessages = true;
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ export const downloadNotePdf = async (note: NoteData): Promise<void> => {
|
||||||
* Plain text mode: Exports chat content as plain text with basic formatting.
|
* Plain text mode: Exports chat content as plain text with basic formatting.
|
||||||
*
|
*
|
||||||
* @param options - Configuration object
|
* @param options - Configuration object
|
||||||
* @param options.containerElementId - ID of the container element to render (for stylized mode). Defaults to 'full-messages-container'
|
* @param options.containerElementId - ID of the container element to render (for stylized mode).
|
||||||
* @param options.chatText - Plain text content (required for plain text mode)
|
* @param options.chatText - Plain text content (required for plain text mode)
|
||||||
* @param options.title - PDF filename (without .pdf extension)
|
* @param options.title - PDF filename (without .pdf extension)
|
||||||
* @param options.stylizedPdfExport - Whether to use stylized PDF export (default: true)
|
* @param options.stylizedPdfExport - Whether to use stylized PDF export (default: true)
|
||||||
|
|
@ -386,12 +386,10 @@ export const downloadNotePdf = async (note: NoteData): Promise<void> => {
|
||||||
export const downloadChatPdf = async (options: ChatPdfOptions): Promise<void> => {
|
export const downloadChatPdf = async (options: ChatPdfOptions): Promise<void> => {
|
||||||
console.log('Downloading PDF', options);
|
console.log('Downloading PDF', options);
|
||||||
|
|
||||||
if (options.stylizedPdfExport ?? true) {
|
if ((options.stylizedPdfExport ?? true) && options.containerElementId) {
|
||||||
await options.onBeforeRender?.();
|
await options.onBeforeRender?.();
|
||||||
|
|
||||||
const containerElement = document.getElementById(
|
const containerElement = document.getElementById(options.containerElementId);
|
||||||
options.containerElementId || 'full-messages-container'
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
if (containerElement) {
|
if (containerElement) {
|
||||||
const virtualWidth = DEFAULT_VIRTUAL_WIDTH;
|
const virtualWidth = DEFAULT_VIRTUAL_WIDTH;
|
||||||
|
|
@ -423,10 +421,10 @@ export const downloadChatPdf = async (options: ChatPdfOptions): Promise<void> =>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.chatText) {
|
if (options.chatText) {
|
||||||
console.error('chatText is required for plain text PDF export');
|
await exportPlainTextToPdf(options.chatText, `chat-${options.title}.pdf`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await exportPlainTextToPdf(options.chatText, `chat-${options.title}.pdf`);
|
throw new Error('Either containerElementId or chatText is required');
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue