using @tauri-apps/plugin-http replace @tauri-apps/api/http

This commit is contained in:
lloydzhou 2024-09-25 19:49:11 +08:00
parent 29296d42d7
commit 4c9fe56f33
7 changed files with 35 additions and 43 deletions

View File

@ -2,8 +2,8 @@ import { useEffect, useState } from "react";
import { showToast } from "./components/ui-lib";
import Locale from "./locales";
import { RequestMessage } from "./client/api";
import { ServiceProvider, REQUEST_TIMEOUT_MS } from "./constant";
import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http";
import { ServiceProvider } from "./constant";
import { fetch as tauriFetch } from "@tauri-apps/plugin-http";
export function trimTopic(topic: string) {
// Fix an issue where double quotes still show in the Indonesian language
@ -287,35 +287,18 @@ export function showPlugins(provider: ServiceProvider, model: string) {
return false;
}
export function fetch(
url: string,
options?: Record<string, unknown>,
): Promise<any> {
if (window.__TAURI__) {
const payload = options?.body || options?.data;
return tauriFetch(url, {
...options,
body:
payload &&
({
type: "Text",
payload,
} as any),
timeout: ((options?.timeout as number) || REQUEST_TIMEOUT_MS) / 1000,
responseType:
options?.responseType == "text" ? ResponseType.Text : ResponseType.JSON,
} as any);
}
return window.fetch(url, options);
}
export function adapter(config: Record<string, unknown>) {
const { baseURL, url, params, ...rest } = config;
const path = baseURL ? `${baseURL}${url}` : url;
const fetchUrl = params
? `${path}?${new URLSearchParams(params as any).toString()}`
: path;
return fetch(fetchUrl as string, { ...rest, responseType: "text" });
if (window.__TAURI__) {
return tauriFetch(fetchUrl, rest)
.then((res) => res.text())
.then((data: any) => ({ data }));
}
return window.fetch(fetchUrl as string, rest);
}
export function safeLocalStorage(): {

View File

@ -25,6 +25,7 @@
"@hello-pangea/dnd": "^16.5.0",
"@next/third-parties": "^14.1.0",
"@svgr/webpack": "^6.5.1",
"@tauri-apps/plugin-http": "^2.0.0-rc.2",
"@vercel/analytics": "^0.1.11",
"@vercel/speed-insights": "^1.0.2",
"axios": "^1.7.5",
@ -55,7 +56,6 @@
"zustand": "^4.3.8"
},
"devDependencies": {
"@tauri-apps/api": "^1.6.0",
"@tauri-apps/cli": "^2.0.0-rc.0",
"@types/js-yaml": "4.0.9",
"@types/lodash-es": "^4.17.12",

10
src-tauri/Cargo.lock generated
View File

@ -3820,7 +3820,7 @@ dependencies = [
"webkit2gtk",
"webview2-com",
"windows 0.58.0",
"wry",
"wry 0.43.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -4594,7 +4594,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@ -4945,6 +4945,12 @@ name = "wry"
version = "0.43.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4d715cf5fe88e9647f3d17b207b6d060d4a88e7171d4ccb2d2c657dd1d44728"
replace = "wry 0.43.1 (git+https://github.com/lloydzhou/wry?branch=webkitgtk-data_manager-directory)"
[[package]]
name = "wry"
version = "0.43.1"
source = "git+https://github.com/lloydzhou/wry?branch=webkitgtk-data_manager-directory#b854092847fadbc398aa727a1ed710adb3f4c8ea"
dependencies = [
"base64 0.22.1",
"block",

View File

@ -4,7 +4,7 @@ version = "0.1.0"
description = "A cross platform app for LLM ChatBot."
authors = ["GPTsMotion Tech LLC"]
license = "mit"
repository = ""
repository = "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web"
default-run = "nextchat"
edition = "2021"
rust-version = "1.71"
@ -24,7 +24,7 @@ serde = { version = "1.0", features = ["derive"] }
log = "0.4"
tauri = { version = "2.0.0-rc.15", features = [] }
tauri-plugin-log = "2.0.0-rc"
tauri-plugin-http = "2.0.0-rc"
tauri-plugin-http = "2.0.0-rc.5"
[replace]
# using this version from github fixed data_directory for webkitgtk
@ -36,7 +36,7 @@ panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
# strip = true # Remove debug symbols
[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.

View File

@ -7,13 +7,8 @@
"core:default",
"core:window:allow-start-dragging",
"core:window:allow-maximize",
"http:default",
"http:allow-fetch",
"http:allow-fetch-cancel",
"http:allow-fetch-read-body",
"http:allow-fetch-send",
{
"identifier": "http:allow-fetch",
"identifier": "http:default",
"allow": [
{
"url": "https://*"

View File

@ -1,6 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"productName": "NextChat",
"mainBinaryName": "next-chat",
"identifier": "com.yida.chatgpt.next.web",
"version": "2.15.4",
"build": {

View File

@ -1490,10 +1490,10 @@
"@swc/counter" "^0.1.3"
tslib "^2.4.0"
"@tauri-apps/api@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.6.0.tgz#745b7e4e26782c3b2ad9510d558fa5bb2cf29186"
integrity sha512-rqI++FWClU5I2UBp4HXFvl+sBWkdigBkxnpJDQUWttNyG7IZP4FwQGhTNL5EOw0vI8i6eSAJ5frLqO7n7jbJdg==
"@tauri-apps/api@^2.0.0-rc.4":
version "2.0.0-rc.5"
resolved "https://registry.npmjs.org/@tauri-apps/api/-/api-2.0.0-rc.5.tgz#9e790680f5cf691b0ae4c25c4de6696f340df401"
integrity sha512-JWs69pE9NsQdcqTpEVBepAZ08+jgQWuthIiTiaWRq/YlCLgnqq0KfC9sDem55uJ0YpgsytZuyj+m6b6q8oiD2g==
"@tauri-apps/cli-darwin-arm64@2.0.0-rc.16":
version "2.0.0-rc.16"
@ -1561,6 +1561,13 @@
"@tauri-apps/cli-win32-ia32-msvc" "2.0.0-rc.16"
"@tauri-apps/cli-win32-x64-msvc" "2.0.0-rc.16"
"@tauri-apps/plugin-http@^2.0.0-rc.2":
version "2.0.0-rc.2"
resolved "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.0.0-rc.2.tgz#385a3c0808db86b59ab0b183c85e4fd2de989cbd"
integrity sha512-s/AbbMaQPgqnIOoObvWNAjJOV17gyf9G+U6gmvjLoFbt7D6jsujOUW6fn+Oe/+rzNSEeo1ZSVrUoMen5DgM+OA==
dependencies:
"@tauri-apps/api" "^2.0.0-rc.4"
"@trysound/sax@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad"