Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Chikage0o0/matrix-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Chikage0o0 committed Oct 30, 2023
2 parents 9217d21 + 63602c2 commit acf00d2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions matrix_bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async fn main() {
.filter(None, log::LevelFilter::Info)
.filter(Some("matrix_sdk"), log::LevelFilter::Warn)
.filter(Some("tracing"), log::LevelFilter::Warn)
.filter(Some("ruma_common"), log::LevelFilter::Warn)
.init();

let args = Args::parse();
Expand All @@ -61,7 +62,10 @@ async fn main() {
let _ = load_plugins(&matrix_client, args.data.join("plugins"), &args.plugins);

let ctrlc = tokio::signal::ctrl_c();
let mut term= tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).unwrap();

#[cfg(unix)]
let mut term =
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).unwrap();

let client = matrix_client.clone();

Expand All @@ -79,7 +83,7 @@ async fn main() {
_=handle => {
log::error!("Syncing stopped");
}

_=term.recv() => {
log::info!("SIGTERM received, stopping");
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/qbittorrent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ reqwest = { version = "0.11.6", default-features = false, features = [
"json",
"trust-dns",
"rustls-tls-native-roots",
"stream",
] }
regex = "1.10.0"
once_cell = "1.8.0"
url = "2.4.1"
tokio-util = { version = "0.7.9", default-features = false, features = ["io"] }
serde_json = "1.0.68"
walkdir = "2.4.0"

Expand Down
21 changes: 13 additions & 8 deletions plugins/qbittorrent/src/upload/gofile.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use anyhow::Result;
use reqwest::Body;
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, path::Path};
use std::path::Path;
use tokio::fs::File;
use tokio_util::io::ReaderStream;
use walkdir::WalkDir;

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -38,12 +41,13 @@ pub async fn upload<P: AsRef<Path>>(file_path: P) -> Result<String> {
})
{
let file_name = entry.file_name().to_string_lossy().to_string();
let file = std::fs::read(entry.path())?;
let file = File::open(entry.path()).await?;
let file_stream = ReaderStream::new(file);
let upload = UploadParams {
server: server.clone(),
token: token.clone(),
folder_id: folder_id.clone(),
file,
file_stream,
file_name,
};
let upload = upload_file(upload).await?;
Expand All @@ -69,12 +73,13 @@ pub async fn upload<P: AsRef<Path>>(file_path: P) -> Result<String> {
.unwrap()
.to_string_lossy()
.to_string();
let file = std::fs::read(file_path)?;
let file = File::open(file_path).await?;
let file_stream = ReaderStream::new(file);
let upload = UploadParams {
server,
token: None,
folder_id: None,
file,
file_stream,
file_name,
};
let upload = upload_file(upload).await?;
Expand All @@ -87,7 +92,7 @@ struct UploadParams {
server: String,
token: Option<String>,
folder_id: Option<String>,
file: Vec<u8>,
file_stream: ReaderStream<File>,
file_name: String,
}

Expand All @@ -113,8 +118,8 @@ async fn upload_file(parameter: UploadParams) -> Result<UploadInfo> {
let url = format!("https://{}.gofile.io/uploadFile", parameter.server);

// 一定要有file_name方法,且参数不能为空,否则数据上传失败
let part =
reqwest::multipart::Part::bytes(Cow::from(parameter.file)).file_name(parameter.file_name);
let part = reqwest::multipart::Part::stream(Body::wrap_stream(parameter.file_stream))
.file_name(parameter.file_name);
let mut form = reqwest::multipart::Form::new().part("file", part);
if let Some(token) = parameter.token {
form = form.text("token", token);
Expand Down

0 comments on commit acf00d2

Please sign in to comment.