-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7f66a6
commit bf408b3
Showing
11 changed files
with
526 additions
and
122 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "qbittorrent" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
anyhow = "1" | ||
matrix_bot_core = { path = "../../matrix_bot_core" } | ||
log = "0.4.14" | ||
toml = "0.8.2" | ||
serde = { version = "1.0.188", features = ["derive"] } | ||
tokio = { version = "1.33.0", default-features = false, features = [] } | ||
qbit-rs = { version = "0.3.7" } | ||
|
||
[dev-dependencies] | ||
env_logger = "0.10.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use anyhow::Result; | ||
use matrix_bot_core::matrix::client::Client; | ||
|
||
mod qbit; | ||
mod setting; | ||
|
||
#[allow(unused_variables)] | ||
pub async fn run(client: Client, plugin_folder: impl AsRef<std::path::Path>) -> Result<()> { | ||
log::info!("start yande_popular"); | ||
|
||
let setting = setting::get_or_init(plugin_folder)?; | ||
|
||
if setting.use_internal_qbit {} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use anyhow::Result; | ||
|
||
#[allow(dead_code)] | ||
fn get_download_link() -> Result<String> { | ||
if !(cfg!(target_os = "linux")) { | ||
return Err(anyhow::anyhow!("only support linux")); | ||
} | ||
|
||
let mut link = | ||
"https://github.com/userdocs/qbittorrent-nox-static/releases/latest/download/".to_string(); | ||
if cfg!(target_arch = "x86_64") { | ||
link.push_str("x86_64-qbittorrent-nox"); | ||
} else if cfg!(target_arch = "aarch64") { | ||
link.push_str("aarch64-qbittorrent-nox"); | ||
} else if cfg!(target_arch = "x86") { | ||
link.push_str("x86-qbittorrent-nox"); | ||
} else { | ||
return Err(anyhow::anyhow!("only support x86_64 and aarch64")); | ||
} | ||
Ok(link) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod binary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Setting { | ||
pub room_setting: Vec<RoomSetting>, | ||
pub qbit_user: String, | ||
pub qbit_pass: String, | ||
pub qbit_url: String, | ||
pub use_internal_qbit: bool, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct RoomSetting { | ||
pub download_path: PathBuf, | ||
pub file_size_limit: u128, | ||
pub room_id: String, | ||
pub db_path: PathBuf, | ||
} | ||
|
||
pub fn get_or_init(path: impl AsRef<Path>) -> Result<Setting> { | ||
let setting_path = path.as_ref().join("qbittorrent.toml"); | ||
// load setting, if not exists, create it and exit | ||
let setting = if !setting_path.exists() { | ||
log::info!("create setting file: {}", setting_path.to_string_lossy()); | ||
let setting = Setting { | ||
room_setting: vec![RoomSetting { | ||
download_path: path.as_ref().join("qbittorrent").join("download"), | ||
file_size_limit: 0, | ||
room_id: "".to_string(), | ||
db_path: path.as_ref().join("qbittorrent").join("db"), | ||
}], | ||
qbit_user: "admin".to_string(), | ||
qbit_pass: "adminadmin".to_string(), | ||
qbit_url: "http://127.0.0.1:8080".to_string(), | ||
use_internal_qbit: true, | ||
}; | ||
let toml = toml::to_string_pretty(&setting).unwrap(); | ||
std::fs::write(&setting_path, toml)?; | ||
log::error!( | ||
"please edit setting file: {}", | ||
setting_path.to_string_lossy() | ||
); | ||
return Err(anyhow::anyhow!( | ||
"please edit setting file: {}", | ||
setting_path.to_string_lossy() | ||
)); | ||
} else { | ||
log::info!("load setting file: {}", setting_path.to_string_lossy()); | ||
let toml = std::fs::read_to_string(&setting_path)?; | ||
toml::from_str(&toml)? | ||
}; | ||
Ok(setting) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::{collections::HashMap, path::Path}; | ||
|
||
use anyhow::Result; | ||
use matrix_bot_core::matrix::{client::Client, room::Room}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Setting { | ||
pub room_id: Vec<String>, | ||
pub token: Option<String>, | ||
pub port: u16, | ||
} | ||
|
||
impl Setting { | ||
pub async fn to_hashmap(self, client: &Client) -> Result<HashMap<String, Room>> { | ||
let mut hashmap = HashMap::new(); | ||
for room_id in self.room_id { | ||
let room = Room::new(&client, &room_id).await?; | ||
hashmap.insert(room_id, room); | ||
} | ||
Ok(hashmap) | ||
} | ||
|
||
pub fn get_or_init(path: impl AsRef<Path>) -> Result<Self> { | ||
let setting_path = path.as_ref().join("webhook.toml"); | ||
|
||
// load setting, if not exists, create it and exit | ||
let setting: Setting = if !setting_path.exists() { | ||
log::info!("create setting file: {}", setting_path.to_string_lossy()); | ||
let settings = Setting { | ||
room_id: vec!["".to_string()], | ||
token: Some("123456".to_string()), | ||
port: 0, | ||
}; | ||
let toml = toml::to_string_pretty(&settings).unwrap(); | ||
std::fs::write(&setting_path, toml)?; | ||
log::error!( | ||
"please edit setting file: {}", | ||
setting_path.to_string_lossy() | ||
); | ||
return Err(anyhow::anyhow!( | ||
"please edit setting file: {}", | ||
setting_path.to_string_lossy() | ||
)); | ||
} else { | ||
log::info!("load setting file: {}", setting_path.to_string_lossy()); | ||
let toml = std::fs::read_to_string(&setting_path)?; | ||
toml::from_str(&toml)? | ||
}; | ||
Ok(setting) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.