Skip to content

Commit

Permalink
🐛 修复图片保存失败(真)
Browse files Browse the repository at this point in the history
fix #56
  • Loading branch information
BTMuli committed Nov 2, 2023
1 parent e6eaa2e commit 8ae1d57
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils/TGClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ class TGClient {
*/
async onClickImg(payload: any): Promise<void> {
const url = payload.image_list[0].url;
const savePath = `${await path.downloadDir()}${path.sep}${Date.now().toString()}.png`;
const imageType = url.endsWith(".png") ? "png" : url.endsWith(".jpg") ? "jpg" : "png";
const savePath = `${await path.downloadDir()}${path.sep}${Date.now().toString()}.${imageType}`;
const executeJS = `javascript:(async function() {
const _t = window.__TAURI__;
const savePath = await _t.dialog.save({
Expand All @@ -456,9 +457,8 @@ class TGClient {
responseType: _t.http.ResponseType.Binary
});
const buffer = new Uint8Array(resBlob.data);
const blob = new Blob([buffer], { type: 'image/png' });
await _t.fs.writeBinaryFile({
contents: blob,
contents: buffer,
path: savePath,
});
alert('保存成功');
Expand Down

0 comments on commit 8ae1d57

Please sign in to comment.