feat(cli): add ID3 image extraction
ci/woodpecker/push/woodpecker Pipeline was successful Details

refactor/sveltekit
Tomáš Mládek 2024-01-17 20:31:20 +01:00
parent 7a59f81fb4
commit 8917221b42
4 changed files with 28 additions and 6 deletions

View File

@ -1,3 +1,4 @@
use std::io::Write;
use std::sync::Arc;
use super::Extractor;
@ -8,10 +9,11 @@ use upend_base::{
constants::{ATTR_IN, ATTR_KEY, ATTR_LABEL, ATTR_OF},
entry::{Entry, EntryValue, InvariantEntry},
};
use upend_db::stores::Blob;
use upend_db::{
jobs::{JobContainer, JobState},
stores::{fs::FILE_MIME_KEY, UpStore},
UpEndConnection,
BlobMode, UpEndConnection,
};
lazy_static! {
@ -33,7 +35,7 @@ impl Extractor for ID3Extractor {
fn get(
&self,
address: &Address,
_connection: &UpEndConnection,
connection: &UpEndConnection,
store: Arc<Box<dyn UpStore + Send + Sync>>,
mut job_container: JobContainer,
) -> Result<Vec<Entry>> {
@ -83,6 +85,26 @@ impl Extractor for ID3Extractor {
})
.collect();
for (idx, picture) in tags.pictures().enumerate() {
let tmp_dir = tempfile::tempdir()?;
let tmp_path = tmp_dir.path().join(format!("img-{}", idx));
let mut file = std::fs::File::create(&tmp_path)?;
file.write_all(&*picture.data)?;
let hash = store.store(
connection,
Blob::from_filepath(&tmp_path),
None,
Some(BlobMode::StoreOnly),
)?;
result.push(Entry {
entity: address.clone(),
attribute: "ID3_PICTURE".to_string(),
value: EntryValue::Address(Address::Hash(hash)),
provenance: "SYSTEM EXTRACTOR".to_string(),
timestamp: chrono::Utc::now().naive_utc(),
});
}
if !result.is_empty() {
result.extend(
result

View File

@ -559,7 +559,7 @@ pub async fn put_blob(
let options = connection.get_vault_options()?;
_store
.store(
connection,
&connection,
Blob::from_filepath(file.path()),
_filename,
options.blob_mode,

View File

@ -645,7 +645,7 @@ impl UpStore for FsStore {
fn store(
&self,
connection: UpEndConnection,
connection: &UpEndConnection,
blob: Blob,
name_hint: Option<String>,
blob_mode: Option<BlobMode>,
@ -694,7 +694,7 @@ impl UpStore for FsStore {
.flatten();
self.insert_file_with_metadata(
&connection,
connection,
&final_path,
upath,
hash.clone(),

View File

@ -57,7 +57,7 @@ pub trait UpStore {
fn retrieve_all(&self) -> Result<Vec<Blob>>;
fn store(
&self,
connection: UpEndConnection,
connection: &UpEndConnection,
blob: Blob,
name_hint: Option<String>,
blob_mode: Option<BlobMode>,