|
| 1 | +use std::sync::Arc; |
| 2 | + |
1 | 3 | use adex_primitives::{
|
2 | 4 | supermarket::units_for_slot,
|
3 | 5 | targeting::{input::Global, Input},
|
@@ -32,11 +34,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
32 | 34 |
|
33 | 35 | info!("Tera templates glob path: {templates_glob}");
|
34 | 36 | // Use globbing
|
35 |
| - let tera = Tera::new(&templates_glob)?; |
| 37 | + let tera = Arc::new(Tera::new(&templates_glob)?); |
36 | 38 |
|
37 | 39 | // `GET /ad`
|
| 40 | + let ad_tera = tera.clone(); |
38 | 41 | let get_ad = warp::get().and(warp::path("ad")).then(move || {
|
39 |
| - let tera = tera.clone(); |
| 42 | + let tera = ad_tera.clone(); |
40 | 43 |
|
41 | 44 | async move {
|
42 | 45 | // let logger = logger.clone();
|
@@ -147,7 +150,68 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
147 | 150 | }
|
148 | 151 | });
|
149 | 152 |
|
150 |
| - warp::serve(get_ad).run(([127, 0, 0, 1], 3030)).await; |
| 153 | + // GET /preview/video |
| 154 | + let get_preview_of_video = warp::get().and(warp::path!("preview" / "video" )).then(move || { |
| 155 | + let tera = tera.clone(); |
| 156 | + |
| 157 | + async move { |
| 158 | + let whitelisted_tokens = vec!["0x6B175474E89094C44Da98b954EedeAC495271d0F" |
| 159 | + .parse() |
| 160 | + .expect("Valid token Address")]; |
| 161 | + let disabled_video = false; |
| 162 | + let publisher_addr = "0x0000000000000000626f62627973686d75726461" |
| 163 | + .parse() |
| 164 | + .unwrap(); |
| 165 | + |
| 166 | + let options = Options { |
| 167 | + market_url: "http://placeholder.com".parse().unwrap(), |
| 168 | + market_slot: DUMMY_IPFS[0], |
| 169 | + publisher_addr, |
| 170 | + // All passed tokens must be of the same price and decimals, so that the amounts can be accurately compared |
| 171 | + whitelisted_tokens, |
| 172 | + size: Some(Size::new(728, 90)), |
| 173 | + // TODO: Check this value |
| 174 | + navigator_language: Some("bg".into()), |
| 175 | + /// Defaulted |
| 176 | + disabled_video, |
| 177 | + disabled_sticky: false, |
| 178 | + }; |
| 179 | + |
| 180 | + // legacy_728x90 |
| 181 | + let video_ad_unit = adex_primitives::supermarket::units_for_slot::response::AdUnit { |
| 182 | + /// Same as `ipfs` |
| 183 | + id: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh" |
| 184 | + .parse() |
| 185 | + .expect("Valid IPFS"), |
| 186 | + media_url: "ipfs://Qmevmms1AZgYXS27A9ghSjHn4DSaHMfgYcD2SoGW14RYGy".to_string(), |
| 187 | + media_mime: "video/mp4".to_string(), |
| 188 | + target_url: "https://www.stremio.com/downloads".to_string(), |
| 189 | + }; |
| 190 | + |
| 191 | + let video_html = get_unit_html_with_events( |
| 192 | + &options, |
| 193 | + &video_ad_unit, |
| 194 | + "localhost", |
| 195 | + DUMMY_CAMPAIGN.id, |
| 196 | + &DUMMY_CAMPAIGN.validators, |
| 197 | + false, |
| 198 | + ); |
| 199 | + |
| 200 | + // let video_html = get_unit_html_with_events(&options, ); |
| 201 | + let html = { |
| 202 | + let mut context = Context::new(); |
| 203 | + context.insert("ad_code", &video_html); |
| 204 | + |
| 205 | + tera.render("ad.html", &context).expect("Should render") |
| 206 | + }; |
| 207 | + |
| 208 | + warp::reply::html(html) |
| 209 | + } |
| 210 | + }); |
| 211 | + |
| 212 | + warp::serve(get_ad.or(get_preview_of_video)) |
| 213 | + .run(([127, 0, 0, 1], 3030)) |
| 214 | + .await; |
151 | 215 |
|
152 | 216 | Ok(())
|
153 | 217 | }
|
0 commit comments