Migrate to Tauri V2
This commit is contained in:
3001
src-tauri/Cargo.lock
generated
3001
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -10,10 +10,10 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "1.4.0", features = [] }
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "1.6.0", features = [ "updater", "app-all", "dialog-all", "fs-all", "http-all", "os-all", "path-all", "process-relaunch", "protocol-all", "reqwest-client", "shell-open", "window-maximize", "window-set-fullscreen"] }
|
||||
tauri = { version = "2", features = ["protocol-asset"] }
|
||||
serde_json = "1.0"
|
||||
tiktoken-rs = "0.4.0"
|
||||
base64 = "0.21.0"
|
||||
@@ -23,13 +23,23 @@ zip = "0.6.6"
|
||||
tar = "0.4.40"
|
||||
eventsource-client = "0.12.2"
|
||||
futures = "0.3.30"
|
||||
actix-web = "4.0"
|
||||
actix-cors = "0.6"
|
||||
actix-rt = "2.5"
|
||||
url = "2.2"
|
||||
uuid = { version = "1.9.1", features = [ "v4" ] }
|
||||
tauri-plugin-fs = "2"
|
||||
tauri-plugin-os = "2"
|
||||
tauri-plugin-dialog = "2"
|
||||
tauri-plugin-process = "2"
|
||||
tauri-plugin-shell = "2"
|
||||
tauri-plugin-http = "2"
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
# DO NOT REMOVE!!
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
||||
|
||||
# [lib]
|
||||
# name = "alib"
|
||||
# crate-type = ["staticlib", "cdylib", "rlib", "lib"]
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-updater = "2"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
tauri_build::build()
|
||||
}
|
||||
|
||||
14
src-tauri/capabilities/desktop.json
Normal file
14
src-tauri/capabilities/desktop.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"identifier": "desktop-capability",
|
||||
"platforms": [
|
||||
"macOS",
|
||||
"windows",
|
||||
"linux"
|
||||
],
|
||||
"permissions": [
|
||||
"updater:default",
|
||||
"process:default",
|
||||
"shell:default",
|
||||
"http:default"
|
||||
]
|
||||
}
|
||||
73
src-tauri/capabilities/migrated.json
Normal file
73
src-tauri/capabilities/migrated.json
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"identifier": "migrated",
|
||||
"description": "permissions that were migrated from v1",
|
||||
"local": true,
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"fs:allow-read-file",
|
||||
"fs:allow-write-file",
|
||||
"fs:allow-read-dir",
|
||||
"fs:allow-copy-file",
|
||||
"fs:allow-mkdir",
|
||||
"fs:allow-remove",
|
||||
"fs:allow-remove",
|
||||
"fs:allow-rename",
|
||||
"fs:allow-exists",
|
||||
{
|
||||
"identifier": "fs:scope",
|
||||
"allow": [
|
||||
"$APPDATA",
|
||||
"$APPDATA/*",
|
||||
"$APPDATA/**/*",
|
||||
"$DOWNLOAD/*",
|
||||
"/data/**/*",
|
||||
"$RESOURCE/*"
|
||||
]
|
||||
},
|
||||
"core:window:allow-maximize",
|
||||
"core:window:allow-set-fullscreen",
|
||||
"shell:allow-open",
|
||||
"dialog:allow-open",
|
||||
"dialog:allow-save",
|
||||
"dialog:allow-message",
|
||||
"dialog:allow-ask",
|
||||
"dialog:allow-confirm",
|
||||
{
|
||||
"identifier": "http:default",
|
||||
"allow": [
|
||||
{
|
||||
"url": "https://*/*"
|
||||
},
|
||||
{
|
||||
"url": "https://*/**/*"
|
||||
},
|
||||
{
|
||||
"url": "http://*/*"
|
||||
},
|
||||
{
|
||||
"url": "http://*/**/*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"os:allow-platform",
|
||||
"os:allow-version",
|
||||
"os:allow-os-type",
|
||||
"os:allow-family",
|
||||
"os:allow-arch",
|
||||
"os:allow-exe-extension",
|
||||
"os:allow-locale",
|
||||
"os:allow-hostname",
|
||||
"process:allow-restart",
|
||||
"core:app:allow-app-show",
|
||||
"core:app:allow-app-hide",
|
||||
"fs:default",
|
||||
"os:default",
|
||||
"dialog:default",
|
||||
"process:default",
|
||||
"shell:default",
|
||||
"http:default"
|
||||
]
|
||||
}
|
||||
1
src-tauri/gen/schemas/acl-manifests.json
Normal file
1
src-tauri/gen/schemas/acl-manifests.json
Normal file
File diff suppressed because one or more lines are too long
1
src-tauri/gen/schemas/capabilities.json
Normal file
1
src-tauri/gen/schemas/capabilities.json
Normal file
@@ -0,0 +1 @@
|
||||
{"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"permissions":["updater:default","process:default","shell:default","http:default"],"platforms":["macOS","windows","linux"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","fs:allow-read-file","fs:allow-write-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":["$APPDATA","$APPDATA/*","$APPDATA/**/*","$DOWNLOAD/*","/data/**/*","$RESOURCE/*"]},"core:window:allow-maximize","core:window:allow-set-fullscreen","shell:allow-open","dialog:allow-open","dialog:allow-save","dialog:allow-message","dialog:allow-ask","dialog:allow-confirm",{"identifier":"http:default","allow":[{"url":"https://*/*"},{"url":"https://*/**/*"},{"url":"http://*/*"},{"url":"http://*/**/*"}]},"os:allow-platform","os:allow-version","os:allow-os-type","os:allow-family","os:allow-arch","os:allow-exe-extension","os:allow-locale","os:allow-hostname","process:allow-restart","core:app:allow-app-show","core:app:allow-app-hide","fs:default","os:default","dialog:default","process:default","shell:default","http:default"]}}
|
||||
5358
src-tauri/gen/schemas/desktop-schema.json
Normal file
5358
src-tauri/gen/schemas/desktop-schema.json
Normal file
File diff suppressed because it is too large
Load Diff
5358
src-tauri/gen/schemas/windows-schema.json
Normal file
5358
src-tauri/gen/schemas/windows-schema.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,24 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
use serde_json::Value;
|
||||
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use tauri::Manager;
|
||||
use tauri::State;
|
||||
use std::io::Write;
|
||||
use std::sync::Mutex;
|
||||
use std::{time::Duration, path::Path};
|
||||
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||
use serde_json::json;
|
||||
use serde_json::Value;
|
||||
use tauri::path::BaseDirectory;
|
||||
use std::collections::HashMap;
|
||||
use actix_cors::Cors;
|
||||
use tauri::api::path::app_data_dir;
|
||||
use actix_web::{web, HttpRequest, HttpResponse, HttpServer, Responder, App, post};
|
||||
use std::fs::File;
|
||||
struct HttpSecret(Mutex<String>);
|
||||
struct HttpPort(Mutex<u16>);
|
||||
use std::io::Write;
|
||||
use std::{path::Path, time::Duration};
|
||||
use tauri::Manager;
|
||||
use tauri::{AppHandle, Emitter};
|
||||
|
||||
#[tauri::command]
|
||||
async fn native_request(url: String, body: String, header: String, method:String) -> String {
|
||||
async fn native_request(url: String, body: String, header: String, method: String) -> String {
|
||||
let headers_json: Value = match serde_json::from_str(&header) {
|
||||
Ok(h) => h,
|
||||
Err(e) => return format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
|
||||
@@ -50,24 +43,23 @@ async fn native_request(url: String, body: String, header: String, method:String
|
||||
}
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let response:Result<reqwest::Response, reqwest::Error>;
|
||||
let response: Result<reqwest::Response, reqwest::Error>;
|
||||
|
||||
if method == "POST" {
|
||||
response = client
|
||||
.post(&url)
|
||||
.headers(headers)
|
||||
.timeout(Duration::from_secs(120))
|
||||
.body(body)
|
||||
.send()
|
||||
.await;
|
||||
}
|
||||
else{
|
||||
.post(&url)
|
||||
.headers(headers)
|
||||
.timeout(Duration::from_secs(120))
|
||||
.body(body)
|
||||
.send()
|
||||
.await;
|
||||
} else {
|
||||
response = client
|
||||
.get(&url)
|
||||
.headers(headers)
|
||||
.timeout(Duration::from_secs(120))
|
||||
.send()
|
||||
.await;
|
||||
.get(&url)
|
||||
.headers(headers)
|
||||
.timeout(Duration::from_secs(120))
|
||||
.send()
|
||||
.await;
|
||||
}
|
||||
|
||||
match response {
|
||||
@@ -80,14 +72,17 @@ async fn native_request(url: String, body: String, header: String, method:String
|
||||
};
|
||||
let encoded = general_purpose::STANDARD.encode(&bytes);
|
||||
|
||||
format!(r#"{{"success":true,"body":"{}","headers":{}}}"#, encoded, header_json)
|
||||
format!(
|
||||
r#"{{"success":true,"body":"{}","headers":{}}}"#,
|
||||
encoded, header_json
|
||||
)
|
||||
}
|
||||
Err(e) => format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn check_auth(fpath: String, auth: String) -> bool{
|
||||
fn check_auth(fpath: String, auth: String) -> bool {
|
||||
//check file exists
|
||||
let path = Path::new(&fpath);
|
||||
if !path.exists() {
|
||||
@@ -109,8 +104,6 @@ fn check_auth(fpath: String, auth: String) -> bool{
|
||||
println!("File {} is too large", path.display());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// read file, return false when error
|
||||
let got_auth = std::fs::read_to_string(&path);
|
||||
@@ -119,8 +112,7 @@ fn check_auth(fpath: String, auth: String) -> bool{
|
||||
if got_auth.is_err() {
|
||||
println!("Error reading file {}", path.display());
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
// check auth
|
||||
if got_auth.unwrap() != auth {
|
||||
println!("Auth does not match");
|
||||
@@ -129,11 +121,10 @@ fn check_auth(fpath: String, auth: String) -> bool{
|
||||
println!("Auth matches");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn install_python(path:String) -> bool{
|
||||
async fn install_python(path: String) -> bool {
|
||||
//get python embeddable depending on os
|
||||
let os = std::env::consts::OS;
|
||||
let url;
|
||||
@@ -142,12 +133,11 @@ async fn install_python(path:String) -> bool{
|
||||
std::fs::create_dir_all(&py_path).unwrap();
|
||||
}
|
||||
let zip_path: std::path::PathBuf = Path::new(&path).join("python.zip");
|
||||
|
||||
|
||||
println!("Path: {}", path);
|
||||
if os == "windows" {
|
||||
url = "https://www.python.org/ftp/python/3.11.7/python-3.11.7-embed-amd64.zip".to_string()
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
println!("OS not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -168,16 +158,13 @@ async fn install_python(path:String) -> bool{
|
||||
if os == "windows" {
|
||||
let mut zipf = ZipArchive::new(std::fs::File::open(&zip_path).unwrap()).unwrap();
|
||||
zipf.extract(&py_path).unwrap();
|
||||
}
|
||||
else if os == "linux" {
|
||||
} else if os == "linux" {
|
||||
let mut tarf = tar::Archive::new(std::fs::File::open(&zip_path).unwrap());
|
||||
tarf.unpack(&py_path).unwrap();
|
||||
}
|
||||
else if os == "macos" {
|
||||
} else if os == "macos" {
|
||||
let mut zipf = zip::ZipArchive::new(std::fs::File::open(&zip_path).unwrap()).unwrap();
|
||||
zipf.extract(&py_path).unwrap();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
println!("OS not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -191,20 +178,20 @@ async fn install_python(path:String) -> bool{
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
if !res.starts_with("Python ") {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
println!("{}", res);
|
||||
return true
|
||||
},
|
||||
return true;
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn install_pip(path:String) -> bool{
|
||||
async fn install_pip(path: String) -> bool {
|
||||
let py_path = Path::new(&path).join("python");
|
||||
let py_exec_path = py_path.join("python.exe");
|
||||
let get_pip_url = "https://bootstrap.pypa.io/get-pip.py";
|
||||
@@ -224,34 +211,34 @@ async fn install_pip(path:String) -> bool{
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
println!("{}", res);
|
||||
if !res.starts_with("Python ") {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
},
|
||||
return true;
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
#[tauri::command]
|
||||
fn check_requirements_local() -> String{
|
||||
fn check_requirements_local() -> String {
|
||||
let mut py = Command::new("python");
|
||||
let output = py.arg("--version").output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
if !res.starts_with("Python ") {
|
||||
return "Python is not installed".to_string()
|
||||
return "Python is not installed".to_string();
|
||||
}
|
||||
println!("{}", res);
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return "Python is not installed, or not loadable".to_string()
|
||||
return "Python is not installed, or not loadable".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,21 +248,21 @@ fn check_requirements_local() -> String{
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
if !res.starts_with("git version ") {
|
||||
return "Git is not installed".to_string()
|
||||
return "Git is not installed".to_string();
|
||||
}
|
||||
println!("{}", res);
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return "Git is not installed, or not loadable".to_string()
|
||||
return "Git is not installed, or not loadable".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
return "success".to_string()
|
||||
return "success".to_string();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn post_py_install(path:String){
|
||||
fn post_py_install(path: String) {
|
||||
let py_path = Path::new(&path).join("python");
|
||||
let py_pth_path = py_path.join("python311._pth");
|
||||
//uncomment python libs
|
||||
@@ -288,31 +275,38 @@ fn post_py_install(path:String){
|
||||
std::fs::write(&completed_path, "python311").unwrap();
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
fn install_py_dependencies(path:String, dependency:String) -> Result<(), String>{
|
||||
fn install_py_dependencies(path: String, dependency: String) -> Result<(), String> {
|
||||
println!("installing {}", dependency);
|
||||
let py_path = Path::new(&path).join("python");
|
||||
let py_exec_path = py_path.join("python.exe");
|
||||
let mut py = Command::new(py_exec_path);
|
||||
let output = py.arg("-m").arg("pip").arg("install").arg(dependency).output();
|
||||
let output = py
|
||||
.arg("-m")
|
||||
.arg("pip")
|
||||
.arg("install")
|
||||
.arg(dependency)
|
||||
.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
println!("{}", res);
|
||||
return Ok(())
|
||||
},
|
||||
return Ok(());
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return Err(e.to_string())
|
||||
return Err(e.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn run_py_server(handle: tauri::AppHandle, py_path:String){
|
||||
fn run_py_server(handle: tauri::AppHandle, py_path: String) {
|
||||
let py_exec_path = Path::new(&py_path).join("python").join("python.exe");
|
||||
let server_path = handle.path_resolver().resolve_resource("src-python/run.py").expect("failed to resolve resource");
|
||||
let server_path = handle
|
||||
.path()
|
||||
.resolve("src-python/run.py", BaseDirectory::Resource)
|
||||
.expect("failed to resolve resource");
|
||||
|
||||
let mut py_server = Command::new(&py_exec_path);
|
||||
//set working directory to server path
|
||||
@@ -320,78 +314,33 @@ fn run_py_server(handle: tauri::AppHandle, py_path:String){
|
||||
|
||||
println!("server_path: {}", server_path.display());
|
||||
println!("py_exec_path: {}", py_exec_path.display());
|
||||
let mut _child = py_server.arg("-m").arg("uvicorn").arg("--port").arg("10026").arg("main:app").spawn().expect("failed to execute process");
|
||||
let mut _child = py_server
|
||||
.arg("-m")
|
||||
.arg("uvicorn")
|
||||
.arg("--port")
|
||||
.arg("10026")
|
||||
.arg("main:app")
|
||||
.spawn()
|
||||
.expect("failed to execute process");
|
||||
println!("server started");
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn run_server_local(){
|
||||
let app_base_path = tauri::api::path::data_dir().unwrap().join("co.aiclient.risu");
|
||||
|
||||
//check app base path exists
|
||||
if !app_base_path.exists() {
|
||||
std::fs::create_dir_all(&app_base_path).unwrap();
|
||||
}
|
||||
|
||||
let server_path = app_base_path.clone().join("local_server");
|
||||
|
||||
//check server path exists
|
||||
if !&server_path.exists() {
|
||||
//git clone server
|
||||
let mut git = Command::new("git");
|
||||
let output = git
|
||||
.current_dir(&app_base_path.clone())
|
||||
.arg("clone")
|
||||
.arg("https://github.com/kwaroran/risu-exllama-connector.git")
|
||||
.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
println!("output: {}", res);
|
||||
},
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
println!("cloned");
|
||||
|
||||
let git_cloned_path = app_base_path.clone().join("risu-exllama-connector");
|
||||
|
||||
println!("git_cloned_path: {}", git_cloned_path.display());
|
||||
//rename folder to local_server
|
||||
std::fs::rename(git_cloned_path, server_path.clone()).unwrap();
|
||||
}
|
||||
|
||||
|
||||
//check os is windows
|
||||
if cfg!(target_os = "windows") {
|
||||
println!("windows runner");
|
||||
let command_location = &server_path.clone().join("run.cmd");
|
||||
let mut server = Command::new(command_location);
|
||||
let mut _child = server.current_dir(server_path).spawn().expect("failed to execute process");
|
||||
}
|
||||
else{
|
||||
println!("linux/mac runner");
|
||||
let command_location = &server_path.clone().join("run.sh");
|
||||
let mut server = Command::new(command_location);
|
||||
let mut _child = server.current_dir(server_path).spawn().expect("failed to execute process");
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn streamed_fetch(id:String, url:String, headers: String, body: String, handle: tauri::AppHandle) -> String {
|
||||
async fn streamed_fetch(
|
||||
id: String,
|
||||
url: String,
|
||||
headers: String,
|
||||
body: String,
|
||||
app: AppHandle
|
||||
) -> String {
|
||||
//parse headers
|
||||
let headers_json: Value = match serde_json::from_str(&headers) {
|
||||
Ok(h) => h,
|
||||
Err(e) => return format!(r#"{{"success":false, body:{}}}"#, e.to_string()),
|
||||
};
|
||||
let app = handle.app_handle();
|
||||
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
if let Some(obj) = headers_json.as_object() {
|
||||
for (key, value) in obj {
|
||||
@@ -415,13 +364,23 @@ async fn streamed_fetch(id:String, url:String, headers: String, body: String, ha
|
||||
.headers(headers)
|
||||
.timeout(Duration::from_secs(240))
|
||||
.body(body)
|
||||
.send().await;
|
||||
.send()
|
||||
.await;
|
||||
|
||||
match response {
|
||||
Ok(mut resp) => {
|
||||
let headers = resp.headers();
|
||||
let header_json = header_map_to_json(headers);
|
||||
app.emit_all("streamed_fetch", &format!(r#"{{"type": "headers", "body": {}, "id": "{}", "status": {}}}"#, header_json, id, resp.status().as_u16())).unwrap();
|
||||
app.emit(
|
||||
"streamed_fetch",
|
||||
&format!(
|
||||
r#"{{"type": "headers", "body": {}, "id": "{}", "status": {}}}"#,
|
||||
header_json,
|
||||
id,
|
||||
resp.status().as_u16()
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
loop {
|
||||
let byt = resp.chunk().await;
|
||||
match byt {
|
||||
@@ -431,140 +390,68 @@ async fn streamed_fetch(id:String, url:String, headers: String, body: String, ha
|
||||
}
|
||||
let chunk = chunk.unwrap();
|
||||
let encoded = general_purpose::STANDARD.encode(chunk);
|
||||
let emited = app.emit_all("streamed_fetch", &format!(r#"{{"type": "chunk", "body": "{}", "id": "{}"}}"#, encoded, id));
|
||||
let emited = app.emit(
|
||||
"streamed_fetch",
|
||||
&format!(
|
||||
r#"{{"type": "chunk", "body": "{}", "id": "{}"}}"#,
|
||||
encoded, id
|
||||
),
|
||||
);
|
||||
|
||||
match emited {
|
||||
Ok(_) => {},
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
return format!(r#"{{"success":false, body:{}}}"#, e.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
return format!(r#"{{"success":false, body:{}}}"#, e.to_string())
|
||||
}
|
||||
Err(e) => return format!(r#"{{"success":false, body:{}}}"#, e.to_string()),
|
||||
}
|
||||
}
|
||||
app.emit_all("streamed_fetch", &format!(r#"{{"type": "end", "id": "{}"}}"#, id)).unwrap();
|
||||
app.emit(
|
||||
"streamed_fetch",
|
||||
&format!(r#"{{"type": "end", "id": "{}"}}"#, id),
|
||||
)
|
||||
.unwrap();
|
||||
return "{\"success\":true}".to_string();
|
||||
}
|
||||
Err(e) => {
|
||||
return format!(r#"{{"success":false, body:{}}}"#, e.to_string())
|
||||
}
|
||||
Err(e) => return format!(r#"{{"success":false, body:{}}}"#, e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_http_secret(secret_state: State<HttpSecret>) -> String {
|
||||
secret_state.0.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_http_port(port_state: State<HttpPort>) -> u16 {
|
||||
port_state.0.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[post("/")]
|
||||
async fn write_binary_file_to_appdata(req: HttpRequest, body: web::Bytes, app_handle: web::Data<tauri::AppHandle>, secret: web::Data<String>) -> impl Responder {
|
||||
let query = req.query_string();
|
||||
let headers = req.headers();
|
||||
let req_secret = headers.get("x-tauri-secret").unwrap().to_str().unwrap();
|
||||
if req_secret != *secret.as_ref() {
|
||||
return HttpResponse::Unauthorized().body("Unauthorized");
|
||||
}
|
||||
let params: std::collections::HashMap<_, _> = url::form_urlencoded::parse(query.as_bytes()).into_owned().collect();
|
||||
let app_data_dir = app_data_dir(&app_handle.config()).expect("App dir must be returned by tauri");
|
||||
if let Some(file_path) = params.get("path") {
|
||||
let full_path = app_data_dir.join(file_path);
|
||||
if let Some(parent) = Path::new(&full_path).parent() {
|
||||
if let Err(e) = std::fs::create_dir_all(parent) {
|
||||
return HttpResponse::InternalServerError().body(format!("Failed to create directories: {}", e));
|
||||
}
|
||||
}
|
||||
|
||||
match File::create(&full_path) {
|
||||
Ok(mut file) => {
|
||||
if let Err(e) = file.write_all(&body) {
|
||||
return HttpResponse::InternalServerError().body(format!("Failed to write to file: {}", e));
|
||||
}
|
||||
HttpResponse::Ok().body("File written successfully")
|
||||
}
|
||||
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to create file: {}", e)),
|
||||
}
|
||||
} else {
|
||||
HttpResponse::BadRequest().body("Missing file path in query string")
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_http_server(handle: tauri::AppHandle, secret: String) {
|
||||
for port in 5354..65535 {
|
||||
let handle_copy = handle.clone();
|
||||
let secret_copy = secret.clone();
|
||||
let res = HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(
|
||||
Cors::default()
|
||||
.allow_any_origin()
|
||||
.allow_any_method()
|
||||
.allow_any_header()
|
||||
.max_age(3600)
|
||||
)
|
||||
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024)) // 1 GB
|
||||
.app_data(web::Data::new(handle_copy.clone()))
|
||||
.app_data(web::Data::new(secret_copy.clone()))
|
||||
.service(write_binary_file_to_appdata)
|
||||
})
|
||||
.bind(("127.0.0.1", port));
|
||||
match res {
|
||||
Ok(server) => {
|
||||
handle.manage(HttpPort(Mutex::new(port)));
|
||||
let _ = server.run().await;
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to bind to port {}: {}", port, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.manage(HttpSecret(uuid::Uuid::new_v4().to_string().into()))
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
greet,
|
||||
native_request,
|
||||
check_auth,
|
||||
check_requirements_local,
|
||||
run_server_local,
|
||||
install_python,
|
||||
install_pip,
|
||||
post_py_install,
|
||||
run_py_server,
|
||||
install_py_dependencies,
|
||||
streamed_fetch,
|
||||
get_http_secret,
|
||||
get_http_port
|
||||
])
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
let secret_state: State<HttpSecret> = app.state();
|
||||
let secret = secret_state.0.lock().unwrap().clone();
|
||||
std::thread::spawn(move || {
|
||||
let rt = actix_rt::Runtime::new().unwrap();
|
||||
rt.block_on(run_http_server(handle.clone(), secret.clone()));
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
|
||||
fn header_map_to_json(header_map: &HeaderMap) -> serde_json::Value {
|
||||
let mut map = HashMap::new();
|
||||
for (key, value) in header_map {
|
||||
map.insert(key.as_str().to_string(), value.to_str().unwrap().to_string());
|
||||
map.insert(
|
||||
key.as_str().to_string(),
|
||||
value.to_str().unwrap().to_string(),
|
||||
);
|
||||
}
|
||||
json!(map)
|
||||
}
|
||||
|
||||
5
src-tauri/src/mainx.txt
Normal file
5
src-tauri/src/mainx.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
alib::run();
|
||||
}
|
||||
@@ -2,108 +2,41 @@
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"beforeBuildCommand": "pnpm build",
|
||||
"devPath": "http://localhost:5174",
|
||||
"distDir": "../dist",
|
||||
"withGlobalTauri": false
|
||||
"frontendDist": "../dist",
|
||||
"devUrl": "http://localhost:5174"
|
||||
},
|
||||
"package": {
|
||||
"productName": "RisuAI",
|
||||
"version": "135.0.0"
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"resources": [
|
||||
"src-python/*"
|
||||
],
|
||||
"targets": "all",
|
||||
"createUpdaterArtifacts": "v1Compatible"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
"app": {
|
||||
"all": true
|
||||
},
|
||||
"process": {
|
||||
"relaunch": true
|
||||
},
|
||||
"protocol": {
|
||||
"all": true,
|
||||
"assetScope": ["asset","$APPDATA","$APPDATA/*","$APPDATA/**/*", "/data/**/*"]
|
||||
},
|
||||
"all": false,
|
||||
"shell": {
|
||||
"all": false,
|
||||
"open": true
|
||||
},
|
||||
"fs":{
|
||||
"all": true,
|
||||
"scope": ["$APPDATA","$APPDATA/*","$APPDATA/**/*", "$DOWNLOAD/*", "/data/**/*", "$RESOURCE/*"]
|
||||
},
|
||||
"path":{
|
||||
"all": true
|
||||
},
|
||||
"http": {
|
||||
"all": true,
|
||||
"request": true,
|
||||
"scope": ["https://*/*", "https://*/**/*","http://*/*", "http://*/**/*"]
|
||||
},
|
||||
"window": {
|
||||
"center": false,
|
||||
"close": false,
|
||||
"create": false,
|
||||
"hide": false,
|
||||
"maximize": true,
|
||||
"minimize": false,
|
||||
"print": false,
|
||||
"requestUserAttention": false,
|
||||
"setAlwaysOnTop": false,
|
||||
"setCursorGrab": false,
|
||||
"setCursorIcon": false,
|
||||
"setCursorPosition": false,
|
||||
"setCursorVisible": false,
|
||||
"setDecorations": false,
|
||||
"setFocus": false,
|
||||
"setFullscreen": true,
|
||||
"setIcon": false,
|
||||
"setIgnoreCursorEvents": false,
|
||||
"setMaxSize": false,
|
||||
"setMinSize": false,
|
||||
"setPosition": false,
|
||||
"setResizable": false,
|
||||
"setSize": false,
|
||||
"setSkipTaskbar": false,
|
||||
"setTitle": false,
|
||||
"show": false,
|
||||
"startDragging": false,
|
||||
"unmaximize": false,
|
||||
"unminimize": false
|
||||
},
|
||||
"dialog": {
|
||||
"all": true
|
||||
},
|
||||
"os": {
|
||||
"all": true
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"identifier": "co.aiclient.risu",
|
||||
"targets": "all",
|
||||
"resources": [
|
||||
"src-python/*"
|
||||
]
|
||||
},
|
||||
"security": {
|
||||
"csp": null
|
||||
},
|
||||
"productName": "RisuAI",
|
||||
"mainBinaryName": "RisuAI",
|
||||
"version": "135.0.0",
|
||||
"identifier": "co.aiclient.risu",
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"active": true,
|
||||
"endpoints": ["https://github.com/kwaroran/RisuAI/releases/latest/download/latest.json"],
|
||||
"dialog": false,
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDU2ODMzOTIxMDMxOTY1MUYKUldRZlpSa0RJVG1EVmx5Vm1WYlhFM29HMEJrUTRrYmg5dDQ0RFpvdUphNDdxQmVlWXJHVmV5TEYK",
|
||||
"endpoints": [
|
||||
"https://github.com/kwaroran/RisuAI/releases/latest/download/latest.json"
|
||||
],
|
||||
"windows": {
|
||||
"installMode": "passive"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": false,
|
||||
"windows": [
|
||||
{
|
||||
"fullscreen": false,
|
||||
@@ -113,8 +46,21 @@
|
||||
"height": 768,
|
||||
"minWidth": 300,
|
||||
"minHeight": 500,
|
||||
"fileDropEnabled": false
|
||||
"dragDropEnabled": false
|
||||
}
|
||||
]
|
||||
],
|
||||
"security": {
|
||||
"assetProtocol": {
|
||||
"scope": [
|
||||
"asset",
|
||||
"$APPDATA",
|
||||
"$APPDATA/*",
|
||||
"$APPDATA/**/*",
|
||||
"/data/**/*"
|
||||
],
|
||||
"enable": true
|
||||
},
|
||||
"csp": null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user