mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 21:43:59 +01:00
remove download pdf
temporary fix for vite-plugin-top-level-await
This commit is contained in:
parent
9cff66f783
commit
8ff5079266
|
@ -6,7 +6,7 @@ import {
|
||||||
chatToMarkdown,
|
chatToMarkdown,
|
||||||
downloadImg,
|
downloadImg,
|
||||||
downloadMarkdown,
|
downloadMarkdown,
|
||||||
downloadPDF,
|
// downloadPDF,
|
||||||
htmlToImg,
|
htmlToImg,
|
||||||
} from '@utils/chat';
|
} from '@utils/chat';
|
||||||
import ImageIcon from '@icon/ImageIcon';
|
import ImageIcon from '@icon/ImageIcon';
|
||||||
|
@ -55,7 +55,7 @@ const DownloadChat = React.memo(
|
||||||
<ImageIcon />
|
<ImageIcon />
|
||||||
Image
|
Image
|
||||||
</button>
|
</button>
|
||||||
<button
|
{/* <button
|
||||||
className='btn btn-neutral gap-2'
|
className='btn btn-neutral gap-2'
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (saveRef && saveRef.current) {
|
if (saveRef && saveRef.current) {
|
||||||
|
@ -76,7 +76,7 @@ const DownloadChat = React.memo(
|
||||||
>
|
>
|
||||||
<PdfIcon />
|
<PdfIcon />
|
||||||
PDF
|
PDF
|
||||||
</button>
|
</button> */}
|
||||||
<button
|
<button
|
||||||
className='btn btn-neutral gap-2'
|
className='btn btn-neutral gap-2'
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import html2canvas from 'html2canvas';
|
import html2canvas from 'html2canvas';
|
||||||
import jsPDF from 'jspdf';
|
// import jsPDF from 'jspdf';
|
||||||
import { ChatInterface, ConfigInterface, MessageInterface } from '@type/chat';
|
import { ChatInterface, ConfigInterface, MessageInterface } from '@type/chat';
|
||||||
import { roles } from '@type/chat';
|
import { roles } from '@type/chat';
|
||||||
import { Theme } from '@type/theme';
|
import { Theme } from '@type/theme';
|
||||||
|
@ -72,41 +72,41 @@ export const downloadImg = (imgData: string, fileName: string) => {
|
||||||
link.remove();
|
link.remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const downloadPDF = (
|
// export const downloadPDF = (
|
||||||
imageData: string,
|
// imageData: string,
|
||||||
theme: Theme,
|
// theme: Theme,
|
||||||
fileName: string
|
// fileName: string
|
||||||
) => {
|
// ) => {
|
||||||
const pdf = new jsPDF('p', 'mm');
|
// const pdf = new jsPDF('p', 'mm');
|
||||||
const imageProps = pdf.getImageProperties(imageData);
|
// const imageProps = pdf.getImageProperties(imageData);
|
||||||
const pageHeight = pdf.internal.pageSize.getHeight();
|
// const pageHeight = pdf.internal.pageSize.getHeight();
|
||||||
const pageWidth = pdf.internal.pageSize.getWidth();
|
// const pageWidth = pdf.internal.pageSize.getWidth();
|
||||||
const imgHeight = (imageProps.height * pageWidth) / imageProps.width;
|
// const imgHeight = (imageProps.height * pageWidth) / imageProps.width;
|
||||||
let heightLeft = imgHeight;
|
// let heightLeft = imgHeight;
|
||||||
let position = 0;
|
// let position = 0;
|
||||||
|
|
||||||
pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight);
|
// pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight);
|
||||||
heightLeft -= pageHeight;
|
// heightLeft -= pageHeight;
|
||||||
|
|
||||||
while (heightLeft >= 0) {
|
// while (heightLeft >= 0) {
|
||||||
position -= pageHeight;
|
// position -= pageHeight;
|
||||||
heightLeft -= pageHeight;
|
// heightLeft -= pageHeight;
|
||||||
pdf.addPage();
|
// pdf.addPage();
|
||||||
pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight);
|
// pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (heightLeft < 0) {
|
// if (heightLeft < 0) {
|
||||||
heightLeft = -heightLeft;
|
// heightLeft = -heightLeft;
|
||||||
if (theme === 'dark') {
|
// if (theme === 'dark') {
|
||||||
pdf.setFillColor(52, 53, 65);
|
// pdf.setFillColor(52, 53, 65);
|
||||||
} else {
|
// } else {
|
||||||
pdf.setFillColor(255, 255, 255);
|
// pdf.setFillColor(255, 255, 255);
|
||||||
}
|
// }
|
||||||
pdf.rect(0, pageHeight - heightLeft - 3, pageWidth, heightLeft + 3, 'F');
|
// pdf.rect(0, pageHeight - heightLeft - 3, pageWidth, heightLeft + 3, 'F');
|
||||||
}
|
// }
|
||||||
|
|
||||||
pdf.save(fileName);
|
// pdf.save(fileName);
|
||||||
};
|
// };
|
||||||
|
|
||||||
export const chatToMarkdown = (chat: ChatInterface) => {
|
export const chatToMarkdown = (chat: ChatInterface) => {
|
||||||
let markdown = `# ${chat.title}\n\n`;
|
let markdown = `# ${chat.title}\n\n`;
|
||||||
|
|
Loading…
Reference in a new issue