fix(backend): hotfix support for WEBM (mime detection, thumbnail generation)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
add RIFF example files
This commit is contained in:
parent
28e5b2d437
commit
fa86adffb3
9 changed files with 678 additions and 125 deletions
760
Cargo.lock
generated
760
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -79,7 +79,7 @@ webbrowser = { version = "^0.5.5", optional = true }
|
||||||
|
|
||||||
nonempty = "0.6.0"
|
nonempty = "0.6.0"
|
||||||
|
|
||||||
image = { version = "0.23.14", optional = true }
|
image = { version = "0.25.2", optional = true }
|
||||||
webp = { version = "0.2.0", optional = true }
|
webp = { version = "0.2.0", optional = true }
|
||||||
|
|
||||||
webpage = { version = "1.5.0", optional = true, default-features = false }
|
webpage = { version = "1.5.0", optional = true, default-features = false }
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl PreviewStore {
|
||||||
let mime_type: Option<String> = if mime_type.is_some() {
|
let mime_type: Option<String> = if mime_type.is_some() {
|
||||||
mime_type
|
mime_type
|
||||||
} else {
|
} else {
|
||||||
tree_magic_mini::from_filepath(&file_path).map(|m| m.into())
|
upend_db::stores::fs::util::detect_mime(&file_path)
|
||||||
};
|
};
|
||||||
|
|
||||||
let preview = match mime_type {
|
let preview = match mime_type {
|
||||||
|
|
|
@ -60,7 +60,8 @@ filebuffer = "0.4.0"
|
||||||
tempfile = "^3.2.0"
|
tempfile = "^3.2.0"
|
||||||
jwalk = "0.8.1"
|
jwalk = "0.8.1"
|
||||||
|
|
||||||
tree_magic_mini = { version = "3.0.2", features = ["with-gpl-data"] }
|
tree_magic_mini = { version = "3.1.5" }
|
||||||
|
riff = "2.0.0"
|
||||||
|
|
||||||
nonempty = "0.6.0"
|
nonempty = "0.6.0"
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ use self::db::files;
|
||||||
use super::{Blob, StoreError, UpStore, UpdateOptions, UpdatePathOutcome};
|
use super::{Blob, StoreError, UpStore, UpdateOptions, UpdatePathOutcome};
|
||||||
use crate::hierarchies::{resolve_path, resolve_path_cached, ResolveCache, UHierPath, UNode};
|
use crate::hierarchies::{resolve_path, resolve_path_cached, ResolveCache, UHierPath, UNode};
|
||||||
use crate::jobs::{JobContainer, JobHandle};
|
use crate::jobs::{JobContainer, JobHandle};
|
||||||
|
use crate::stores::fs::util::detect_mime;
|
||||||
use crate::util::{hash, hash_at_path};
|
use crate::util::{hash, hash_at_path};
|
||||||
use crate::{
|
use crate::{
|
||||||
BlobMode, ConnectionOptions, LoggingHandler, OperationContext, UpEndConnection, UpEndDatabase,
|
BlobMode, ConnectionOptions, LoggingHandler, OperationContext, UpEndConnection, UpEndDatabase,
|
||||||
|
@ -32,6 +33,7 @@ use upend_base::entry::Entry;
|
||||||
use upend_base::hash::{b58_encode, UpMultihash};
|
use upend_base::hash::{b58_encode, UpMultihash};
|
||||||
|
|
||||||
mod db;
|
mod db;
|
||||||
|
pub mod util;
|
||||||
|
|
||||||
pub const FILE_MIME_KEY: &str = "FILE_MIME";
|
pub const FILE_MIME_KEY: &str = "FILE_MIME";
|
||||||
const FILE_SIZE_KEY: &str = "FILE_SIZE";
|
const FILE_SIZE_KEY: &str = "FILE_SIZE";
|
||||||
|
@ -459,7 +461,8 @@ impl FsStore {
|
||||||
user: context.user.clone(),
|
user: context.user.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mime_type = tree_magic_mini::from_filepath(path).map(|s| s.to_string());
|
let mime_type = detect_mime(&path);
|
||||||
|
|
||||||
let mime_entry = mime_type.map(|mime_type| Entry {
|
let mime_entry = mime_type.map(|mime_type| Entry {
|
||||||
entity: blob_address.clone(),
|
entity: blob_address.clone(),
|
||||||
attribute: FILE_MIME_KEY.parse().unwrap(),
|
attribute: FILE_MIME_KEY.parse().unwrap(),
|
||||||
|
|
22
db/src/stores/fs/util.rs
Normal file
22
db/src/stores/fs/util.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
use std::fs::File;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
pub fn detect_mime<P: AsRef<Path>>(path: P) -> Option<String> {
|
||||||
|
let mime_type = tree_magic_mini::from_filepath(path.as_ref()).map(|s| s.to_string());
|
||||||
|
if mime_type == Some("application/octet-stream".into()) {
|
||||||
|
return None;
|
||||||
|
} else if mime_type == Some("application/x-riff".into()) {
|
||||||
|
let mut file = File::open(path).ok()?;
|
||||||
|
let chunk = riff::Chunk::read(&mut file, 0).ok()?;
|
||||||
|
let chunk_type = chunk.read_type(&mut file).ok()?;
|
||||||
|
|
||||||
|
return match chunk_type.as_str() {
|
||||||
|
"WAVE" => Some("audio/x-wav".to_string()),
|
||||||
|
"WEBP" => Some("image/webp".to_string()),
|
||||||
|
"AVI " => Some("video/x-msvideo".to_string()),
|
||||||
|
_ => mime_type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
mime_type
|
||||||
|
}
|
BIN
example_vault/audio/339326__inspectorj__bird-whistling-a.wav
(Stored with Git LFS)
Normal file
BIN
example_vault/audio/339326__inspectorj__bird-whistling-a.wav
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
example_vault/images/church.jpg
(Stored with Git LFS)
BIN
example_vault/images/church.jpg
(Stored with Git LFS)
Binary file not shown.
BIN
example_vault/images/church.webp
(Stored with Git LFS)
Normal file
BIN
example_vault/images/church.webp
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in a new issue