start to implement save and dnd for files
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-10-02 11:39:20 -05:00
parent 61fdc288b6
commit f9f3f7f95f
5 changed files with 426 additions and 303 deletions

64
Cargo.lock generated
View file

@ -2174,6 +2174,18 @@ dependencies = [
"simd-adler32", "simd-adler32",
] ]
[[package]]
name = "filetime"
version = "0.2.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0505cd1b6fa6580283f6bdf70a73fcf4aba1184038c90902b92b3dd0df63ed"
dependencies = [
"cfg-if",
"libc",
"libredox",
"windows-sys 0.60.2",
]
[[package]] [[package]]
name = "find-crate" name = "find-crate"
version = "0.6.3" version = "0.6.3"
@ -4142,6 +4154,7 @@ dependencies = [
"colors-transform", "colors-transform",
"crisp", "crisp",
"dirs 6.0.0", "dirs 6.0.0",
"fastrand 2.3.0",
"gstreamer", "gstreamer",
"gstreamer-app", "gstreamer-app",
"iced_video_player", "iced_video_player",
@ -4160,11 +4173,13 @@ dependencies = [
"sqlx", "sqlx",
"strum", "strum",
"strum_macros", "strum_macros",
"tar",
"tokio", "tokio",
"tracing", "tracing",
"tracing-log", "tracing-log",
"tracing-subscriber", "tracing-subscriber",
"url", "url",
"zstd",
] ]
[[package]] [[package]]
@ -7225,6 +7240,17 @@ dependencies = [
"slotmap", "slotmap",
] ]
[[package]]
name = "tar"
version = "0.4.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a"
dependencies = [
"filetime",
"libc",
"xattr",
]
[[package]] [[package]]
name = "target-lexicon" name = "target-lexicon"
version = "0.12.16" version = "0.12.16"
@ -8947,6 +8973,16 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd" checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"
[[package]]
name = "xattr"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156"
dependencies = [
"libc",
"rustix 1.1.2",
]
[[package]] [[package]]
name = "xcursor" name = "xcursor"
version = "0.3.10" version = "0.3.10"
@ -9297,6 +9333,34 @@ dependencies = [
"syn 2.0.106", "syn 2.0.106",
] ]
[[package]]
name = "zstd"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "7.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
dependencies = [
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.16+zstd.1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748"
dependencies = [
"cc",
"pkg-config",
]
[[package]] [[package]]
name = "zune-core" name = "zune-core"
version = "0.4.12" version = "0.4.12"

View file

@ -39,6 +39,9 @@ rapidfuzz = "0.5.0"
# wgpu = "26.0.1" # wgpu = "26.0.1"
# mupdf = "0.5.0" # mupdf = "0.5.0"
mupdf = { version = "0.5.0", git = "https://github.com/messense/mupdf-rs", rev="2425c1405b326165b06834dcc1ca859015f92787"} mupdf = { version = "0.5.0", git = "https://github.com/messense/mupdf-rs", rev="2425c1405b326165b06834dcc1ca859015f92787"}
tar = "0.4.44"
zstd = "0.13.3"
fastrand = "2.3.0"
# rfd = { version = "0.15.4", default-features = false, features = ["xdg-portal"] } # rfd = { version = "0.15.4", default-features = false, features = ["xdg-portal"] }

View file

@ -1,356 +1,401 @@
use tar::{Archive, Builder}; use crate::core::{
kinds::ServiceItemKind, service_items::ServiceItem,
slide::Background,
};
use miette::{IntoDiagnostic, Result};
use std::{
fs::{self, File},
io::Write,
iter,
path::{Path, PathBuf},
};
use tar::Builder;
use tracing::error; use tracing::error;
use zstd::Encoder; use zstd::Encoder;
use std::{fs::{self, File}, iter, path::{Path, PathBuf}};
use color_eyre::eyre::{eyre, Context, Result};
use serde_json::Value;
use sqlx::{query, query_as, FromRow, SqliteConnection};
use crate::{images::{get_image_from_db, Image}, kinds::ServiceItemKind, model::get_db, presentations::{get_presentation_from_db, PresKind, Presentation}, service_items::ServiceItem, slides::Background, songs::{get_song_from_db, Song}, videos::{get_video_from_db, Video}};
pub async fn save(list: Vec<ServiceItem>, path: impl AsRef<Path>) -> Result<()> { pub async fn save(
list: Vec<ServiceItem>,
path: impl AsRef<Path>,
) -> Result<()> {
let path = path.as_ref(); let path = path.as_ref();
let save_file = File::create(path)?; let save_file = File::create(path).into_diagnostic()?;
let mut db = get_db().await; let ron = process_service_items(&list).await?;
let json = process_service_items(&list, &mut db).await?;
let archive = store_service_items(&list, &mut db, &save_file, &json).await?;
Ok(())
}
async fn store_service_items(items: &Vec<ServiceItem>, db: &mut SqliteConnection, save_file: &File, json: &Value) -> Result<()> {
let encoder = Encoder::new(save_file, 3).unwrap(); let encoder = Encoder::new(save_file, 3).unwrap();
let mut tar = Builder::new(encoder); let mut tar = Builder::new(encoder);
let mut temp_dir = dirs::data_dir().unwrap(); let mut temp_dir = dirs::data_dir().unwrap();
temp_dir.push("lumina"); temp_dir.push("lumina");
let mut s: String = let mut s: String =
iter::repeat_with(fastrand::alphanumeric) iter::repeat_with(fastrand::alphanumeric).take(5).collect();
.take(5)
.collect();
s.insert_str(0, "temp_"); s.insert_str(0, "temp_");
temp_dir.push(s); temp_dir.push(s);
fs::create_dir_all(&temp_dir)?; fs::create_dir_all(&temp_dir).into_diagnostic()?;
let service_file = temp_dir.join("serviceitems.json"); let service_file = temp_dir.join("serviceitems.ron");
fs::File::create(&service_file)?; fs::File::create(&service_file).into_diagnostic()?;
match fs::File::options().read(true).write(true).open(service_file) { match fs::File::options()
Ok(f) => { .read(true)
serde_json::to_writer_pretty(f, json)?; .write(true)
}, .open(service_file)
Err(e) => error!("There were problems making a file i guess: {e}"), {
Ok(mut f) => {
f.write(ron.as_bytes()).into_diagnostic()?;
}
Err(e) => {
error!("There were problems making a file i guess: {e}")
}
}; };
for item in items { for item in list {
let background; let background;
let audio: Option<PathBuf>; let audio: Option<PathBuf>;
match item.kind { match &item.kind {
ServiceItemKind::Song => { ServiceItemKind::Song(song) => {
let song = get_song_from_db(item.database_id, db).await?; background = song.background.clone();
background = song.background; audio = song.audio.clone();
audio = song.audio; }
}, ServiceItemKind::Image(image) => {
ServiceItemKind::Image => { background = Some(
let image = get_image_from_db(item.database_id, db).await?; Background::try_from(image.path.clone())
background = Some(Background::try_from(image.path)?); .into_diagnostic()?,
);
audio = None; audio = None;
}, }
ServiceItemKind::Video => { ServiceItemKind::Video(video) => {
let video = get_video_from_db(item.database_id, db).await?; background = Some(
background = Some(Background::try_from(video.path)?); Background::try_from(video.path.clone())
.into_diagnostic()?,
);
audio = None; audio = None;
}, }
ServiceItemKind::Presentation(_) => { ServiceItemKind::Presentation(presentation) => {
let presentation = get_presentation_from_db(item.database_id, db).await?; background = Some(
background = Some(Background::try_from(presentation.path)?); Background::try_from(presentation.path.clone())
.into_diagnostic()?,
);
audio = None; audio = None;
}, }
ServiceItemKind::Content => { ServiceItemKind::Content(_slide) => {
todo!() todo!()
}, }
}; };
if let Some(file) = audio { if let Some(file) = audio {
let audio_file = temp_dir.join(file.file_name().expect("Audio file couldn't be added to temp_dir")); let audio_file =
temp_dir.join(file.file_name().expect(
"Audio file couldn't be added to temp_dir",
));
if let Ok(file) = file.strip_prefix("file://") { if let Ok(file) = file.strip_prefix("file://") {
fs::File::create(&audio_file).wrap_err("Couldn't create audio file")?; fs::File::create(&audio_file).into_diagnostic()?;
fs::copy(file, audio_file).wrap_err("Audio file could not be copied, the source file doesn't exist not be found"); fs::copy(file, audio_file).into_diagnostic()?;
} else { } else {
fs::File::create(&audio_file).wrap_err("Couldn't create audio file")?; fs::File::create(&audio_file).into_diagnostic()?;
fs::copy(file, audio_file).wrap_err("Audio file could not be copied, the source file doesn't exist not be found"); fs::copy(file, audio_file).into_diagnostic()?;
} }
}; };
if let Some(file) = background { if let Some(file) = background {
let background_file = temp_dir.join(file.path.file_name().expect("Background file couldn't be added to temp_dir")); let background_file =
temp_dir.join(file.path.file_name().expect(
"Background file couldn't be added to temp_dir",
));
if let Ok(file) = file.path.strip_prefix("file://") { if let Ok(file) = file.path.strip_prefix("file://") {
fs::File::create(&background_file).wrap_err("Couldn't create background file")?; fs::File::create(&background_file)
fs::copy(file, background_file).wrap_err("Background file could not be copied, the source file doesn't exist not be found"); .into_diagnostic()?;
fs::copy(file, background_file).into_diagnostic()?;
} else { } else {
fs::File::create(&background_file).wrap_err("Couldn't create background file")?; fs::File::create(&background_file)
fs::copy(file.path, background_file).wrap_err("Background file could not be copied, the source file doesn't exist not be found"); .into_diagnostic()?;
fs::copy(file.path, background_file)
.into_diagnostic()?;
} }
} }
} }
Ok(()) tar.append_dir_all(path, temp_dir).into_diagnostic()?;
tar.finish().into_diagnostic()
} }
async fn clear_temp_dir(temp_dir: &Path) -> Result<()> { async fn clear_temp_dir(temp_dir: &Path) -> Result<()> {
todo!() todo!()
} }
async fn process_service_items(items: &Vec<ServiceItem>, db: &mut SqliteConnection) -> Result<Value> { async fn process_service_items(
let mut values: Vec<Value> = vec![]; items: &Vec<ServiceItem>,
for item in items { ) -> Result<String> {
match item.kind { Ok(items
ServiceItemKind::Song => { .into_iter()
let value = process_song(item.database_id, db).await?; .filter_map(|item| {
values.push(value); let ron = ron::ser::to_string(item);
}, ron.ok()
ServiceItemKind::Image => { })
let value = process_image(item.database_id, db).await?; .collect())
values.push(value);
},
ServiceItemKind::Video => {
let value = process_video(item.database_id, db).await?;
values.push(value);
},
ServiceItemKind::Presentation(_) => {
let value = process_presentation(item.database_id, db).await?;
values.push(value);
},
ServiceItemKind::Content => {
todo!()
},
}
}
let json = Value::from(values);
Ok(json)
} }
async fn process_song(database_id: i32, db: &mut SqliteConnection) -> Result<Value> { // async fn process_song(
let song = get_song_from_db(database_id, db).await?; // database_id: i32,
let song_json = serde_json::to_value(&song)?; // db: &mut SqliteConnection,
let kind_json = serde_json::to_value(ServiceItemKind::Song)?; // ) -> Result<Value> {
let json = serde_json::json!({"item": song_json, "kind": kind_json}); // let song = get_song_from_db(database_id, db).await?;
Ok(json) // let song_ron = ron::to_value(&song)?;
} // let kind_ron = ron::to_value(ServiceItemKind::Song)?;
// let json =
// serde_json::json!({"item": song_json, "kind": kind_json});
// Ok(json)
// }
async fn process_image(database_id: i32, db: &mut SqliteConnection) -> Result<Value> { // async fn process_image(
let image = get_image_from_db(database_id, db).await?; // database_id: i32,
let image_json = serde_json::to_value(&image)?; // db: &mut SqliteConnection,
let kind_json = serde_json::to_value(ServiceItemKind::Image)?; // ) -> Result<Value> {
let json = serde_json::json!({"item": image_json, "kind": kind_json}); // let image = get_image_from_db(database_id, db).await?;
Ok(json) // let image_json = serde_json::to_value(&image)?;
} // let kind_json = serde_json::to_value(ServiceItemKind::Image)?;
// let json =
// serde_json::json!({"item": image_json, "kind": kind_json});
// Ok(json)
// }
async fn process_video(database_id: i32, db: &mut SqliteConnection) -> Result<Value> { // async fn process_video(
let video = get_video_from_db(database_id, db).await?; // database_id: i32,
let video_json = serde_json::to_value(&video)?; // db: &mut SqliteConnection,
let kind_json = serde_json::to_value(ServiceItemKind::Video)?; // ) -> Result<Value> {
let json = serde_json::json!({"item": video_json, "kind": kind_json}); // let video = get_video_from_db(database_id, db).await?;
Ok(json) // let video_json = serde_json::to_value(&video)?;
} // let kind_json = serde_json::to_value(ServiceItemKind::Video)?;
// let json =
// serde_json::json!({"item": video_json, "kind": kind_json});
// Ok(json)
// }
async fn process_presentation(database_id: i32, db: &mut SqliteConnection) -> Result<Value> { // async fn process_presentation(
let presentation = get_presentation_from_db(database_id, db).await?; // database_id: i32,
let presentation_json = serde_json::to_value(&presentation)?; // db: &mut SqliteConnection,
let kind_json = match presentation.kind { // ) -> Result<Value> {
PresKind::Html => serde_json::to_value(ServiceItemKind::Presentation(PresKind::Html))?, // let presentation =
PresKind::Pdf => serde_json::to_value(ServiceItemKind::Presentation(PresKind::Pdf))?, // get_presentation_from_db(database_id, db).await?;
PresKind::Generic => serde_json::to_value(ServiceItemKind::Presentation(PresKind::Generic))?, // let presentation_json = serde_json::to_value(&presentation)?;
}; // let kind_json = match presentation.kind {
let json = serde_json::json!({"item": presentation_json, "kind": kind_json}); // PresKind::Html => serde_json::to_value(
Ok(json) // ServiceItemKind::Presentation(PresKind::Html),
} // )?,
// PresKind::Pdf => serde_json::to_value(
// ServiceItemKind::Presentation(PresKind::Pdf),
// )?,
// PresKind::Generic => serde_json::to_value(
// ServiceItemKind::Presentation(PresKind::Generic),
// )?,
// };
// let json = serde_json::json!({"item": presentation_json, "kind": kind_json});
// Ok(json)
// }
#[cfg(test)] // #[cfg(test)]
mod test { // mod test {
use std::path::PathBuf; // use std::path::PathBuf;
use fs::canonicalize; // use super::*;
use sqlx::Connection; // use fs::canonicalize;
use pretty_assertions::assert_eq; // use pretty_assertions::assert_eq;
use tracing::debug; // use sqlx::Connection;
use super::*; // use tracing::debug;
async fn get_db() -> SqliteConnection { // async fn get_db() -> SqliteConnection {
let mut data = dirs::data_local_dir().unwrap(); // let mut data = dirs::data_local_dir().unwrap();
data.push("lumina"); // data.push("lumina");
data.push("library-db.sqlite3"); // data.push("library-db.sqlite3");
let mut db_url = String::from("sqlite://"); // let mut db_url = String::from("sqlite://");
db_url.push_str(data.to_str().unwrap()); // db_url.push_str(data.to_str().unwrap());
SqliteConnection::connect(&db_url) // SqliteConnection::connect(&db_url).await.expect("problems")
.await // }
.expect("problems")
}
#[tokio::test(flavor = "current_thread")] // #[tokio::test(flavor = "current_thread")]
async fn test_process_song() { // async fn test_process_song() {
let mut db = get_db().await; // let mut db = get_db().await;
let result = process_song(7, &mut db).await; // let result = process_song(7, &mut db).await;
let json_song_file = PathBuf::from("./test/test_song.json"); // let json_song_file = PathBuf::from("./test/test_song.json");
if let Ok(path) = canonicalize(json_song_file) { // if let Ok(path) = canonicalize(json_song_file) {
debug!(file = ?&path); // debug!(file = ?&path);
if let Ok(s) = fs::read_to_string(path) { // if let Ok(s) = fs::read_to_string(path) {
debug!(s); // debug!(s);
match result { // match result {
Ok(json) => assert_eq!(json.to_string(), s), // Ok(json) => assert_eq!(json.to_string(), s),
Err(e) => panic!("There was an error in processing the song: {e}"), // Err(e) => panic!(
} // "There was an error in processing the song: {e}"
} else { // ),
panic!("String wasn't read from file"); // }
} // } else {
} else { // panic!("String wasn't read from file");
panic!("Cannot find absolute path to test_song.json"); // }
} // } else {
} // panic!("Cannot find absolute path to test_song.json");
// }
// }
#[tokio::test(flavor = "current_thread")] // #[tokio::test(flavor = "current_thread")]
async fn test_process_image() { // async fn test_process_image() {
let mut db = get_db().await; // let mut db = get_db().await;
let result = process_image(3, &mut db).await; // let result = process_image(3, &mut db).await;
let json_image_file = PathBuf::from("./test/test_image.json"); // let json_image_file = PathBuf::from("./test/test_image.json");
if let Ok(path) = canonicalize(json_image_file) { // if let Ok(path) = canonicalize(json_image_file) {
debug!(file = ?&path); // debug!(file = ?&path);
if let Ok(s) = fs::read_to_string(path) { // if let Ok(s) = fs::read_to_string(path) {
debug!(s); // debug!(s);
match result { // match result {
Ok(json) => assert_eq!(json.to_string(), s), // Ok(json) => assert_eq!(json.to_string(), s),
Err(e) => panic!("There was an error in processing the image: {e}"), // Err(e) => panic!(
} // "There was an error in processing the image: {e}"
} else { // ),
panic!("String wasn't read from file"); // }
} // } else {
} else { // panic!("String wasn't read from file");
panic!("Cannot find absolute path to test_image.json"); // }
} // } else {
} // panic!("Cannot find absolute path to test_image.json");
// }
// }
#[tokio::test(flavor = "current_thread")] // #[tokio::test(flavor = "current_thread")]
async fn test_process_video() { // async fn test_process_video() {
let mut db = get_db().await; // let mut db = get_db().await;
let result = process_video(73, &mut db).await; // let result = process_video(73, &mut db).await;
let json_video_file = PathBuf::from("./test/test_video.json"); // let json_video_file = PathBuf::from("./test/test_video.json");
if let Ok(path) = canonicalize(json_video_file) { // if let Ok(path) = canonicalize(json_video_file) {
debug!(file = ?&path); // debug!(file = ?&path);
if let Ok(s) = fs::read_to_string(path) { // if let Ok(s) = fs::read_to_string(path) {
debug!(s); // debug!(s);
match result { // match result {
Ok(json) => assert_eq!(json.to_string(), s), // Ok(json) => assert_eq!(json.to_string(), s),
Err(e) => panic!("There was an error in processing the video: {e}"), // Err(e) => panic!(
} // "There was an error in processing the video: {e}"
} else { // ),
panic!("String wasn't read from file"); // }
} // } else {
} else { // panic!("String wasn't read from file");
panic!("Cannot find absolute path to test_video.json"); // }
} // } else {
} // panic!("Cannot find absolute path to test_video.json");
// }
// }
#[tokio::test(flavor = "current_thread")] // #[tokio::test(flavor = "current_thread")]
async fn test_process_presentation() { // async fn test_process_presentation() {
let mut db = get_db().await; // let mut db = get_db().await;
let result = process_presentation(54, &mut db).await; // let result = process_presentation(54, &mut db).await;
let json_presentation_file = PathBuf::from("./test/test_presentation.json"); // let json_presentation_file =
if let Ok(path) = canonicalize(json_presentation_file) { // PathBuf::from("./test/test_presentation.json");
debug!(file = ?&path); // if let Ok(path) = canonicalize(json_presentation_file) {
if let Ok(s) = fs::read_to_string(path) { // debug!(file = ?&path);
debug!(s); // if let Ok(s) = fs::read_to_string(path) {
match result { // debug!(s);
Ok(json) => assert_eq!(json.to_string(), s), // match result {
Err(e) => panic!("There was an error in processing the presentation: {e}"), // Ok(json) => assert_eq!(json.to_string(), s),
} // Err(e) => panic!(
} else { // "There was an error in processing the presentation: {e}"
panic!("String wasn't read from file"); // ),
} // }
} else { // } else {
panic!("Cannot find absolute path to test_presentation.json"); // panic!("String wasn't read from file");
} // }
} // } else {
// panic!(
// "Cannot find absolute path to test_presentation.json"
// );
// }
// }
fn get_items() -> Vec<ServiceItem> { // fn get_items() -> Vec<ServiceItem> {
let items = vec![ // let items = vec![
ServiceItem { // ServiceItem {
database_id: 7, // database_id: 7,
kind: ServiceItemKind::Song, // kind: ServiceItemKind::Song,
id: 0, // id: 0,
}, // },
ServiceItem { // ServiceItem {
database_id: 54, // database_id: 54,
kind: ServiceItemKind::Presentation(PresKind::Html), // kind: ServiceItemKind::Presentation(PresKind::Html),
id: 0, // id: 0,
}, // },
ServiceItem { // ServiceItem {
database_id: 73, // database_id: 73,
kind: ServiceItemKind::Video, // kind: ServiceItemKind::Video,
id: 0, // id: 0,
}, // },
]; // ];
items // items
} // }
#[tokio::test] // #[tokio::test]
async fn test_service_items() { // async fn test_service_items() {
let mut db = get_db().await; // let mut db = get_db().await;
let items = get_items(); // let items = get_items();
let json_item_file = PathBuf::from("./test/test_service_items.json"); // let json_item_file =
let result = process_service_items(&items, &mut db).await; // PathBuf::from("./test/test_service_items.json");
if let Ok(path) = canonicalize(json_item_file) { // let result = process_service_items(&items, &mut db).await;
if let Ok(s) = fs::read_to_string(path) { // if let Ok(path) = canonicalize(json_item_file) {
match result { // if let Ok(s) = fs::read_to_string(path) {
Ok(strings) => assert_eq!(strings.to_string(), s), // match result {
Err(e) => panic!("There was an error: {e}"), // Ok(strings) => assert_eq!(strings.to_string(), s),
} // Err(e) => panic!("There was an error: {e}"),
} // }
} // }
} // }
// }
// #[tokio::test] // // #[tokio::test]
// async fn test_save() { // // async fn test_save() {
// let path = PathBuf::from("~/dev/lumina/src/rust/core/test.pres"); // // let path = PathBuf::from("~/dev/lumina/src/rust/core/test.pres");
// let list = get_items(); // // let list = get_items();
// match save(list, path).await { // // match save(list, path).await {
// Ok(_) => assert!(true), // // Ok(_) => assert!(true),
// Err(e) => panic!("There was an error: {e}"), // // Err(e) => panic!("There was an error: {e}"),
// } // // }
// } // // }
#[tokio::test] // #[tokio::test]
async fn test_store() { // async fn test_store() {
let path = PathBuf::from("/home/chris/dev/lumina/src/rust/core/test.pres"); // let path = PathBuf::from(
let save_file = match File::create(path) { // "/home/chris/dev/lumina/src/rust/core/test.pres",
Ok(f) => f, // );
Err(e) => panic!("Couldn't create save_file: {e}"), // let save_file = match File::create(path) {
}; // Ok(f) => f,
let mut db = get_db().await; // Err(e) => panic!("Couldn't create save_file: {e}"),
let list = get_items(); // };
if let Ok(json) = process_service_items(&list, &mut db).await { // let mut db = get_db().await;
println!("{:?}", json); // let list = get_items();
match store_service_items(&list, &mut db, &save_file, &json).await { // if let Ok(json) = process_service_items(&list, &mut db).await
Ok(_) => assert!(true), // {
Err(e) => panic!("There was an error: {e}"), // println!("{:?}", json);
} // match store_service_items(
} else { // &list, &mut db, &save_file, &json,
panic!("There was an error getting the json value"); // )
} // .await
} // {
// Ok(_) => assert!(true),
// Err(e) => panic!("There was an error: {e}"),
// }
// } else {
// panic!("There was an error getting the json value");
// }
// }
// #[tokio::test] // // #[tokio::test]
// async fn test_things() { // // async fn test_things() {
// let mut temp_dir = dirs::data_dir().unwrap(); // // let mut temp_dir = dirs::data_dir().unwrap();
// temp_dir.push("lumina"); // // temp_dir.push("lumina");
// let mut s: String = // // let mut s: String =
// iter::repeat_with(fastrand::alphanumeric) // // iter::repeat_with(fastrand::alphanumeric)
// .take(5) // // .take(5)
// .collect(); // // .collect();
// s.insert_str(0, "temp_"); // // s.insert_str(0, "temp_");
// temp_dir.push(s); // // temp_dir.push(s);
// let _ = fs::create_dir_all(&temp_dir); // // let _ = fs::create_dir_all(&temp_dir);
// let mut db = get_db().await; // // let mut db = get_db().await;
// let service_file = temp_dir.join("serviceitems.json"); // // let service_file = temp_dir.join("serviceitems.json");
// let list = get_items(); // // let list = get_items();
// if let Ok(json) = process_service_items(&list, &mut db).await { // // if let Ok(json) = process_service_items(&list, &mut db).await {
// let _ = fs::File::create(&service_file); // // let _ = fs::File::create(&service_file);
// match fs::write(service_file, json.to_string()) { // // match fs::write(service_file, json.to_string()) {
// Ok(_) => assert!(true), // // Ok(_) => assert!(true),
// Err(e) => panic!("There was an error: {e}"), // // Err(e) => panic!("There was an error: {e}"),
// } // // }
// } else { // // } else {
// panic!("There was an error getting the json value"); // // panic!("There was an error getting the json value");
// } // // }
// } // // }
} // }

View file

@ -1,4 +1,5 @@
pub mod content; pub mod content;
pub mod file;
pub mod images; pub mod images;
pub mod kinds; pub mod kinds;
pub mod model; pub mod model;

View file

@ -47,6 +47,12 @@ impl TryFrom<(Vec<u8>, String)> for ServiceItem {
fn try_from( fn try_from(
value: (Vec<u8>, String), value: (Vec<u8>, String),
) -> std::result::Result<Self, Self::Error> { ) -> std::result::Result<Self, Self::Error> {
let (data, mime) = value;
match mime.as_str() {
"application/service_item" => {}
"text/uri-list" => {}
"x-special/gnome-copied-files" => {}
}
debug!(?value); debug!(?value);
ron::de::from_bytes(&value.0).into_diagnostic() ron::de::from_bytes(&value.0).into_diagnostic()
} }
@ -54,7 +60,11 @@ impl TryFrom<(Vec<u8>, String)> for ServiceItem {
impl AllowedMimeTypes for ServiceItem { impl AllowedMimeTypes for ServiceItem {
fn allowed() -> Cow<'static, [String]> { fn allowed() -> Cow<'static, [String]> {
Cow::from(vec!["application/service-item".to_string()]) Cow::from(vec![
"application/service-item".to_string(),
"text/uri-list".to_string(),
"x-special/gnome-copied-files".to_string(),
])
} }
} }