Skip to content

Commit bb7e4a1

Browse files
committed
sentry - lib - move POST events route and remove .* from Regex
1 parent e0aeee2 commit bb7e4a1

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

sentry/src/lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ lazy_static! {
6060
static ref ANALYTICS_BY_CHANNEL_ID: Regex = Regex::new(r"^/analytics/0x([a-zA-Z0-9]{64})/?$").expect("The regex should be valid");
6161
static ref ADVERTISER_ANALYTICS_BY_CHANNEL_ID: Regex = Regex::new(r"^/analytics/for-advertiser/0x([a-zA-Z0-9]{64})/?$").expect("The regex should be valid");
6262
static ref PUBLISHER_ANALYTICS_BY_CHANNEL_ID: Regex = Regex::new(r"^/analytics/for-publisher/0x([a-zA-Z0-9]{64})/?$").expect("The regex should be valid");
63-
static ref CREATE_EVENTS_BY_CHANNEL_ID: Regex = Regex::new(r"^/channel/0x([a-zA-Z0-9]{64})/events(/.*)?$").expect("The regex should be valid");
64-
63+
static ref CREATE_EVENTS_BY_CHANNEL_ID: Regex = Regex::new(r"^/channel/0x([a-zA-Z0-9]{64})/events/?$").expect("The regex should be valid");
6564
}
6665

6766
fn auth_required_middleware<'a, A: Adapter>(
@@ -255,7 +254,16 @@ async fn channels_router<A: Adapter + 'static>(
255254
// example with
256255
// @TODO remove later
257256
// regex matching for routes with params
258-
if let (Some(caps), &Method::GET) = (LAST_APPROVED_BY_CHANNEL_ID.captures(&path), method) {
257+
if let (Some(caps), &Method::POST) = (CREATE_EVENTS_BY_CHANNEL_ID.captures(&path), method) {
258+
let param = RouteParams(vec![caps
259+
.get(1)
260+
.map_or("".to_string(), |m| m.as_str().to_string())]);
261+
262+
req.extensions_mut().insert(param);
263+
264+
insert_events(req, app).await
265+
} else if let (Some(caps), &Method::GET) = (LAST_APPROVED_BY_CHANNEL_ID.captures(&path), method)
266+
{
259267
let param = RouteParams(vec![caps
260268
.get(1)
261269
.map_or("".to_string(), |m| m.as_str().to_string())]);
@@ -334,16 +342,6 @@ async fn channels_router<A: Adapter + 'static>(
334342
let req = chain(req, app, vec![Box::new(channel_load)]).await?;
335343

336344
list_channel_event_aggregates(req, app).await
337-
} else if let (Some(caps), &Method::POST) =
338-
(CREATE_EVENTS_BY_CHANNEL_ID.captures(&path), method)
339-
{
340-
let param = RouteParams(vec![caps
341-
.get(1)
342-
.map_or("".to_string(), |m| m.as_str().to_string())]);
343-
344-
req.extensions_mut().insert(param);
345-
346-
insert_events(req, app).await
347345
} else {
348346
Err(ResponseError::NotFound)
349347
}

0 commit comments

Comments
 (0)