Skip to content

Commit d5199e6

Browse files
authored
Merge pull request #481 from AmbireTech/adview-manager-preview-a-video-ad
AdView manager preview for a video ad
2 parents 304984b + 8057441 commit d5199e6

File tree

5 files changed

+88
-21
lines changed

5 files changed

+88
-21
lines changed

Cargo.lock

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ members = [
44
"primitives",
55
"adapter",
66
"adview-manager",
7-
# Server for testing adview manager generated code
7+
# `adview-serve` binary - Servers for testing adview manager generated code
88
"adview-manager/serve",
99
"validator_worker",
1010
"sentry",

adview-manager/serve/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["Ambire <[email protected]>", "Lachezar Lechev <[email protected]>"]
33
edition = "2021"
4-
name = "serve"
4+
name = "adview-serve"
55
version = "0.1.0"
66
license = "AGPL-3.0"
77
publish = false

adview-manager/serve/src/main.rs

+67-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use adex_primitives::{
24
supermarket::units_for_slot,
35
targeting::{input::Global, Input},
@@ -32,11 +34,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3234

3335
info!("Tera templates glob path: {templates_glob}");
3436
// Use globbing
35-
let tera = Tera::new(&templates_glob)?;
37+
let tera = Arc::new(Tera::new(&templates_glob)?);
3638

3739
// `GET /ad`
40+
let ad_tera = tera.clone();
3841
let get_ad = warp::get().and(warp::path("ad")).then(move || {
39-
let tera = tera.clone();
42+
let tera = ad_tera.clone();
4043

4144
async move {
4245
// let logger = logger.clone();
@@ -147,7 +150,68 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
147150
}
148151
});
149152

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;
151215

152216
Ok(())
153217
}

adview-manager/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ fn get_unit_html(
196196
</div>", style=max_min_size, adex_icon=adex_icon())
197197
}
198198

199+
/// no_impression - whether or not an IMPRESSION event should be sent with `onload`
200+
///
201+
/// [`WAIT_FOR_IMPRESSION`] - The timeout used before sending the IMPRESSION event to all validators
199202
pub fn get_unit_html_with_events(
200203
options: &Options,
201204
ad_unit: &AdUnit,

0 commit comments

Comments
 (0)