Skip to content

Commit 6dd0e52

Browse files
committed
Merge image uploading from kernel
kernelkind (8): upload media button get file binary import base64 notedeck_columns: use sha2 & base64 use rfd for desktop file selection add utils for uploading media draft fields for media upload feat ui: user can upload images
2 parents 0c3db9a + 7abf1c9 commit 6dd0e52

File tree

10 files changed

+1284
-36
lines changed

10 files changed

+1284
-36
lines changed

Cargo.lock

Lines changed: 472 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010

1111
[workspace.dependencies]
1212
base32 = "0.4.0"
13+
base64 = "0.22.1"
1314
bech32 = { version = "0.11", default-features = false }
1415
bitflags = "2.5.0"
1516
dirs = "5.0.1"

assets/icons/media_upload_dark_4x.png

1.47 KB
Loading

crates/notedeck_columns/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ tracing-subscriber = { workspace = true }
4343
url = { workspace = true }
4444
urlencoding = { workspace = true }
4545
uuid = { workspace = true }
46+
sha2 = { workspace = true }
47+
base64 = { workspace = true }
48+
49+
[target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies]
50+
rfd = "0.15"
4651

4752
[dev-dependencies]
4853
tempfile = { workspace = true }

crates/notedeck_columns/src/draft.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
use crate::ui::note::PostType;
1+
use poll_promise::Promise;
2+
3+
use crate::{media_upload::Nip94Event, ui::note::PostType, Error};
24
use std::collections::HashMap;
35

46
#[derive(Default)]
57
pub struct Draft {
68
pub buffer: String,
9+
pub uploaded_media: Vec<Nip94Event>, // media uploads to include
10+
pub uploading_media: Vec<Promise<Result<Nip94Event, Error>>>, // promises that aren't ready yet
11+
pub upload_errors: Vec<String>, // media upload errors to show the user
712
}
813

914
#[derive(Default)]
@@ -42,5 +47,8 @@ impl Draft {
4247

4348
pub fn clear(&mut self) {
4449
self.buffer = "".to_string();
50+
self.upload_errors = Vec::new();
51+
self.uploaded_media = Vec::new();
52+
self.uploading_media = Vec::new();
4553
}
4654
}

crates/notedeck_columns/src/images.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use notedeck::ImageCache;
44
use notedeck::Result;
55
use poll_promise::Promise;
66
use std::path;
7+
use std::path::PathBuf;
78
use tokio::fs;
89

910
//pub type ImageCacheKey = String;
@@ -198,6 +199,10 @@ fn fetch_img_from_disk(
198199
})
199200
}
200201

202+
pub fn fetch_binary_from_disk(path: PathBuf) -> Result<Vec<u8>> {
203+
std::fs::read(path).map_err(|e| notedeck::Error::Generic(e.to_string()))
204+
}
205+
201206
/// Controls type-specific handling
202207
#[derive(Debug, Clone, Copy)]
203208
pub enum ImageType {

crates/notedeck_columns/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod frame_history;
1818
mod images;
1919
mod key_parsing;
2020
pub mod login_manager;
21+
mod media_upload;
2122
mod multi_subscriber;
2223
mod nav;
2324
mod post;

0 commit comments

Comments
 (0)