Risuai 0.6.3 first commit

This commit is contained in:
kwaroran
2023-05-07 12:41:45 +09:00
parent 50e5e1d917
commit 2c5c7d2694
98 changed files with 15070 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
[build]
target = 'x86_64-pc-windows-msvc'
[target]

3
src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# Generated by Cargo
# will have compiled files and executables
/target/

3889
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

28
src-tauri/Cargo.toml Normal file
View File

@@ -0,0 +1,28 @@
[package]
name = "risuai"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.2.1", features = [] }
[dependencies]
tauri = { version = "1.2.4", features = ["app-all", "dialog-all", "fs-all", "http-all", "os-all", "path-all", "process-relaunch", "protocol-all", "shell-open", "window-maximize", "window-set-fullscreen"] }
serde_json = "1.0"
tiktoken-rs = "0.4.0"
base64 = "0.21.0"
reqwest = { version = "0.11.16", features = ["json"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]
# [lib]
# crate-type = ["staticlib", "cdylib", "rlib"]

3
src-tauri/build.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

81
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,81 @@
// 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 std::time::Duration;
#[tauri::command]
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()),
};
let mut headers = HeaderMap::new();
let method = method.to_string();
if let Some(obj) = headers_json.as_object() {
for (key, value) in obj {
let header_name = match HeaderName::from_bytes(key.as_bytes()) {
Ok(name) => name,
Err(e) => return format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
};
let header_value = match HeaderValue::from_str(value.as_str().unwrap_or("")) {
Ok(value) => value,
Err(e) => return format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
};
headers.insert(header_name, header_value);
}
} else {
return format!(r#"{{"success":false,"body":"Invalid header JSON"}}"#);
}
let client = reqwest::Client::new();
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{
response = client
.get(&url)
.headers(headers)
.timeout(Duration::from_secs(120))
.send()
.await;
}
match response {
Ok(resp) => {
let bytes = match resp.bytes().await {
Ok(b) => b,
Err(e) => return format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
};
let encoded = general_purpose::STANDARD.encode(&bytes);
format!(r#"{{"success":true,"body":"{}"}}"#, encoded)
}
Err(e) => format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
}
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, native_request])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

110
src-tauri/tauri.conf.json Normal file
View File

@@ -0,0 +1,110 @@
{
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build",
"devPath": "http://localhost:5174",
"distDir": "../dist",
"withGlobalTauri": false
},
"package": {
"productName": "RisuAI",
"version": "0.6.2"
},
"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/**/*"]
},
"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"
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"resizable": true,
"title": "RisuAI",
"width": 1024,
"height": 768,
"minWidth": 300,
"minHeight": 500
}
]
}
}