Skip to content

Commit

Permalink
fix(decode): make header to json correct
Browse files Browse the repository at this point in the history
  • Loading branch information
s1rius committed May 27, 2024
1 parent 8f58f94 commit 2edc82d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,4 @@ jobs:
if: ${{ runner.os == 'macOS' }}
run: cargo build -Z build-std -p ezlog --release --lib --target aarch64-apple-ios
- name: Clippy Check
# tauri cant run from cargo
run: |
cargo clippy -p ezlog --all-features -- -D warnings
cargo clippy -p ezlogcli --all-features -- -D warnings
run: cargo clippy --all --all-features -- -D warnings
2 changes: 1 addition & 1 deletion ezlog-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["ezlog"]
crate-type = ["lib", "cdylib", "staticlib"]

[features]
default = ["json"]
default = []
log = ["dep:log"]
json = ["serde", "serde_json", "bitflags/serde"]
decode = ["aes-gcm", "regex", "log", "hex"]
Expand Down
2 changes: 1 addition & 1 deletion ui-tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tauri-build = { version = "1.5.2", features = [] }
tauri = { version = "1.6", features = ["shell-open", "window-center", "window-close", "window-hide", "window-maximize", "window-minimize", "window-print", "window-show", "window-start-dragging"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
ezlog = { version = "0.2.0", path = "../../ezlog-core", features = ["decode"] }
ezlog = { version = "0.2.0", path = "../../ezlog-core", features = ["decode", "json"] }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
22 changes: 3 additions & 19 deletions ui-tauri/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
};

use ezlog::EZLogConfigBuilder;
use serde_json::json;

fn main() {
tauri::Builder::default()
Expand All @@ -31,25 +32,8 @@ fn parse_header_and_extra(file_path: String) -> Result<String, String> {
let mut cursor = Cursor::new(contents);
ezlog::decode::decode_header_and_extra(&mut cursor)
.map(|header_and_extra| {
let extra_tuple = header_and_extra.1.unwrap_or_default();
let json_string = format!(
"{{\"{}\":{},\"{}\":{},\"{}\":{},\"{}\":\"{}\",\"{}\":\"{}\"}}",
"timestamp",
header_and_extra.0.timestamp().unix_timestamp(),
"version",
Into::<u8>::into(*header_and_extra.0.version()),
"encrypt",
if header_and_extra.0.is_encrypt() {
1
} else {
0
},
"extra",
extra_tuple.0,
"extra_encode",
extra_tuple.1
);
json_string
let extra_tuple: (String, String) = header_and_extra.1.unwrap_or_default();
json!({"header": header_and_extra.0, "extra": extra_tuple.0, "extra_encode": extra_tuple.1}).to_string()
})
.map_err(|e| e.to_string())
}
Expand Down
23 changes: 13 additions & 10 deletions ui-tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { onMounted, ref } from "vue";
import Modal from './Modal.vue'
const logs = ref<Record[]>([]);
const add = (items: Record[]) => {
const addRecords = (items: Record[]) => {
logs.value = []
logs.value.push(...items)
showTable.value = logs.value.length > 0
}
Expand All @@ -29,7 +30,11 @@ logColors.set('Error', "rgb(244, 67, 54)");
type Header = {
timestamp: 0,
version: 2,
encrypt: 0,
cipher: string,
}
type HeaderWithExtra = {
header: Header,
extra: "",
extra_encode: ""
}
Expand Down Expand Up @@ -62,7 +67,7 @@ async function fetchLogs(path: string, k: string, n: string) {
await invoke('parse_log_file_to_records', { filePath: path, key: k, nonce: n })
.then((logs: any) => {
let records: Record[] = JSON.parse(logs).map((item: string) => <Record>JSON.parse(item));
add(records)
addRecords(records)
})
.catch((error: any) => {
console.error('Error fetching logs:', error);
Expand All @@ -73,10 +78,10 @@ async function parse_header_and_extra(path: string) {
console.log('parse file dropped:', path);
currentPath.value = path;
await invoke('parse_header_and_extra', { filePath: path }).then(async (result: any) => {
const header = JSON.parse(result as string) as Header
console.log(header)
currentExtra.value = header.extra_encode + ":\n" + header.extra
if (header.encrypt == 0) {
const header_extra = JSON.parse(result as string) as HeaderWithExtra
currentExtra.value = header_extra.extra_encode + ":\n" + header_extra.extra
const noEncrypt = "NONE" == header_extra.header.cipher;
if (noEncrypt) {
fetchLogs(path, "", "")
} else {
showModal.value = true;
Expand All @@ -100,9 +105,7 @@ function getColorClass(data: string) {
listen('tauri://file-drop', (event: Event<string[]>) => {
if (event.payload && event.payload.length > 0) {
const firstFilePath = event.payload[0];
console.log('First file dropped:', firstFilePath);
// Now you can do something with the first file path
// For example, reading the file content or processing the file
console.log('file dropped:', firstFilePath);
parse_header_and_extra(firstFilePath)
}
})
Expand Down

0 comments on commit 2edc82d

Please sign in to comment.