From f9c0739d5e92fbbc33cce8daf2ede9d12c57da9d Mon Sep 17 00:00:00 2001 From: frozenbloo Date: Fri, 24 Nov 2023 09:19:48 +0000 Subject: [PATCH 1/5] Hopeful Fix to the stupid discord change --- src/grpc/attachments.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/grpc/attachments.rs b/src/grpc/attachments.rs index a62b478..2368b56 100644 --- a/src/grpc/attachments.rs +++ b/src/grpc/attachments.rs @@ -27,6 +27,9 @@ impl Attachments for ImplementedAttachmentsServer { let file_url = request.into_inner().url; debug!("finished parsing url: {}", file_url); + // remove if broken + file_url = file_url.split('?').next().unwrap_or(file_url); + let ext = Files::get_extension(&file_url)?; let bytes = Files::fetch(&file_url).await?; info!("fetched attachment: {}", file_url); From 5a248cdd9cd2bcf12a1a497677607f963560ecb6 Mon Sep 17 00:00:00 2001 From: Frozenbloo <61006165+Frozenbloo@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:30:20 +0000 Subject: [PATCH 2/5] Update docker.yml --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 33246ee..035b436 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -35,4 +35,4 @@ jobs: context: . platforms: linux/amd64 push: ${{ github.event_name != 'pull_request' }} - tags: ghcr.io/fg-devs/attachment-service:latest + tags: ghcr.io/survivalquestmc/attachment-service:latest From 300eeb15d8429dbe6193c4735d7d95251e7dc2ec Mon Sep 17 00:00:00 2001 From: frozenbloo Date: Fri, 24 Nov 2023 09:36:05 +0000 Subject: [PATCH 3/5] Fix hopefully? --- src/grpc/attachments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grpc/attachments.rs b/src/grpc/attachments.rs index 2368b56..b57e356 100644 --- a/src/grpc/attachments.rs +++ b/src/grpc/attachments.rs @@ -28,7 +28,7 @@ impl Attachments for ImplementedAttachmentsServer { debug!("finished parsing url: {}", file_url); // remove if broken - file_url = file_url.split('?').next().unwrap_or(file_url); + file_url = file_url.split('?').next().unwrap_or(file_url).to_string(); let ext = Files::get_extension(&file_url)?; let bytes = Files::fetch(&file_url).await?; From 0caaefacbe7f20b2cb5ff749e7b38c8a22b6c965 Mon Sep 17 00:00:00 2001 From: frozenbloo Date: Fri, 24 Nov 2023 09:52:44 +0000 Subject: [PATCH 4/5] fix? --- src/grpc/attachments.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grpc/attachments.rs b/src/grpc/attachments.rs index b57e356..835c9d7 100644 --- a/src/grpc/attachments.rs +++ b/src/grpc/attachments.rs @@ -28,7 +28,7 @@ impl Attachments for ImplementedAttachmentsServer { debug!("finished parsing url: {}", file_url); // remove if broken - file_url = file_url.split('?').next().unwrap_or(file_url).to_string(); + file_url = file_url.split('?').next().unwrap_or(file_url.as_str()); let ext = Files::get_extension(&file_url)?; let bytes = Files::fetch(&file_url).await?; From 3f9fe222ba55eaec4a842403d67ef984a10a5502 Mon Sep 17 00:00:00 2001 From: Jared Date: Wed, 29 Nov 2023 21:05:55 +1100 Subject: [PATCH 5/5] GhatGPT fix for extra params on discord url --- Cargo.lock | 1 + Cargo.toml | 1 + src/grpc/attachments.rs | 13 +++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5048b84..bdba70b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,6 +66,7 @@ dependencies = [ "tower-http 0.2.5", "tracing", "tracing-subscriber", + "url", "uuid", ] diff --git a/Cargo.toml b/Cargo.toml index e1cd68e..b5fb021 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ tower-http = { version = "0.2.5", features = ["fs", "trace"] } tracing = "0.1.34" tracing-subscriber = { version = "0.3.11", features = ["env-filter"] } uuid = { version = "0.8.2", features = ["v4"] } +url = "2.2.2" [build-dependencies] tonic-build = "0.7.0" diff --git a/src/grpc/attachments.rs b/src/grpc/attachments.rs index 835c9d7..4825464 100644 --- a/src/grpc/attachments.rs +++ b/src/grpc/attachments.rs @@ -4,6 +4,7 @@ use std::env; use tonic::{Request, Response, Status}; use tracing::*; use uuid::Uuid; +use url::Url; use crate::Files; pub use attachments_proto::attachments_server::AttachmentsServer; @@ -24,11 +25,15 @@ impl Attachments for ImplementedAttachmentsServer { info!("received create attachment request"); trace!("parsing url"); - let file_url = request.into_inner().url; - debug!("finished parsing url: {}", file_url); + let mut file_url = request.into_inner().url; + + // Parse the URL and strip off the query parameters + if let Ok(mut parsed_url) = Url::parse(&file_url) { + parsed_url.set_query(None); + file_url = parsed_url.to_string(); + } - // remove if broken - file_url = file_url.split('?').next().unwrap_or(file_url.as_str()); + debug!("finished parsing url: {}", file_url); let ext = Files::get_extension(&file_url)?; let bytes = Files::fetch(&file_url).await?;