Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix jpeg extension not being correct
Browse files Browse the repository at this point in the history
  • Loading branch information
the-codeboy committed Mar 8, 2024
1 parent 3edea66 commit f04e3f7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
extern crate rocket;

use regex::Regex;
use rocket::fs::FileServer;
use rocket::response::Redirect;
use reqwest::header::{HeaderMap, HeaderValue};
Expand All @@ -20,9 +19,9 @@ async fn download(url: &str) -> Redirect {

println!("doc_id={}", doc_id);

let body = ureq::get(url).call().unwrap().into_string().unwrap();
let re = Regex::new(r##"token=(.*?)""##).unwrap();
let Some(caps) = re.captures(&*body) else {
let json = send_get_request(doc_id).await.unwrap();
let data = json["data"].as_object().unwrap();
if data["file_preview"].is_null(){
println!("no token found");
let json = send_get_request(doc_id).await.unwrap();
let token = get_token().await.unwrap();
Expand All @@ -32,9 +31,16 @@ async fn download(url: &str) -> Redirect {
.last()
.unwrap();
return Redirect::to(format!("https://cdn.studydrive.net/d/prod/documents/{}/original/{}.{}?token={}", doc_id, doc_id,ending, token));
};
let token = &caps[1];
Redirect::to(format!("https://cdn.studydrive.net/d/prod/documents/{}/original/{}.pdf?token={}", doc_id, doc_id, token))
}
let name = data["filename"].as_str().unwrap();
let ending=name.split(".")
.last()
.unwrap();
let preview = data["file_preview"].as_str().unwrap();
let token = preview.split("token=")
.last()
.unwrap();
Redirect::to(format!("https://cdn.studydrive.net/d/prod/documents/{}/original/{}.{}?token={}", doc_id, doc_id, ending, token))
}

async fn get_token() -> Result<String, Box<dyn std::error::Error>> {
Expand Down

0 comments on commit f04e3f7

Please sign in to comment.