Skip to content

Commit 5e97f4d

Browse files
committed
feat: infer mime
feat: store in tmp dir next to output dir
1 parent 4accc35 commit 5e97f4d

File tree

11 files changed

+323
-293
lines changed

11 files changed

+323
-293
lines changed

Cargo.lock

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ serde_with = { version = "3.8.1", features = ["hex"] }
5252
reqwest = { version = "0.12.8", features = ["stream"] }
5353
clap = { version = "4.5.18", features = ["derive"] }
5454
mime2ext = "0.1.53"
55-
tokio-util = { version = "0.7.13", features = ["io"] }
55+
infer = "0.16.0"
56+
tokio-util = { version = "0.7.13", features = ["io", "io-util"] }
5657

5758
libc = { version = "0.2.153", optional = true }
58-
ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "76333375d8c7c825cd9e45c041866f2c655c7bbd", optional = true }
59+
ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "de2050cec07a095bace38d3ccf9c4c4f9b03b217", optional = true }
5960
candle-core = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
6061
candle-nn = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
6162
candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
6263
sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] }
6364
http-range-header = { version = "0.4.2", optional = true }
6465
nostr-cursor = { git = "https://git.v0l.io/Kieran/nostr_backup_proc.git", branch = "main", optional = true }
6566
regex = { version = "1.11.1", optional = true }
67+
rand = "0.8.5"
6668

6769

src/bin/void_cat_migrate.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ async fn migrate_file(
125125
let md: Option<Vec<&str>> = f.media_dimensions.as_ref().map(|s| s.split("x").collect());
126126
let fu = FileUpload {
127127
id: id_vec,
128-
name: match &f.name {
129-
Some(n) => n.to_string(),
130-
None => "".to_string(),
131-
},
128+
name: f.name.clone(),
132129
size: f.size as u64,
133130
mime_type: f.mime_type.clone(),
134131
created: f.uploaded,
@@ -142,7 +139,6 @@ async fn migrate_file(
142139
},
143140
blur_hash: None,
144141
alt: f.description.clone(),
145-
..Default::default()
146142
};
147143
db.add_file(&fu, uid).await?;
148144
Ok(())

src/db.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,53 @@
1+
use crate::filesystem::NewFileResult;
12
use chrono::{DateTime, Utc};
23
use serde::Serialize;
34
use sqlx::migrate::MigrateError;
45
use sqlx::{Error, Executor, FromRow, Row};
56

67
#[derive(Clone, FromRow, Default, Serialize)]
78
pub struct FileUpload {
9+
/// SHA-256 hash of the file
810
#[serde(with = "hex")]
911
pub id: Vec<u8>,
10-
pub name: String,
12+
/// Filename
13+
pub name: Option<String>,
14+
/// Size in bytes
1115
pub size: u64,
16+
/// MIME type
1217
pub mime_type: String,
18+
/// When the upload was created
1319
pub created: DateTime<Utc>,
20+
/// Width of the media in pixels
1421
pub width: Option<u32>,
22+
/// Height of the media in pixels
1523
pub height: Option<u32>,
24+
/// Blurhash of the media
1625
pub blur_hash: Option<String>,
26+
/// Alt text of the media
1727
pub alt: Option<String>,
1828

1929
#[sqlx(skip)]
2030
#[cfg(feature = "labels")]
2131
pub labels: Vec<FileLabel>,
2232
}
2333

34+
impl From<&NewFileResult> for FileUpload {
35+
fn from(value: &NewFileResult) -> Self {
36+
Self {
37+
id: value.id.clone(),
38+
name: None,
39+
size: value.size,
40+
mime_type: value.mime_type.clone(),
41+
created: Utc::now(),
42+
width: value.width,
43+
height: value.height,
44+
blur_hash: value.blur_hash.clone(),
45+
alt: None,
46+
#[cfg(feature = "labels")]
47+
labels: value.labels.clone(),
48+
}
49+
}
50+
}
2451
#[derive(Clone, FromRow, Serialize)]
2552
pub struct User {
2653
pub id: u64,

0 commit comments

Comments
 (0)