Skip to content

Commit b45018d

Browse files
committed
refactor: drop webhook system
1 parent 5e97f4d commit b45018d

File tree

8 files changed

+3
-118
lines changed

8 files changed

+3
-118
lines changed

Cargo.lock

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ sha2 = "0.10.8"
4747
sqlx = { version = "0.8.1", features = ["mysql", "runtime-tokio", "chrono", "uuid"] }
4848
config = { version = "0.14.0", features = ["yaml"] }
4949
chrono = { version = "0.4.38", features = ["serde"] }
50-
url = "2.5.0"
5150
serde_with = { version = "3.8.1", features = ["hex"] }
5251
reqwest = { version = "0.12.8", features = ["stream"] }
5352
clap = { version = "4.5.18", features = ["derive"] }
@@ -63,7 +62,4 @@ candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag =
6362
sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] }
6463
http-range-header = { version = "0.4.2", optional = true }
6564
nostr-cursor = { git = "https://git.v0l.io/Kieran/nostr_backup_proc.git", branch = "main", optional = true }
66-
regex = { version = "1.11.1", optional = true }
67-
rand = "0.8.5"
68-
69-
65+
regex = { version = "1.11.1", optional = true }

config.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ vit_model:
2121
model: "/home/kieran/Downloads/falcon_nsfw.safetensors"
2222
config: "/home/kieran/Downloads/falcon_nsfw.json"
2323

24-
# Webhook api endpoint
25-
# webhook_url: "https://api.snort.social/api/v1/media/webhook"
26-
2724
# Analytics support
2825
# plausible_url: "https://plausible.com/"
2926

src/bin/main.rs

-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use route96::filesystem::FileStore;
1818
use route96::routes;
1919
use route96::routes::{get_blob, head_blob, root};
2020
use route96::settings::Settings;
21-
use route96::webhook::Webhook;
2221

