Skip to content

Commit

Permalink
fix bad api calls copied original
Browse files Browse the repository at this point in the history
  • Loading branch information
1majom committed Aug 12, 2024
1 parent 4131c09 commit 2205dbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export CAROOT ?= $(shell cd dev ; go run filippo.io/mkcert -CAROOT)

.PHONY: run
run: dev/localhost.crt
@./gen_compose.sh
@docker-compose up --build --remove-orphans

dev/localhost.crt:
Expand Down
23 changes: 13 additions & 10 deletions moq-api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ impl Client {
pub fn new(url: Url, node:Url, original: bool) -> Self {
let client = reqwest::Client::new();
let parts:Vec<&str> = node.host_str().unwrap().split('.').collect();
log::debug!("{:?}",parts);

if parts.len() > 3 {
if parts.len() == 4 && !original {
Self { url: url.clone(), client, relayid:parts[3].to_string() , original }
} else {
log::info!("The hostname is not an IPv4 address. The specified API won't work.");
Self { url: url.clone(), client, relayid:"".to_string() , original:false }
log::info!("The hostname is not an IPv4 address. The specified API will not work.");
if original {
Self { url: url.clone(), client, relayid:"".to_string() , original:true }
}
else {
panic!("The hostname is an IPv4 address. But trying to use the specified API.");
}
}
}

pub async fn get_origin(&self, namespace: &str) -> Result<Option<Origin>, ApiError> {
let url;
if self.original {
url = self.url.join("origin/")?.join(namespace)?;
url = self.url.join(&format!("origin/{}", namespace))?;
}
else {
url = self.url.join(&format!("origin/{}/{}", self.relayid.to_string(), namespace))?;
Expand All @@ -48,11 +52,10 @@ impl Client {
pub async fn set_origin(&self, namespace: &str, origin: Origin) -> Result<(), ApiError> {
let url: Url;
if self.original {
url = self.url.join("origin/")?.join(namespace)?;
url = self.url.join(&format!("origin/{}", namespace))?;
}
else {
let rest=self.relayid.clone().to_string()+"/"+namespace;
url = self.url.join("origin/")?.join(&rest)?;
url = self.url.join(&format!("origin/{}/{}", self.relayid,namespace))?;
}


Expand All @@ -63,7 +66,7 @@ impl Client {
}

pub async fn delete_origin(&self, namespace: &str) -> Result<(), ApiError> {
let url = self.url.join("origin/")?.join(namespace)?;
let url = self.url.join(&format!("origin/{}", namespace))?;

let resp = self.client.delete(url).send().await?;
resp.error_for_status()?;
Expand All @@ -72,7 +75,7 @@ impl Client {
}

pub async fn patch_origin(&self, namespace: &str, origin: Origin) -> Result<(), ApiError> {
let url = self.url.join("origin/")?.join(namespace)?;
let url = self.url.join(&format!("origin/{}", namespace))?;

let resp = self.client.patch(url).json(&origin).send().await?;
resp.error_for_status()?;
Expand Down

0 comments on commit 2205dbe

Please sign in to comment.