Implements gui file queue and drag and drop.

This commit is contained in:
2026-08-23 19:08:54 -07:00
parent ae84a31ed6
commit 6411fecb4f
5 changed files with 607 additions and 189 deletions

View File

@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use nextcloud_client::{
@@ -14,6 +15,13 @@ pub struct LoginFlowInitPayload {
pub poll_token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FileInfo {
pub path: String,
pub name: String,
pub size: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GuiUploadResult {
pub file_path: String,
@@ -154,6 +162,26 @@ pub async fn select_files() -> Result<Vec<String>, String> {
}
}
#[tauri::command]
pub fn get_file_info(file_path: String) -> Result<FileInfo, String> {
let path = PathBuf::from(&file_path);
if !path.exists() {
return Err(format!("File '{}' does not exist", file_path));
}
let metadata = fs::metadata(&path).map_err(|e| e.to_string())?;
let name = path
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("file")
.to_string();
Ok(FileInfo {
path: file_path,
name,
size: metadata.len(),
})
}
#[tauri::command]
pub async fn upload_file(
file_path: String,
@@ -211,7 +239,7 @@ pub async fn upload_file(
#[cfg(test)]
mod tests {
use super::{GuiUploadResult, LoginFlowInitPayload};
use super::{FileInfo, GuiUploadResult, LoginFlowInitPayload};
#[test]
fn test_login_flow_payload_serialization() {
@@ -226,6 +254,19 @@ mod tests {
assert_eq!(payload, deserialized);
}
#[test]
fn test_file_info_serialization() {
let file_info = FileInfo {
path: "/path/to/document.pdf".to_string(),
name: "document.pdf".to_string(),
size: 2048,
};
let json = serde_json::to_string(&file_info).unwrap();
let deserialized: FileInfo = serde_json::from_str(&json).unwrap();
assert_eq!(file_info, deserialized);
}
#[test]
fn test_gui_upload_result_serialization() {
let res = GuiUploadResult {

View File

@@ -13,6 +13,7 @@ pub fn run() {
commands::poll_login_flow,
commands::manual_login,
commands::select_files,
commands::get_file_info,
commands::upload_file
])
.run(tauri::generate_context!())