🐛 修复过时用法

This commit is contained in:
目棃
2024-07-26 22:03:44 +08:00
parent e9252bbfcd
commit a7a0a8b0e0

View File

@@ -1,7 +1,7 @@
/** /**
* @file utils/TGClient.ts * @file utils/TGClient.ts
* @desc 负责米游社客户端的 callback 处理 * @desc 负责米游社客户端的 callback 处理
* @since Beta v0.5.0 * @since Beta v0.5.1
*/ */
import { event, core, webviewWindow } from "@tauri-apps/api"; import { event, core, webviewWindow } from "@tauri-apps/api";
@@ -99,7 +99,7 @@ class TGClient {
/** /**
* @func getSaveImgJS * @func getSaveImgJS
* @since Beta v0.3.7 * @since Beta v0.5.1
* @desc 获取保存图片的 JS * @desc 获取保存图片的 JS
* @param {string} url - 图片链接 * @param {string} url - 图片链接
* @param {string} format - 图片格式 * @param {string} format - 图片格式
@@ -107,22 +107,21 @@ class TGClient {
*/ */
getSaveImgJS(url: string, format: string): string { getSaveImgJS(url: string, format: string): string {
return `javascript:(async function() { return `javascript:(async function() {
const _t = window.__TAURI__; var _path = window.__TAURI__.path;
const defaultPath = await _t.path.downloadDir() + Date.now() + '.${format}'; var saveDefault = await _path.downloadDir() + _path.sep() + Date.now() + '.${format}';
const savePath = await _t.dialog.save({ var savePath = await window.__TAURI_PLUGIN_DIALOG__.save({
title: '保存图片', title: '保存图片',
filters: [{ name: '图片', extensions: ['png'] }], filters: [{ name: '图片', extensions: ['${format}'] }],
defaultPath: defaultPath, defaultPath: saveDefault,
}); });
if (savePath) { if(savePath !== null) {
const resBlob = await _t.http.fetch('${url}',{ var resBlob = await window.__TAURI_PLUGIN_HTTP__.fetch('${url}',{
method: 'GET', method: 'GET'
responseType: _t.http.ResponseType.Binary }).then(res => res.blob());
}); var buffer = new Uint8Array(await resBlob.arrayBuffer());
const buffer = new Uint8Array(resBlob.data); await window.__TAURI_PLUGIN_FS__.writeBinaryFile({
await _t.fs.writeBinaryFile({
contents: buffer, contents: buffer,
path: savePath, path: savePath
}); });
alert('保存成功'); alert('保存成功');
} }