2322
#[derive(Parser, Debug)]
2423
#[command(version, about)]
@@ -68,12 +67,6 @@ async fn main() -> Result<(), Error> {
6867
.manage(FileStore::new(settings.clone()))
6968
.manage(settings.clone())
7069
.manage(db.clone())
71-
.manage(
72-
settings
73-
.webhook_url
74-
.as_ref()
75-
.map(|w| Webhook::new(w.clone())),
76-
)
7770
.attach(CORS)
7871
.attach(Shield::new()) // disable
7972
.mount(

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ pub mod settings;
1111
#[cfg(any(feature = "void-cat-redirects", feature = "bin-void-cat-migrate"))]
1212
pub mod void_db;
1313
pub mod void_file;
14-
pub mod webhook;

src/routes/blossom.rs

+2-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::db::{Database, FileUpload};
33
use crate::filesystem::{FileStore, FileSystemResult};
44
use crate::routes::{delete_file, Nip94Event};
55
use crate::settings::Settings;
6-
use crate::webhook::Webhook;
76
use log::error;
87
use nostr::prelude::hex;
98
use nostr::{Alphabet, SingleLetterTag, TagKind};
@@ -15,7 +14,6 @@ use rocket::serde::json::Json;
1514
use rocket::{routes, Data, Request, Response, Route, State};
1615
use serde::{Deserialize, Serialize};
1716
use std::collections::HashMap;
18-
use std::fs;
1917
use tokio::io::AsyncRead;
2018
use tokio_util::io::StreamReader;
2119

@@ -213,10 +211,9 @@ async fn upload(
213211
fs: &State<FileStore>,
214212
db: &State<Database>,
215213
settings: &State<Settings>,
216-
webhook: &State<Option<Webhook>>,
217214
data: Data<'_>,
218215
) -> BlossomResponse {
219-
process_upload("upload", false, auth, fs, db, settings, webhook, data).await
216+
process_upload("upload", false, auth, fs, db, settings, data).await
220217
}
221218

222219
#[rocket::put("/mirror", data = "<req>", format = "json")]
@@ -225,7 +222,6 @@ async fn mirror(
225222
fs: &State<FileStore>,
226223
db: &State<Database>,
227224
settings: &State<Settings>,
228-
webhook: &State<Option<Webhook>>,
229225
req: Json<MirrorRequest>,
230226
) -> BlossomResponse {
231227
if !check_method(&auth.event, "mirror") {
@@ -263,7 +259,6 @@ async fn mirror(
263259
fs,
264260
db,
265261
settings,
266-
webhook,
267262
)
268263
.await
269264
}
@@ -281,10 +276,9 @@ async fn upload_media(
281276
fs: &State<FileStore>,
282277
db: &State<Database>,
283278
settings: &State<Settings>,
284-
webhook: &State<Option<Webhook>>,
285279
data: Data<'_>,
286280
) -> BlossomResponse {
287-
process_upload("media", true, auth, fs, db, settings, webhook, data).await
281+
process_upload("media", true, auth, fs, db, settings, data).await
288282
}
289283

290284
fn check_head(auth: BlossomAuth, settings: &State<Settings>) -> BlossomHead {
@@ -337,7 +331,6 @@ async fn process_upload(
337331
fs: &State<FileStore>,
338332
db: &State<Database>,
339333
settings: &State<Settings>,
340-
webhook: &State<Option<Webhook>>,
341334
data: Data<'_>,
342335
) -> BlossomResponse {
343336
if !check_method(&auth.event, method) {
@@ -380,7 +373,6 @@ async fn process_upload(
380373
fs,
381374
db,
382375
settings,
383-
webhook,
384376
)
385377
.await
386378
}
@@ -394,30 +386,12 @@ async fn process_stream<'p, S>(
394386
fs: &State<FileStore>,
395387
db: &State<Database>,
396388
settings: &State<Settings>,
397-
webhook: &State<Option<Webhook>>,
398389
) -> BlossomResponse
399390
where
400391
S: AsyncRead + Unpin + 'p,
401392
{
402393
let upload = match fs.put(stream, mime_type, compress).await {
403394
Ok(FileSystemResult::NewFile(blob)) => {
404-
if let Some(wh) = webhook.as_ref() {
405-
match wh.store_file(pubkey, blob.clone()).await {
406-
Ok(store) => {
407-
if !store {
408-
let _ = fs::remove_file(blob.path);
409-
return BlossomResponse::error("Upload rejected");
410-
}
411-
}
412-
Err(e) => {
413-
let _ = fs::remove_file(blob.path);
414-
return BlossomResponse::error(format!(
415-
"Internal error, failed to call webhook: {}",
416-
e
417-
));
418-
}
419-
}
420-
}
421395
let mut ret: FileUpload = (&blob).into();
422396

423397
// update file data before inserting

src/routes/nip96.rs

-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashMap;
2-
use std::fs;
32
use std::ops::Sub;
43
use std::time::Duration;
54

@@ -17,7 +16,6 @@ use crate::db::{Database, FileUpload};
1716
use crate::filesystem::{FileStore, FileSystemResult};
1817
use crate::routes::{delete_file, Nip94Event, PagedResult};
1918
use crate::settings::Settings;
20-
use crate::webhook::Webhook;
2119

2220
#[derive(Serialize, Default)]
2321
#[serde(crate = "rocket::serde")]
@@ -174,7 +172,6 @@ async fn upload(
174172
fs: &State<FileStore>,
175173
db: &State<Database>,
176174
settings: &State<Settings>,
177-
webhook: &State<Option<Webhook>>,
178175
form: Form<Nip96Form<'_>>,
179176
) -> Nip96Response {
180177
if let Some(size) = auth.content_length {
@@ -215,24 +212,6 @@ async fn upload(
215212
.await
216213
{
217214
Ok(FileSystemResult::NewFile(blob)) => {
218-
if let Some(wh) = webhook.as_ref() {
219-
match wh.store_file(&pubkey_vec, blob.clone()).await {
220-
Ok(store) => {
221-
if !store {
222-
let _ = fs::remove_file(blob.path);
223-
return Nip96Response::error("Upload rejected");
224-
}
225-
}
226-
Err(e) => {
227-
let _ = fs::remove_file(blob.path);
228-
return Nip96Response::error(&format!(
229-
"Internal error, failed to call webhook: {}",
230-
e
231-
));
232-
}
233-
}
234-
}
235-
236215
let mut upload: FileUpload = (&blob).into();
237216
upload.name = form.caption.map(|cap| cap.to_string());
238217
upload.alt = form.alt.as_ref().map(|s| s.to_string());

src/webhook.rs

-51
This file was deleted.

0 commit comments

Comments
 (0)