ChatGPT
ChatGPT copied to clipboard
[Bug] Download file (.md/.pdf) is working, but the 'open_file' command fails
Version
v0.9.2
Bug description
I think the issue here, on Windows machines, in the open_file command, the path argument contains a mix of forward and back slashes. The Open_file command then just opens an Explorer window to a default path, and not the file just downloaded.
Example, from my log file I see: open_file: C:\Users\MXX.chatgpt\download/pdf/fq2fbm.pdf
I think this fails because of the forward slashes - this is my guess.
OS
Windows 10
Environment
No response
Please try v0.10.0
Just tried it - the correct folder now opens, but the file does not; Checking the logs:
[2023-01-25][02:57:17][chatgpt::utils][[9INFO[0m] open_file: C:\Users\xxxx\.chatgpt\download\pdf\1n4m4wy.pdf
[2023-01-25][02:58:12][chatgpt::utils][[9mINFO[0m] open_file: C:\Users\xxxx\.chatgpt\notes\aegck9.md
Should the open_file command open the file in a default application?
Only Explorer opens - which is fine, if that's the expected behavior.
Also, the pdf looks like it's one long image pasted into a pdf. Is that the intended behaviour? That's also OK, since the .md file can be converted to a pdf with text.
It will only open the directory where the file is located, not open the file (this is the expected behavior, because considering the exported file may require secondary operations by the user, so did not open the file itself).
PDF export using jsPDF, I have not yet studied in depth whether its API supports text content.
When you're handling the pdf it looks like you're putting a .png image in there from the code:
async function handlePdf(imgData, canvas, pixelRatio) {
const { jsPDF } = window.jspdf;
const orientation = canvas.width > canvas.height ? "l" : "p";
var pdf = new jsPDF(orientation, "pt", [
canvas.width / pixelRatio,
canvas.height / pixelRatio,
]);
var pdfWidth = pdf.internal.pageSize.getWidth();
var pdfHeight = pdf.internal.pageSize.getHeight();
pdf.addImage(imgData, "PNG", 0, 0, pdfWidth, pdfHeight, '', 'FAST');
const { pathname, id, filename } = getName();
const data = pdf.__private__.getArrayBuffer(pdf.__private__.buildDocument());
await invoke('download', { name: `download/pdf/${id}.pdf`, blob: Array.from(new Uint8Array(data)) });
await invoke('download_list', { pathname, filename, id, dir: 'download' });
Maybe you can inject the .md file instead of a png. I'm just guessing here.
If you just inject markdown you will lose the style, it should be html with css.
Am I misreading the code above that's injecting imgData, PNG?
The code snippet you sent is the code that generates the PDF, which is drawn via canvas, and I also found a related issues to explain how it works now. https://github.com/parallax/jsPDF/issues/1580#issuecomment-419227348