From f95d968a9f3cdd25c2b8b6b918949fcc03460067 Mon Sep 17 00:00:00 2001 From: "xmppftw@kl.netlib.re" Date: Sat, 30 Dec 2023 00:06:11 +0100 Subject: [PATCH] Move upload_file_with to upload::send module --- xmpp/src/lib.rs | 16 +--------------- xmpp/src/upload/mod.rs | 1 + xmpp/src/upload/send.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 xmpp/src/upload/send.rs diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 0a4e776..3c65fdb 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -9,13 +9,11 @@ use futures::stream::StreamExt; use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; -use tokio::fs::File; pub use tokio_xmpp::parsers; use tokio_xmpp::parsers::{ caps::{compute_disco, hash_caps, Caps}, disco::{DiscoInfoQuery, DiscoInfoResult}, hashes::Algo, - http_upload::SlotRequest, iq::Iq, message::{Body, Message, MessageType}, muc::{user::MucUser, Muc}, @@ -235,19 +233,7 @@ impl Agent { } pub async fn upload_file_with(&mut self, service: &str, path: &Path) { - let name = path.file_name().unwrap().to_str().unwrap().to_string(); - let file = File::open(path).await.unwrap(); - let size = file.metadata().await.unwrap().len(); - let slot_request = SlotRequest { - filename: name, - size: size, - content_type: None, - }; - let to = service.parse::().unwrap(); - let request = Iq::from_get("upload1", slot_request).with_to(to.clone()); - self.uploads - .push((String::from("upload1"), to, path.to_path_buf())); - self.client.send_stanza(request.into()).await.unwrap(); + upload::send::upload_file_with(self, service, path).await } } diff --git a/xmpp/src/upload/mod.rs b/xmpp/src/upload/mod.rs index ce689d6..f38387b 100644 --- a/xmpp/src/upload/mod.rs +++ b/xmpp/src/upload/mod.rs @@ -5,3 +5,4 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. pub mod receive; +pub mod send; diff --git a/xmpp/src/upload/send.rs b/xmpp/src/upload/send.rs new file mode 100644 index 0000000..8b9272e --- /dev/null +++ b/xmpp/src/upload/send.rs @@ -0,0 +1,31 @@ +// Copyright (c) 2023 xmpp-rs contributors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +use std::path::Path; +use tokio::fs::File; +use tokio_xmpp::{ + parsers::{http_upload::SlotRequest, iq::Iq}, + Jid, +}; + +use crate::Agent; + +pub async fn upload_file_with(agent: &mut Agent, service: &str, path: &Path) { + let name = path.file_name().unwrap().to_str().unwrap().to_string(); + let file = File::open(path).await.unwrap(); + let size = file.metadata().await.unwrap().len(); + let slot_request = SlotRequest { + filename: name, + size: size, + content_type: None, + }; + let to = service.parse::().unwrap(); + let request = Iq::from_get("upload1", slot_request).with_to(to.clone()); + agent + .uploads + .push((String::from("upload1"), to, path.to_path_buf())); + agent.client.send_stanza(request.into()).await.unwrap(); +}