Skip to content

Commit

Permalink
Merge pull request #268 from opeolluwa/dev
Browse files Browse the repository at this point in the history
Implement file transfer store
  • Loading branch information
opeolluwa authored Sep 19, 2023
2 parents 6028d86 + fd826df commit c1e8f37
Show file tree
Hide file tree
Showing 18 changed files with 451 additions and 420 deletions.
7 changes: 7 additions & 0 deletions core/bindings/CommandData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface CommandData<T> {
data: T | null;
message: string;
status: boolean;
}
7 changes: 6 additions & 1 deletion core/bindings/TransferHistoryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TransferHistoryBuilder { fileName: string, fileSize: string, transactionType: string, recipient: string, }
export interface TransferHistoryBuilder {
fileName: string;
fileSize: string;
transactionType: string;
recipient: string;
}
325 changes: 0 additions & 325 deletions core/src/api/fs.rs

This file was deleted.

42 changes: 42 additions & 0 deletions core/src/api/fs/audio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* the audion module is responsible for parsing audio relater commands */
use super::*;
static ACCEPTABLE_SUFFIXES: &[&str] = &[
"3gp", "aa", "aac", "aax", "act", "aiff", "alac", "amr", "ape", "au", "awb", "dss", "dvf",
"flac", "gsm", "iklax", "ivs", "m4a", "m4b", "m4p", "mmf", "movpkg", "mp3", "mpc", "msv",
"nmf", "ogg", "oga", "mogg", "opus", "ra", "rm", "raw", "rf64", "sln", "tta", "voc", "vox",
"wav", "wma", "wv", "webm", "8svx", "cda",
];

// get the audio file from 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() -> Result<CommandData<Vec<File>>, CommandData<()>> {
// if there is an error getting the audio path, fire an error
let audio_dir = dirs::audio_dir();
let Some(audio_dir) = audio_dir else {
return Err(CommandData::err("error getting the audio dir", ()));
};

let entries = search_files("*", &audio_dir)
.into_iter()
.filter(|f| ACCEPTABLE_SUFFIXES.contains(&f.file_format.as_str()))
.collect();

Ok(CommandData::ok("retrieved all audio files", entries))
}

#[cfg(test)]
mod tests {
use super::{fetch_audio, ACCEPTABLE_SUFFIXES};
#[test] // see if there are files in the audio directory path
fn _fetch_audio_files_() {
let aud_files = fetch_audio().ok();
assert!(aud_files.is_some());

let aud_files = aud_files.unwrap().data.unwrap();
for file in aud_files {
let file_format = file.file_format;
assert!(ACCEPTABLE_SUFFIXES.contains(&file_format.as_str()));
}
}
}
Loading

0 comments on commit c1e8f37

Please sign in to comment.