Compare commits
2 Commits
v0.7.0-74-
...
todos
Author | SHA1 | Date | |
---|---|---|---|
d415f02e9f
|
|||
102732974d
|
@@ -4,7 +4,6 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- next-v0.8
|
||||
|
||||
jobs:
|
||||
release:
|
||||
|
@@ -7,7 +7,6 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- next-v0.8
|
||||
|
||||
jobs:
|
||||
check:
|
||||
|
@@ -7,22 +7,22 @@ pub struct CoverArt {
|
||||
pub id: uuid::Uuid,
|
||||
pub title: String,
|
||||
#[serde(skip)]
|
||||
pub directory: String,
|
||||
pub filename: String,
|
||||
pub path: String,
|
||||
#[serde(skip)]
|
||||
pub data: Vec<u8>,
|
||||
pub song_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
pub mod init {
|
||||
use super::CoverArt;
|
||||
use crate::coverart::CoverArt;
|
||||
|
||||
/// Initializes the CoverArt with just the directory and filename
|
||||
pub fn init_coverart_dir_and_filename(directory: &str, filename: &str) -> CoverArt {
|
||||
pub fn init_coverart_only_path(path: String) -> CoverArt {
|
||||
CoverArt {
|
||||
directory: String::from(directory),
|
||||
filename: String::from(filename),
|
||||
..Default::default()
|
||||
id: uuid::Uuid::nil(),
|
||||
title: String::new(),
|
||||
path: path.clone(),
|
||||
data: Vec::new(),
|
||||
song_id: uuid::Uuid::nil(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,9 @@ pub mod init {
|
||||
impl CoverArt {
|
||||
/// Saves the coverart to the filesystem
|
||||
pub fn save_to_filesystem(&self) -> Result<(), std::io::Error> {
|
||||
match self.get_path() {
|
||||
Ok(path) => match std::fs::File::create(&path) {
|
||||
Ok(mut file) => match file.write_all(&self.data) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
match std::fs::File::create(&self.path) {
|
||||
Ok(mut file) => match file.write_all(&self.data) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
Err(err) => Err(err),
|
||||
@@ -44,46 +41,15 @@ impl CoverArt {
|
||||
|
||||
/// Removes the coverart from the filesystem
|
||||
pub fn remove_from_filesystem(&self) -> Result<(), std::io::Error> {
|
||||
match self.get_path() {
|
||||
Ok(path) => {
|
||||
let p = std::path::Path::new(&path);
|
||||
if p.exists() {
|
||||
match std::fs::remove_file(p) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
} else {
|
||||
Err(std::io::Error::other(
|
||||
"Cannot delete file that does not exist",
|
||||
))
|
||||
}
|
||||
let p = std::path::Path::new(&self.path);
|
||||
if p.exists() {
|
||||
match std::fs::remove_file(p) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the path of the CoverArt
|
||||
pub fn get_path(&self) -> Result<String, std::io::Error> {
|
||||
if self.directory.is_empty() {
|
||||
return Err(std::io::Error::other("Directory has not been initialized"));
|
||||
} else if self.filename.is_empty() {
|
||||
return Err(std::io::Error::other("Filename has not bee initialized"));
|
||||
}
|
||||
|
||||
let directory = &self.directory;
|
||||
let last_index = directory.len() - 1;
|
||||
|
||||
if let Some(character) = directory.chars().nth(last_index) {
|
||||
let buffer = if character != '/' {
|
||||
directory.clone() + "/"
|
||||
} else {
|
||||
directory.clone()
|
||||
};
|
||||
|
||||
Ok(buffer + &self.filename.clone())
|
||||
} else {
|
||||
Err(std::io::Error::other(
|
||||
"Could not access last character of directory",
|
||||
"Cannot delete file that does not exist",
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -94,15 +60,11 @@ pub mod io {
|
||||
|
||||
/// Gets the raw data of the cover art
|
||||
pub fn to_data(coverart: &super::CoverArt) -> Result<Vec<u8>, std::io::Error> {
|
||||
match coverart.get_path() {
|
||||
Ok(path) => {
|
||||
let mut file = std::fs::File::open(path)?;
|
||||
let mut buffer = Vec::new();
|
||||
match file.read_to_end(&mut buffer) {
|
||||
Ok(_) => Ok(buffer),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
let path: &String = &coverart.path;
|
||||
let mut file = std::fs::File::open(path)?;
|
||||
let mut buffer = Vec::new();
|
||||
match file.read_to_end(&mut buffer) {
|
||||
Ok(_) => Ok(buffer),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user