crawler
This commit is contained in:
parent
3e6a69ccbf
commit
4af77f8dd0
103
package-lock.json
generated
103
package-lock.json
generated
@ -6,7 +6,7 @@
|
||||
"": {
|
||||
"name": "nextauri",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.6.0",
|
||||
"@tauri-apps/api": "2.2.0",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.2.1",
|
||||
"@tauri-apps/plugin-dialog": "^2.2.0",
|
||||
"@tauri-apps/plugin-fs": "^2.2.0",
|
||||
@ -839,15 +839,10 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/api": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-1.6.0.tgz",
|
||||
"integrity": "sha512-rqI++FWClU5I2UBp4HXFvl+sBWkdigBkxnpJDQUWttNyG7IZP4FwQGhTNL5EOw0vI8i6eSAJ5frLqO7n7jbJdg==",
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"engines": {
|
||||
"node": ">= 14.6.0",
|
||||
"npm": ">= 6.6.0",
|
||||
"yarn": ">= 1.19.1"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
@ -1061,16 +1056,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-clipboard-manager/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-dialog": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.2.0.tgz",
|
||||
@ -1080,16 +1065,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-dialog/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-fs": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-fs/-/plugin-fs-2.2.0.tgz",
|
||||
@ -1099,16 +1074,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-fs/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-global-shortcut": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-global-shortcut/-/plugin-global-shortcut-2.2.0.tgz",
|
||||
@ -1118,16 +1083,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-global-shortcut/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-http": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-http/-/plugin-http-2.3.0.tgz",
|
||||
@ -1137,16 +1092,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-http/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-notification": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-notification/-/plugin-notification-2.2.1.tgz",
|
||||
@ -1156,16 +1101,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-notification/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-os": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-os/-/plugin-os-2.2.0.tgz",
|
||||
@ -1175,16 +1110,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-os/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-process": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-process/-/plugin-process-2.2.0.tgz",
|
||||
@ -1194,16 +1119,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-process/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-shell": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-shell/-/plugin-shell-2.2.0.tgz",
|
||||
@ -1213,16 +1128,6 @@
|
||||
"@tauri-apps/api": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-shell/node_modules/@tauri-apps/api": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz",
|
||||
"integrity": "sha512-R8epOeZl1eJEl603aUMIGb4RXlhPjpgxbGVEaqY+0G5JG9vzV/clNlzTeqc+NLYXVqXcn8mb4c5b9pJIUDEyAg==",
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/tauri-inliner": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/tauri-inliner/-/tauri-inliner-1.14.1.tgz",
|
||||
|
@ -9,7 +9,7 @@
|
||||
"next-build": "next build src-next"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.6.0",
|
||||
"@tauri-apps/api": "2.2.0",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.2.1",
|
||||
"@tauri-apps/plugin-dialog": "^2.2.0",
|
||||
"@tauri-apps/plugin-fs": "^2.2.0",
|
||||
|
@ -1,37 +1,61 @@
|
||||
"use client";
|
||||
"use client"
|
||||
|
||||
import React, {useEffect} from 'react';
|
||||
import TreeNode from '../TreeNode';
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import { } from "@tauri-apps/api";
|
||||
import {invoke} from "@tauri-apps/api/core";
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
|
||||
|
||||
interface TreeNodeData {
|
||||
name: string;
|
||||
type: string;
|
||||
path: string;
|
||||
subfolders: number;
|
||||
size: number;
|
||||
files: number;
|
||||
type: "folder" | "file"; // Enforce specific values for 'type'
|
||||
totalSize: number;
|
||||
subfolderCount: number;
|
||||
fileCount: number;
|
||||
children?: TreeNodeData[];
|
||||
}
|
||||
|
||||
|
||||
interface TreeProps {
|
||||
data: TreeNodeData[];
|
||||
}
|
||||
|
||||
const Tree: React.FC<TreeProps> = ({ data }) => {
|
||||
const rootSize = data[0].size;
|
||||
|
||||
const Tree: React.FC<TreeProps> = () => {
|
||||
const [folders, setFolders] = React.useState<TreeNodeData>();
|
||||
|
||||
function countTotalFolderChildren(root: TreeNodeData): number {
|
||||
let count = 0;
|
||||
|
||||
if (root.children && root.children.length > 0) {
|
||||
for (const child of root.children) {
|
||||
if (child.type === 'folder') {
|
||||
count += child.subfolderCount + countTotalFolderChildren(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
invoke('load_folders')
|
||||
.then(() => console.log("Folders loaded"))
|
||||
.catch(console.error)
|
||||
listen<any>('folders-loaded', (event) => {
|
||||
setFolders(event.payload)
|
||||
});
|
||||
|
||||
setInterval(async () => {
|
||||
invoke('load_folders')
|
||||
.then(() => console.log("Folders loaded"))
|
||||
.catch(console.error)
|
||||
}, 5000)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="tree">
|
||||
{data.map((node) => (
|
||||
<TreeNode key={node.path} node={node} rootSize={rootSize} />
|
||||
{folders.map((node) => (
|
||||
<TreeNode key={node.path} node={node} rootSize={countTotalFolderChildren(folders)} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
@ -2,54 +2,47 @@
|
||||
use std::path::PathBuf;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Clone, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct FolderData {
|
||||
name: String,
|
||||
path: String,
|
||||
#[serde(rename = "type")]
|
||||
folder_type: String, // Always "folder" in this case
|
||||
size: u64,
|
||||
subfolders: usize,
|
||||
total_size: u64,
|
||||
subfolder_count: usize,
|
||||
file_count: usize,
|
||||
children: Vec<FolderData>
|
||||
}
|
||||
|
||||
pub struct FolderCrawler {
|
||||
stack: Vec<PathBuf>,
|
||||
}
|
||||
pub fn load_folder(path : PathBuf) -> FolderData {
|
||||
let mut subfolder_count = 0;
|
||||
let mut file_count = 0;
|
||||
let mut total_size = 0;
|
||||
let mut children = Vec::new();
|
||||
let folder_type = "folder".parse().unwrap();
|
||||
|
||||
impl FolderCrawler {
|
||||
pub fn new(root: PathBuf) -> Self {
|
||||
Self { stack: vec![root] }
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for FolderCrawler {
|
||||
type Item = FolderData;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while let Some(path) = self.stack.pop() {
|
||||
if let Ok(entries) = fs::read_dir(&path) {
|
||||
let mut size = 0;
|
||||
let mut subfolder_count = 0;
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let entry_path = entry.path();
|
||||
if entry_path.is_dir() {
|
||||
subfolder_count += 1;
|
||||
self.stack.push(entry_path);
|
||||
} else {
|
||||
size += entry.metadata().unwrap().len();
|
||||
}
|
||||
}
|
||||
|
||||
return Some(FolderData {
|
||||
name: path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||
path: path.to_str().unwrap().to_string(),
|
||||
folder_type: "folder".to_string(),
|
||||
size,
|
||||
subfolders: subfolder_count,
|
||||
});
|
||||
if let Ok(entries) = fs::read_dir(&path) {
|
||||
for entry in entries.flatten() {
|
||||
let entry_path = entry.path();
|
||||
if entry_path.is_dir() {
|
||||
subfolder_count += 1;
|
||||
children.push(load_folder(entry_path));
|
||||
} else {
|
||||
file_count += 1;
|
||||
total_size += entry.metadata().unwrap().len();
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
FolderData {
|
||||
name: path.file_name().unwrap().to_str().unwrap().to_string(),
|
||||
path: path.to_str().unwrap().to_string(),
|
||||
folder_type,
|
||||
total_size,
|
||||
subfolder_count,
|
||||
file_count,
|
||||
children
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
)]
|
||||
use std::path::PathBuf;
|
||||
mod folder_crawler;
|
||||
use tauri::{AppHandle, Emitter, EventTarget};
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
@ -22,12 +23,8 @@ fn main() {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn load_folders(){
|
||||
println!("TEST");
|
||||
|
||||
let root = PathBuf::from("C:/Users/Damie/Desktop");
|
||||
let crawler = folder_crawler::FolderCrawler::new(root);
|
||||
for folder_data in crawler {
|
||||
println!("{:?}", folder_data);
|
||||
}
|
||||
fn load_folders(app: AppHandle){
|
||||
let root_path = PathBuf::from("C:\\Users\\Damie\\Data443\\dim_argocd");
|
||||
let folder_data = folder_crawler::load_folder(root_path);
|
||||
app.emit("folders-loaded", folder_data).unwrap();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user