1
0
Fork 0

add deploy zip

This commit is contained in:
chaos 2023-10-07 18:33:40 +01:00
parent 470e2deb4c
commit 8d039e9404
No known key found for this signature in database
6 changed files with 80 additions and 1 deletions

3
.gitignore vendored
View file

@ -2,4 +2,5 @@
dist
build
result
.direnv
.direnv
*.zip

22
Cargo.lock generated
View file

@ -209,6 +209,15 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
dependencies = [
"cfg-if",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -1214,6 +1223,7 @@ dependencies = [
"tokio",
"tracing",
"tracing-subscriber",
"zip",
]
[[package]]
@ -1749,3 +1759,15 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]
[[package]]
name = "zip"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261"
dependencies = [
"byteorder",
"crc32fast",
"crossbeam-utils",
"flate2",
]

View file

@ -11,6 +11,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9.9"
serde_with = "1.3.1"
zip = { version = "0.6.6", default-features = false, features = ["deflate"] }
serenity = { version = "0.11" }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

View file

@ -1,6 +1,7 @@
use crate::deploy_discord::deploy_discord;
use crate::deploy_mastodon::deploy_mastodon;
use crate::deploy_telegram::deploy_telegram;
use crate::deploy_zip::deploy_zip;
use crate::sticker_config::StickerConfig;
use std::collections::HashMap;
@ -46,6 +47,15 @@ pub async fn deploy(args: crate::args::DeployArgs) {
)
.await;
}
"zip" => {
println!("deploying {} to zip", &deploy_id);
deploy_zip(
deploy_id,
sticker_config,
args.folder.clone(),
)
.await;
}
"telegram" => {
println!("deploying {} to telegram", &deploy_id);
deploy_telegram(

44
src/deploy_zip.rs Normal file
View file

@ -0,0 +1,44 @@
use std::{collections::HashMap, io::{Read, Write}, path::{PathBuf, Path}, fs::File};
use crate::sticker_config::{Sticker, StickerConfig};
pub async fn deploy_zip(
deploy_id: String,
sticker_config: StickerConfig,
base_stickerdb_path: String,
) {
let deploy_where = sticker_config.deploy_where.get(&deploy_id).unwrap();
let pack_contents = sticker_config
.sticker_sets
.get(&deploy_where.pack_id)
.unwrap();
let pack_stickers: HashMap<String, Sticker> = pack_contents
.iter()
.map(|sticker_name| {
return (
sticker_name.clone(),
sticker_config.stickers.get(sticker_name).unwrap().clone(),
);
})
.collect();
let zip_path = format!("{}.zip", &deploy_id).to_string();
let path = Path::new(&zip_path);
let file = File::create(path).unwrap();
let mut zip = zip::ZipWriter::new(file);
let mut buffer = Vec::new();
for (name, sticker) in pack_stickers.into_iter() {
let sticker_path = PathBuf::from(&base_stickerdb_path).join(sticker.file);
let sticker_extension = (&sticker_path).extension().unwrap().to_string_lossy();
let mut sticker_file = File::open(&sticker_path).unwrap();
zip.start_file(format!("{}.{}", name, sticker_extension), Default::default()).unwrap();
sticker_file.read_to_end(&mut buffer).unwrap();
zip.write_all(&buffer).unwrap();
buffer.clear();
}
zip.finish().unwrap();
}

View file

@ -5,6 +5,7 @@ pub mod cmd_deploy;
pub mod deploy_discord;
pub mod deploy_mastodon;
pub mod deploy_telegram;
pub mod deploy_zip;
pub mod mastodon_api;
pub mod sticker_config;
pub mod tg_api;