Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
aaaaahhhhhhhhh
Browse files Browse the repository at this point in the history
  • Loading branch information
raisfeld-ori committed Apr 24, 2024
1 parent 1a1a5d2 commit b15a242
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 7 deletions.
148 changes: 148 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rust-crypto ="*"
serde_json = "1"
dirs = "*"
once_cell = "*"
image = "*"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/data/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub fn gather_type(file: &str) -> &str {
if file_extension.is_none(){return "Unknown";}
match file_extension.unwrap(){
"png" => {return "Image"}
"jpg" => {return "Image"}
"txt" => {return "Text"}
"html" => {return "HTML"}
"mp4" => {return "Video"}
Expand Down
15 changes: 14 additions & 1 deletion src-tauri/src/fs/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs::read_dir;
use std::path::PathBuf;
use dirs::data_dir;
pub use base64::{decode_config, encode_config, URL_SAFE};
use serde_json::Value;
pub use tauri::Runtime;
use crate::data::auth::{init_dir, Encodable};
use crate::data::json::init_user_data;
Expand Down Expand Up @@ -37,6 +38,19 @@ pub fn bytes_to_string(bytes: Vec<u8>) -> Result<String, ()> {
else {return Ok(result.unwrap());}
}

#[tauri::command]
pub fn image_to_string(bytes: Vec<u8>) -> Result<(String, String), Value> {
let reader = image::io::Reader::new(std::io::Cursor::new(bytes));
let reader = reader.with_guessed_format();
if reader.is_err(){return Err(Value::Null)}
let reader = reader.unwrap();
let format = reader.format();
let result = reader.decode();
if result.is_err() || format.is_none() {return Err(Value::Null)}
let result = base64::encode(result.unwrap().as_bytes());
return Ok((result, format.unwrap().to_mime_type().to_string()));
}

#[test]
fn test_general(){
let name = "test";
Expand All @@ -53,7 +67,6 @@ pub fn first_init<R: Runtime>(app: tauri::AppHandle<R>, window: tauri::Window<R>
unsafe{FS.init_fs()};
Ok(())
}

#[tauri::command]
pub fn console(value: String) {println!("{}", value)}
#[tauri::command]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fn main() {
tauri::Builder::default().invoke_handler(tauri::generate_handler![
first_init, console, user_get, authenticate_user, save_user, user_exists, load_user, ls, pwd, cd, create_user, read_file,
create_value, mkdir, system_get, system_make, user_make, close_app, mk, upload_file, cd_back, rm, file_exists, gather_type,
bytes_to_string
bytes_to_string, image_to_string
]).run(tauri::generate_context!()).expect("failed to run the code");
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ export default function image_viewer(file_selected: string | null) : AppInterfac
if (file_selected == null) {return;}
let name: string = await invoke('system_get', {key: 'name'});
let password: string = await invoke('system_get', {key: 'password'});
let bytes: string = await invoke('read_file', {name, password,file: file_selected});
let bytes = await invoke('read_file', {name, password,file: file_selected});
if (bytes == null) {return;}
set_image(bytes);
let data: [string, string] = await invoke('image_to_string', {bytes: bytes});
let data_blob = new Blob([data[0]], {type: data[1]});
let url = URL.createObjectURL(data_blob);
set_image(url);
}
let context_menu = <div>

</div>
let html = <div className="outer">
{/*for now, this is readonly, cause it would take a while to remake this as a text editor*/}
<img className="inner" src={image}>
</img>
</div>
let [screen, set_display, fullscreen] = App(html, 'text editor');
let [screen, set_display, fullscreen] = App(html, 'image viewer');
return {screen, set_display, fullscreen, context_menu, update};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export default function text_viewer(file_selected: string | null) : AppInterface
<textarea className="inner" readOnly={true} value={text}>
</textarea>
</div>
let [screen, set_display, fullscreen] = App(html, 'text editor');
let [screen, set_display, fullscreen] = App(html, 'text viewer');
return {screen, set_display, fullscreen, context_menu, update};
}

0 comments on commit b15a242

Please sign in to comment.