Skip to content

Commit

Permalink
Merge pull request #17 from opeolluwa/master
Browse files Browse the repository at this point in the history
updates from master"
  • Loading branch information
opeolluwa authored Mar 22, 2023
2 parents a9f997a + 6f5628a commit d46d2b3
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 209 deletions.
10 changes: 10 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 @@ -19,6 +19,7 @@ serde_json = "1.0"
local-ip-address = "0.5.1"
dirs = "5.0.0"
glob = "0.3.1"
filesize = "0.2.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
74 changes: 65 additions & 9 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use filesize::PathExt;
// use glob::glob;
use local_ip_address::local_ip;
use serde::{Deserialize, Serialize};
use std::{fs, path::PathBuf};
use std::{
fmt, fs,
path::{Path, PathBuf},
};
extern crate dirs;

#[derive(Debug, Serialize, Deserialize)]
pub struct CommandData<T> {
data: Option<T>,
pub data: Option<T>,
message: String,
status: bool,
}
Expand Down Expand Up @@ -41,10 +45,41 @@ pub fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}

// the audio file interface
#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AudioFile {
file_name: String,
file_format: String,
file_path: PathBuf,
file_size: u128,
}
// AudioFile constructor
impl AudioFile {
pub fn new(name: &str, format: &str, path: PathBuf, size: u128) -> Self {
Self {
file_name: name.to_string(),
file_format: format.to_string(),
file_path: path,
file_size: size,
}
}
}
// implement display for the AudioFiles
impl fmt::Display for AudioFile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"(name: {}\nformat: {}\npath: {:?}, size\n{})",
self.file_name, self.file_format, self.file_path, self.file_size
)
}
}

// get the audio file form the default audio dir of the OS
// return an instance of the CommandData and vector of the path if any
#[tauri::command]
pub fn fetch_audio_files() -> Result<CommandData<Vec<PathBuf>>, CommandData<()>> {
pub fn fetch_audio_files() -> Result<CommandData<Vec<AudioFile>>, CommandData<()>> {
let audio_dir = dirs::audio_dir();

// if there is an error getting the audio path, fire an error
Expand All @@ -53,10 +88,31 @@ pub fn fetch_audio_files() -> Result<CommandData<Vec<PathBuf>>, CommandData<()>>
};

//
let mut entries: Vec<PathBuf> = vec![];
let mut entries: Vec<AudioFile> = vec![];
for entry in fs::read_dir(audio_dir).expect("error reading file") {
let dir = entry.expect("could not read dir");
entries.push(dir.path());
let file = &dir.path();

let file_name = Path::new(file)
.file_name()
.unwrap_or_default()
.to_str()
.unwrap_or_default();
let file_extension = Path::new(file)
.extension()
.unwrap_or_default()
.to_str()
.unwrap_or_default();
let file_size: u128 = file.size_on_disk().unwrap_or(0).into();
let file_path = &dir.path();

let audio_file = AudioFile::new(
file_name,
file_extension,
file_path.to_path_buf(),
file_size,
);
entries.push(audio_file);
}
Ok(CommandData::new("retrieved all audio files", true, entries))
}
Expand Down Expand Up @@ -84,17 +140,17 @@ pub fn fetch_video_files() -> Result<CommandData<Vec<PathBuf>>, CommandData<()>>

#[cfg(test)]
mod tests {
use crate::commands;
use crate::commands::{self, AudioFile};

#[test]// see if there are files in the audio directory path
#[test] // see if there are files in the audio directory path
fn _fetch_audio_files_() {
let aud_files = commands::fetch_audio_files().ok();
assert!(aud_files.is_some())
}

#[test]// see if there are files in the video directory path
#[test] // see if there are files in the video directory path
fn _fetch_video_files_() {
let vid_files: Option<commands::CommandData<Vec<std::path::PathBuf>>> =
let vid_files: Option<commands::CommandData<Vec<AudioFile>>> =
commands::fetch_audio_files().ok();
assert!(vid_files.is_some())
}
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
mod commands;

fn main() {
let aud_files = commands::fetch_audio_files().ok().unwrap();
println!("the audio files {:?}", aud_files);
// let aud_files = commands::fetch_audio_files().ok().unwrap();
// println!("the audio files {:?}", aud_files.data.unwrap()[6]);

tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/components/Layout.tsx → src/components/AppLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Aside from "./Aside";
import Nav from "./Nav";
import Aside from "./AppAside";
import Nav from "./AppNavigation";

interface Props {
children: React.ReactNode
Expand All @@ -15,7 +15,7 @@ export default function Layout({ children }: Props) {
}
}>
<Nav />
<main className='col-span-7 pt-10 px-20 bg-[rgba(241,246,251,255)] dark:bg-mirage-600 '>
<main className='col-span-7 pt-10 px-20 bg-[rgba(241,246,251,255)] overflow-y-scroll dark:bg-mirage-600 '>
{children}
</main>
<Aside />
Expand Down
File renamed without changes.
19 changes: 1 addition & 18 deletions src/components/FileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,10 @@
* and the file status
*/

import { computeFileSize } from '@/utils';
import { ArrowDownCircleIcon, PauseCircleIcon } from '@heroicons/react/24/outline';
import Image from 'next/image';

/**
*
* @function computeFileSize - compute file size to human readable format
* @param size - file size in byte
* @returns file size and extension e.g 3.5 MB
*/

function computeFileSize(size: number) {
if (size > 1024 * 1024 * 1024) {
return (size / (1024 * 1024 * 1024)).toFixed(1).toString() + " TB";
} else if (size > 1024 * 1024) {
return (size / (1024 * 1024)).toFixed(1).toString() + " GB";
} else if (size > 1024) {
return (size / 1024).toFixed(1).toString() + " MB";
} else {
return size.toString() + " KB";
}
}

// the reqired data to render the file card component
// the data will be passed dynamically
Expand Down
161 changes: 0 additions & 161 deletions src/components/Main.tsx

This file was deleted.

Loading

0 comments on commit d46d2b3

Please sign in to comment.