generated from t/malachite
add: use bucket methods everywhere
This commit is contained in:
parent
4e4f26ea14
commit
6583c34243
5 changed files with 51 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "buckets-core"
|
||||
description = "Buckets media upload types"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
edition = "2024"
|
||||
readme = "../../README.md"
|
||||
authors.workspace = true
|
||||
|
|
|
@ -210,7 +210,7 @@ impl DataManager {
|
|||
// if there's an issue in the database
|
||||
//
|
||||
// the actual file takes up much more space than the database entry.
|
||||
let upload = self.get_upload_by_id(id).await?;
|
||||
let upload = self.get_upload_by_id_bucket(id, bucket).await?;
|
||||
upload.remove(&self.0.0.directory)?;
|
||||
|
||||
// delete from database
|
||||
|
|
|
@ -90,14 +90,44 @@ impl MediaUpload {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the path to the fs file for this upload.
|
||||
pub fn path(&self, directory: &str) -> PathBufD {
|
||||
/// Get the path to the fs file for this upload (without bucket).
|
||||
pub(crate) fn legacy_path(&self, directory: &str) -> PathBufD {
|
||||
PathBufD::current().extend(&[
|
||||
directory,
|
||||
&format!("{}.{}", self.id, self.metadata.what.extension()),
|
||||
])
|
||||
}
|
||||
|
||||
/// Get the path to the fs file for this upload (with bucket).
|
||||
pub fn full_path(&self, directory: &str) -> PathBufD {
|
||||
PathBufD::current().extend(&[
|
||||
directory,
|
||||
&format!(
|
||||
"{}{}.{}",
|
||||
if self.bucket != "" {
|
||||
format!("{}.", self.bucket)
|
||||
} else {
|
||||
String::new()
|
||||
},
|
||||
self.id,
|
||||
self.metadata.what.extension()
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
/// Get the path to the fs file for this upload.
|
||||
///
|
||||
/// Uses path with bucket unless legacy path exists.
|
||||
pub fn path(&self, directory: &str) -> PathBufD {
|
||||
let legacy = self.legacy_path(directory);
|
||||
|
||||
if std::fs::exists(&legacy).unwrap() {
|
||||
return legacy;
|
||||
}
|
||||
|
||||
self.full_path(directory)
|
||||
}
|
||||
|
||||
/// Write to this upload in the file system.
|
||||
pub fn write(&self, directory: &str, bytes: &[u8]) -> Result<()> {
|
||||
match write(self.path(directory), bytes) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue