diff --git a/Cargo.lock b/Cargo.lock index 6ffc117..b130867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3202,7 +3202,6 @@ dependencies = [ "nostr", "nostr-cursor", "pretty_env_logger", - "rand", "regex", "reqwest", "rocket", @@ -3213,7 +3212,6 @@ dependencies = [ "sqlx-postgres", "tokio", "tokio-util", - "url", "uuid", ] diff --git a/Cargo.toml b/Cargo.toml index fb7dfda..c392586 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,6 @@ sha2 = "0.10.8" sqlx = { version = "0.8.1", features = ["mysql", "runtime-tokio", "chrono", "uuid"] } config = { version = "0.14.0", features = ["yaml"] } chrono = { version = "0.4.38", features = ["serde"] } -url = "2.5.0" serde_with = { version = "3.8.1", features = ["hex"] } reqwest = { version = "0.12.8", features = ["stream"] } clap = { version = "4.5.18", features = ["derive"] } @@ -63,7 +62,4 @@ candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag = sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] } http-range-header = { version = "0.4.2", optional = true } nostr-cursor = { git = "https://git.v0l.io/Kieran/nostr_backup_proc.git", branch = "main", optional = true } -regex = { version = "1.11.1", optional = true } -rand = "0.8.5" - - +regex = { version = "1.11.1", optional = true } \ No newline at end of file diff --git a/config.yaml b/config.yaml index e55bd69..d6e47f7 100644 --- a/config.yaml +++ b/config.yaml @@ -21,9 +21,6 @@ vit_model: model: "/home/kieran/Downloads/falcon_nsfw.safetensors" config: "/home/kieran/Downloads/falcon_nsfw.json" -# Webhook api endpoint -# webhook_url: "https://api.snort.social/api/v1/media/webhook" - # Analytics support # plausible_url: "https://plausible.com/" diff --git a/src/bin/main.rs b/src/bin/main.rs index 3f1568e..03fa101 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -18,7 +18,6 @@ use route96::filesystem::FileStore; use route96::routes; use route96::routes::{get_blob, head_blob, root}; use route96::settings::Settings; -use route96::webhook::Webhook; #[derive(Parser, Debug)] #[command(version, about)] @@ -68,12 +67,6 @@ async fn main() -> Result<(), Error> { .manage(FileStore::new(settings.clone())) .manage(settings.clone()) .manage(db.clone()) - .manage( - settings - .webhook_url - .as_ref() - .map(|w| Webhook::new(w.clone())), - ) .attach(CORS) .attach(Shield::new()) // disable .mount( diff --git a/src/lib.rs b/src/lib.rs index 57ac69d..b0d1c99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,4 +11,3 @@ pub mod settings; #[cfg(any(feature = "void-cat-redirects", feature = "bin-void-cat-migrate"))] pub mod void_db; pub mod void_file; -pub mod webhook; diff --git a/src/routes/blossom.rs b/src/routes/blossom.rs index ff6ee83..1a9795f 100644 --- a/src/routes/blossom.rs +++ b/src/routes/blossom.rs @@ -3,7 +3,6 @@ use crate::db::{Database, FileUpload}; use crate::filesystem::{FileStore, FileSystemResult}; use crate::routes::{delete_file, Nip94Event}; use crate::settings::Settings; -use crate::webhook::Webhook; use log::error; use nostr::prelude::hex; use nostr::{Alphabet, SingleLetterTag, TagKind}; @@ -15,7 +14,6 @@ use rocket::serde::json::Json; use rocket::{routes, Data, Request, Response, Route, State}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::fs; use tokio::io::AsyncRead; use tokio_util::io::StreamReader; @@ -213,10 +211,9 @@ async fn upload( fs: &State, db: &State, settings: &State, - webhook: &State>, data: Data<'_>, ) -> BlossomResponse { - process_upload("upload", false, auth, fs, db, settings, webhook, data).await + process_upload("upload", false, auth, fs, db, settings, data).await } #[rocket::put("/mirror", data = "", format = "json")] @@ -225,7 +222,6 @@ async fn mirror( fs: &State, db: &State, settings: &State, - webhook: &State>, req: Json, ) -> BlossomResponse { if !check_method(&auth.event, "mirror") { @@ -263,7 +259,6 @@ async fn mirror( fs, db, settings, - webhook, ) .await } @@ -281,10 +276,9 @@ async fn upload_media( fs: &State, db: &State, settings: &State, - webhook: &State>, data: Data<'_>, ) -> BlossomResponse { - process_upload("media", true, auth, fs, db, settings, webhook, data).await + process_upload("media", true, auth, fs, db, settings, data).await } fn check_head(auth: BlossomAuth, settings: &State) -> BlossomHead { @@ -337,7 +331,6 @@ async fn process_upload( fs: &State, db: &State, settings: &State, - webhook: &State>, data: Data<'_>, ) -> BlossomResponse { if !check_method(&auth.event, method) { @@ -380,7 +373,6 @@ async fn process_upload( fs, db, settings, - webhook, ) .await } @@ -394,30 +386,12 @@ async fn process_stream<'p, S>( fs: &State, db: &State, settings: &State, - webhook: &State>, ) -> BlossomResponse where S: AsyncRead + Unpin + 'p, { let upload = match fs.put(stream, mime_type, compress).await { Ok(FileSystemResult::NewFile(blob)) => { - if let Some(wh) = webhook.as_ref() { - match wh.store_file(pubkey, blob.clone()).await { - Ok(store) => { - if !store { - let _ = fs::remove_file(blob.path); - return BlossomResponse::error("Upload rejected"); - } - } - Err(e) => { - let _ = fs::remove_file(blob.path); - return BlossomResponse::error(format!( - "Internal error, failed to call webhook: {}", - e - )); - } - } - } let mut ret: FileUpload = (&blob).into(); // update file data before inserting diff --git a/src/routes/nip96.rs b/src/routes/nip96.rs index 0b158c5..1993d1a 100644 --- a/src/routes/nip96.rs +++ b/src/routes/nip96.rs @@ -1,5 +1,4 @@ use std::collections::HashMap; -use std::fs; use std::ops::Sub; use std::time::Duration; @@ -17,7 +16,6 @@ use crate::db::{Database, FileUpload}; use crate::filesystem::{FileStore, FileSystemResult}; use crate::routes::{delete_file, Nip94Event, PagedResult}; use crate::settings::Settings; -use crate::webhook::Webhook; #[derive(Serialize, Default)] #[serde(crate = "rocket::serde")] @@ -174,7 +172,6 @@ async fn upload( fs: &State, db: &State, settings: &State, - webhook: &State>, form: Form>, ) -> Nip96Response { if let Some(size) = auth.content_length { @@ -215,24 +212,6 @@ async fn upload( .await { Ok(FileSystemResult::NewFile(blob)) => { - if let Some(wh) = webhook.as_ref() { - match wh.store_file(&pubkey_vec, blob.clone()).await { - Ok(store) => { - if !store { - let _ = fs::remove_file(blob.path); - return Nip96Response::error("Upload rejected"); - } - } - Err(e) => { - let _ = fs::remove_file(blob.path); - return Nip96Response::error(&format!( - "Internal error, failed to call webhook: {}", - e - )); - } - } - } - let mut upload: FileUpload = (&blob).into(); upload.name = form.caption.map(|cap| cap.to_string()); upload.alt = form.alt.as_ref().map(|s| s.to_string()); diff --git a/src/webhook.rs b/src/webhook.rs deleted file mode 100644 index 8726dcf..0000000 --- a/src/webhook.rs +++ /dev/null @@ -1,51 +0,0 @@ -use anyhow::Error; -use nostr::serde_json; -use reqwest::{Client, ClientBuilder}; -use serde::{Deserialize, Serialize}; - -use crate::filesystem::NewFileResult; - -pub struct Webhook { - url: String, - client: Client, -} - -#[derive(Serialize, Deserialize)] -struct WebhookRequest { - pub action: String, - pub subject: Option, - pub payload: T, -} - -impl Webhook { - pub fn new(url: String) -> Self { - Self { - url, - client: ClientBuilder::new().build().unwrap(), - } - } - - /// Ask webhook api if this file can be accepted - pub async fn store_file(&self, pubkey: &Vec, fs: NewFileResult) -> Result { - let body = WebhookRequest { - action: "store_file".to_string(), - subject: Some(hex::encode(pubkey)), - payload: fs, - }; - let body = serde_json::to_string(&body)?; - let req = self - .client - .post(&self.url) - .header("accept", "application/json") - .header("content-type", "application/json") - .body(body) - .send() - .await?; - - if req.status() == 200 { - Ok(true) - } else { - Ok(false) - } - } -}