diff --git a/README.md b/README.md
index 1755e65..440ac35 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
A ChatGPT App for all platforms
-English / [简体中文](./docs/README-zh-CN.md) / [繁體中文](./docs/README-zh-TW.md) / [Deutsch](./docs/README-de-DE.md) / [Français](./docs/README-fr-FR.md) / [Italiano](./docs/README-it-IT.md) / [한국어](./docs/README-kr-KR.md)
+
Built with Rust + Tauri + Vue + Axum
@@ -54,7 +54,7 @@ Timeout of OpenAI api request
# Run Android / iOS
-Comming soom
+Coming soom
# Thanks
- The initial frontend code was copied from [Chanzhaoyu/chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web)
diff --git a/shared/src/gpt.rs b/shared/src/gpt.rs
index c04b5bc..9550ead 100644
--- a/shared/src/gpt.rs
+++ b/shared/src/gpt.rs
@@ -208,18 +208,13 @@ pub async fn fetch_usage(rng: DateRange) -> Result {
"${url}/dashboard/billing/usage?start_date=${}&end_date=${}",
rng.start_date, rng.end_date
);
- let client = if let Some(c) = build_proxy_client() {
- c
- } else {
- reqwest::Client::new()
- };
+ let client = build_proxy_client().unwrap_or(reqwest::Client::new());
let res = client
.get(url_usage)
.header("Authorization", format!("Bearer ${key}"))
.header("Content-Type", "application/json")
.send()
.await?;
- res.status();
Ok(res.text().await?)
}
diff --git a/shared/src/network.rs b/shared/src/network.rs
index 7ff91e3..45dd064 100644
--- a/shared/src/network.rs
+++ b/shared/src/network.rs
@@ -69,6 +69,16 @@ fn get_auth(url: &str) -> Option<(String, String)> {
None
}
+pub async fn fetch(url: &str) -> crate::Result {
+ Ok(build_proxy_client()
+ .unwrap_or(reqwest::Client::new())
+ .get(url)
+ .send()
+ .await?
+ .text()
+ .await?)
+}
+
mod test {
#[test]
fn test_proxy() {
diff --git a/src-tauri/src/app/cmd.rs b/src-tauri/src/app/cmd.rs
index a7d198b..0d32efe 100644
--- a/src-tauri/src/app/cmd.rs
+++ b/src-tauri/src/app/cmd.rs
@@ -55,3 +55,10 @@ pub fn set(key: String, value: String) {
pub fn get(key: String) -> String {
std::env::var(key).unwrap_or_default()
}
+
+#[command]
+pub async fn fetch(url: String) -> std::result::Result {
+ Ok(shared::network::fetch(&url)
+ .await
+ .map_err(|x| x.to_string())?)
+}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 5316611..ae3f145 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -4,7 +4,7 @@ use app::cmd;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
- .invoke_handler(tauri::generate_handler![cmd::call, cmd::set, cmd::get])
+ .invoke_handler(tauri::generate_handler![cmd::call, cmd::set, cmd::get, cmd::fetch])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
diff --git a/src/components/common/PromptStore/index.vue b/src/components/common/PromptStore/index.vue
index 185f951..047a777 100644
--- a/src/components/common/PromptStore/index.vue
+++ b/src/components/common/PromptStore/index.vue
@@ -9,6 +9,7 @@ import { usePromptStore } from '@/store'
import { useBasicLayout } from '@/hooks/useBasicLayout'
import { t } from '@/locales'
import { getLanguage } from '@/hooks/useLanguage'
+import { isTauri, fetch as tauri_fetch } from '@/tauri'
interface DataProps {
renderKey: string
@@ -221,8 +222,14 @@ const exportPromptTemplate = () => {
const downloadPromptTemplate = async () => {
try {
importLoading.value = true
- const response = await fetch(downloadURL.value)
- const data = await response.text()
+ let data
+ if (isTauri) {
+ data = await tauri_fetch(downloadURL.value)
+ }
+ else {
+ const response = await fetch(downloadURL.value)
+ data = await response.text()
+ }
try {
const jsonData = JSON.parse(data)
if ('key' in jsonData[0] && 'value' in jsonData[0])
diff --git a/src/tauri/index.ts b/src/tauri/index.ts
index e8df48c..b1ef855 100644
--- a/src/tauri/index.ts
+++ b/src/tauri/index.ts
@@ -34,4 +34,8 @@ export async function loadEnvFromLocalStorage() {
await invoke('set', { key, value: env[key] })
}
+export async function fetch(url: string): Promise {
+ return invoke('fetch', { url })
+}
+
export default call