generated from nhcarrigan/template
fix: show actual file size for picked files
This commit is contained in:
@@ -373,3 +373,10 @@ pub async fn cleanup_orphaned_temp_files(
|
||||
let mut manager = temp_manager.lock();
|
||||
manager.cleanup_orphaned_files()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_file_size(file_path: String) -> Result<u64, String> {
|
||||
let metadata = std::fs::metadata(&file_path)
|
||||
.map_err(|e| format!("Failed to get file metadata: {}", e))?;
|
||||
Ok(metadata.len())
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ pub fn run() {
|
||||
cleanup_temp_files,
|
||||
cleanup_all_temp_files,
|
||||
cleanup_orphaned_temp_files,
|
||||
get_file_size,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -474,11 +474,19 @@ User: ${formattedMessage}`;
|
||||
const extension = filename.split(".").pop()?.toLowerCase() || "";
|
||||
const fileType = getFileTypeFromExtension(extension);
|
||||
|
||||
// Get file size from Tauri
|
||||
let fileSize = 0;
|
||||
try {
|
||||
fileSize = await invoke<number>("get_file_size", { filePath });
|
||||
} catch (e) {
|
||||
console.warn("Could not get file size:", e);
|
||||
}
|
||||
|
||||
const attachment: Attachment = {
|
||||
id: `attachment-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||
filename,
|
||||
path: filePath,
|
||||
size: 0,
|
||||
size: fileSize,
|
||||
type: fileType,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user