Skip to content

Commit d82528c

Browse files
committed
Use catbox.moe image hosting
ofc I think it will ban us soon XD
1 parent 468e58f commit d82528c

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

eh2telegraph/src/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ struct UploadedImage {
304304
src: String,
305305
}
306306

307-
// Size: {"tag":"img","attrs":{"src":"https://telegra.ph..."}}
308307
impl From<UploadedImage> for Node {
309308
fn from(i: UploadedImage) -> Self {
310-
Node::new_image(format!("https://telegra.ph{}", i.src))
309+
// Use the full URL directly since catbox.moe returns complete URLs
310+
Node::new_image(&i.src)
311311
}
312312
}

eh2telegraph/src/telegraph/mod.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -242,33 +242,32 @@ where
242242
IT: IntoIterator<Item = I>,
243243
I: Into<Cow<'static, [u8]>>,
244244
{
245-
let mut form = Form::new();
246-
let mut cnt = 0;
247-
for (idx, data) in files.into_iter().enumerate() {
248-
let part = Part::bytes(data).file_name(idx.to_string());
249-
form = form.part(idx.to_string(), part);
250-
cnt += 1;
251-
}
252-
253-
let r: Result<Vec<MediaInfo>, TelegraphError> = self
254-
.client
255-
.post_builder("https://telegra.ph/upload")
256-
.multipart(form)
257-
.send()
258-
.await
259-
.and_then(Response::error_for_status)?
260-
.json::<UploadResult>()
261-
.await?
262-
.into();
263-
264-
// Here we check if server returns the same amount as files posted
265-
r.and_then(|x| {
266-
if x.len() != cnt {
267-
Err(TelegraphError::Server)
245+
let mut results = Vec::new();
246+
247+
for data in files.into_iter() {
248+
let form = Form::new()
249+
.text("reqtype", "fileupload")
250+
.text("userhash", "") // Empty string for anonymous upload
251+
.part("fileToUpload", Part::bytes(data).file_name("image.jpg"));
252+
253+
let response = self.client
254+
.post_builder("https://catbox.moe/user/api.php")
255+
.multipart(form)
256+
.send()
257+
.await
258+
.and_then(Response::error_for_status)?;
259+
260+
let url = response.text().await?;
261+
262+
// catbox.moe returns just the URL as plain text
263+
if url.starts_with("https://files.catbox.moe/") {
264+
results.push(MediaInfo { src: url });
268265
} else {
269-
Ok(x)
266+
return Err(TelegraphError::Server);
270267
}
271-
})
268+
}
269+
270+
Ok(results)
272271
}
273272
}
274273

0 commit comments

Comments
 (0)