Skip to content

Commit

Permalink
Merge branch 'release/1.1.0-alpha.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
nekofar committed Jun 16, 2024
2 parents 076113b + bff8434 commit 06eb85f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [1.1.0-alpha.16] - 2024-06-16

### Features

- Add Lilnouns Camp to Platform enum and handle functionalities

## [1.1.0-alpha.15] - 2024-06-16

### Refactor
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lilnouns-click"
version = "1.1.0-alpha.15"
version = "1.1.0-alpha.16"
authors = ["Milad Nekofar <[email protected]>"]
edition = "2021"
description = "A Nounish URL shortener for LilNouns DAO."
Expand Down
49 changes: 48 additions & 1 deletion src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
queries::{fetch_lil_nouns_data, fetch_meta_gov_data, fetch_prop_lot_data},
routes::{
Community::LilNouns,
Platform::{Ethereum, MetaGov, PropLot},
Platform::{Ethereum, LilCamp, MetaGov, PropLot},
},
utils::create_og_image,
};
Expand All @@ -30,6 +30,7 @@ pub enum Platform {
Ethereum = 1,
PropLot = 2,
MetaGov = 3,
LilCamp = 4,
}

pub async fn handle_redirect<D>(req: Request, ctx: RouteContext<D>) -> worker::Result<Response> {
Expand All @@ -46,6 +47,7 @@ pub async fn handle_redirect<D>(req: Request, ctx: RouteContext<D>) -> worker::R
1 => Some(Ethereum),
2 => Some(PropLot),
3 => Some(MetaGov),
4 => Some(LilCamp),
_ => None,
};

Expand Down Expand Up @@ -94,6 +96,21 @@ pub async fn handle_redirect<D>(req: Request, ctx: RouteContext<D>) -> worker::R
.to_string();
(url, title, description, image)
}
(Some(LilNouns), Some(LilCamp)) => {
let url = format!(
"{}/{}?utm_source=farcaster&utm_medium=social&utm_campaign=governor&\
utm_content=proposal_{}",
"https://lilnouns.camp/proposals", numbers[2], numbers[2]
);
let (title, description) = fetch_lil_nouns_data(&ctx.env, numbers[2]).await?;
let image = req
.url()
.unwrap()
.join(format!("{}/og.png", sqid).as_str())
.unwrap()
.to_string();
(url, title, description, image)
}
_ => (String::new(), String::new(), String::new(), String::new()),
};

Expand Down Expand Up @@ -200,6 +217,7 @@ pub async fn handle_og_image<D>(_req: Request, ctx: RouteContext<D>) -> worker::
1 => Some(Ethereum),
2 => Some(PropLot),
3 => Some(MetaGov),
4 => Some(LilCamp),
_ => None,
};

Expand All @@ -216,6 +234,10 @@ pub async fn handle_og_image<D>(_req: Request, ctx: RouteContext<D>) -> worker::
let (title, description) = fetch_meta_gov_data(&ctx.env, numbers[2]).await?;
create_og_image(numbers[2], &title.to_uppercase(), &description, MetaGov)
}
(Some(LilNouns), Some(LilCamp)) => {
let (title, description) = fetch_lil_nouns_data(&ctx.env, numbers[2]).await?;
create_og_image(numbers[2], &title.to_uppercase(), &description, Ethereum)
}
_ => String::new(),
};

Expand Down Expand Up @@ -283,6 +305,31 @@ pub async fn handle_creation<D>(
sqid: Some(sqids.encode(&*numbers).unwrap()),
})
}
Some("lilnouns.camp") | Some("www.lilnouns.camp") => {
numbers.push(LilNouns as u64);

let segments: Vec<_> = url
.path_segments()
.expect("Cannot get path segments")
.filter(|segment| !segment.is_empty())
.collect();

if segments.is_empty() || segments[0] != "proposals" {
return Response::error("Bad Request", 400);
}

if segments[0] == "proposals" {
numbers.push(LilCamp as u64);
numbers.push(segments[1].parse::<u32>().unwrap().try_into().unwrap());
} else {
return Response::error("Bad Request", 400);
}

Response::from_json(&UrlPayload {
url: url.into(),
sqid: Some(sqids.encode(&*numbers).unwrap()),
})
}
_ => Response::error("Bad Request", 400),
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub fn create_og_image(id: u64, title: &str, description: &str, platform: Platfo
Platform::Ethereum => "l_lil_noun_logo",
Platform::PropLot => "l_lil_noun_logo",
Platform::MetaGov => "l_lil_noun_logo",
Platform::LilCamp => "l_lil_noun_logo",
}
);
let foreground_color = format!(
Expand All @@ -73,6 +74,7 @@ pub fn create_og_image(id: u64, title: &str, description: &str, platform: Platfo
Platform::Ethereum => "FFFFFF",
Platform::PropLot => "000000",
Platform::MetaGov => "FFFFFF",
Platform::LilCamp => "FFFFFF",
}
);
let background_color = format!(
Expand All @@ -81,6 +83,7 @@ pub fn create_og_image(id: u64, title: &str, description: &str, platform: Platfo
Platform::Ethereum => "7DC4F2",
Platform::PropLot => "FFEF2E",
Platform::MetaGov => "F0C850",
Platform::LilCamp => "156636",
}
);

Expand Down

0 comments on commit 06eb85f

Please sign in to comment.