Remove leftover references of gitea
All checks were successful
/ Building (push) Successful in 2m32s
All checks were successful
/ Building (push) Successful in 2m32s
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
b4ccb245a1
commit
73eebdca94
3 changed files with 44 additions and 18 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -254,6 +254,19 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-compression"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc2d0cfb2a7388d34f590e76686704c494ed7aaceed62ee1ba35cbf363abc2a5"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"futures-core",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
|
@ -262,9 +275,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.21.6"
|
||||
version = "0.21.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9"
|
||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
|
@ -1235,6 +1248,7 @@ version = "0.11.23"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41"
|
||||
dependencies = [
|
||||
"async-compression",
|
||||
"base64",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
|
@ -1260,6 +1274,7 @@ dependencies = [
|
|||
"system-configuration",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-util",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
|
|
|
@ -8,7 +8,7 @@ actix-web = { version = "4.4.1", default-features = false, features = ["macros",
|
|||
actix-files = "0.6.5"
|
||||
tera = "1.19.1"
|
||||
serde = { version = "1.0.195", features = ["derive"] }
|
||||
reqwest = { version = "0.11.23", default-features = false, features = ["rustls-tls"] }
|
||||
reqwest = { version = "0.11.23", default-features = false, features = ["rustls-tls", "gzip"] }
|
||||
serde_json = "1.0.111"
|
||||
base64 = "0.21.6"
|
||||
base64 = "0.21.7"
|
||||
mime = "0.3.17"
|
||||
|
|
39
src/main.rs
39
src/main.rs
|
@ -23,7 +23,7 @@ struct Paste {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GitLabSuccessJSON {
|
||||
struct GiteaSuccessJSON {
|
||||
name: String,
|
||||
path: String,
|
||||
size: u64,
|
||||
|
@ -34,42 +34,53 @@ struct GitLabSuccessJSON {
|
|||
html_url: String,
|
||||
git_url: String,
|
||||
submodule_git_url: Option<String>,
|
||||
content: String
|
||||
content: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GitLabFailedJSON {
|
||||
struct GiteaFailedJSON {
|
||||
errors: Option<Vec<String>>,
|
||||
message: String,
|
||||
url: String
|
||||
url: String,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Responder {
|
||||
let my_data = data.get_ref();
|
||||
let mut context = Context::new();
|
||||
let gitlab_token = env::var("GITEA_TOKEN").unwrap_or("".to_string());
|
||||
let base_url = env::var("BASE_URL").unwrap_or("https://gitea.com".to_string());
|
||||
let client = Client::new();
|
||||
let gitea_token = env::var("GITEA_TOKEN").unwrap_or("".to_string());
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert("Authorization", gitlab_token.parse().unwrap());
|
||||
headers.insert("Authorization", gitea_token.parse().unwrap());
|
||||
let base_url = env::var("BASE_URL").unwrap_or("https://gitea.com".to_string());
|
||||
let client = Client::builder()
|
||||
.default_headers(headers)
|
||||
.gzip(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
let paste_content: String;
|
||||
if paste.paste_id.is_some() {
|
||||
let response = client.get(format!("{}/contents/{}?ref=master", base_url, paste.paste_id.as_ref().unwrap())).headers(headers).send().await.unwrap();
|
||||
let response = client
|
||||
.get(format!(
|
||||
"{}/contents/{}?ref=master",
|
||||
base_url,
|
||||
paste.paste_id.as_ref().unwrap()
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
let response_code = response.status().as_str().to_string();
|
||||
let response_json = response.text().await.unwrap();
|
||||
if response_code != "200" {
|
||||
let resp_struct: GitLabFailedJSON = serde_json::from_str(&response_json).unwrap();
|
||||
let resp_struct: GiteaFailedJSON = serde_json::from_str(&response_json).unwrap();
|
||||
if resp_struct.message == "The target couldn't be found." {
|
||||
context.insert("md", "true");
|
||||
paste_content = "Project ID Mismatch/Gitea Token Missing".to_string();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
context.insert("md", "true");
|
||||
paste_content = "Paste ID is Invalid".to_string();
|
||||
}
|
||||
} else {
|
||||
let resp_struct: GitLabSuccessJSON = serde_json::from_str(&response_json).unwrap();
|
||||
let resp_struct: GiteaSuccessJSON = serde_json::from_str(&response_json).unwrap();
|
||||
paste_content = String::from_utf8(
|
||||
general_purpose::STANDARD
|
||||
.decode(resp_struct.content)
|
||||
|
@ -79,7 +90,7 @@ async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Respond
|
|||
}
|
||||
} else {
|
||||
context.insert("md", "true");
|
||||
paste_content = "This is a no-nonsense Pastebin Server, written in Rust. It serves the content from files on a GitLab Private Repository. Please look into the repository for hosting your own copy of this.".to_string();
|
||||
paste_content = "This is a no-nonsense Pastebin Server, written in Rust. It serves the content from files on a Gitea Private Repository. Please look into the repository for hosting your own copy of this.".to_string();
|
||||
}
|
||||
context.insert("paste_content", &paste_content);
|
||||
if paste.parse_md.is_some() {
|
||||
|
|
Loading…
Reference in a new issue