A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
18
mut req: tide::Request<State>,19
next: tide::Next<'_, State>,20
) -> tide::Result {21
let path_url = req.url().path();22
if path_url.starts_with("/api") {23
match req.header("verbal-token") {24
Some(header) => {25
let token = header.as_str();26
let option_account;27
{28
let query = format!(29
"30
SELECT31
account.*,32
(33
SELECT34
sum(playtime)35
FROM get_playtime(account.id)36
)37
AS playtime38
FROM account39
INNER JOIN device40
ON account.id = device.account_id41
WHERE device.uid = '{}'42
",43
&token,44
);45
let mut conn = req.sqlx_conn::<Postgres>().await;46
option_account = unwrap_result_or_throw!(47
sqlx::query_as::<_, model::Account>(&query)48
.fetch_optional(unwrap_result_or_throw!(49
conn.acquire().await,50
"cannot acquire connection to database!"51
))52
.await,53
"cannot acquire account for given device!"54
);21
if req.method() != Method::Options {22
let path_url = req.url().path();23
if path_url.starts_with("/api") {24
match req.header("verbal-token") {25
Some(header) => {26
let token = header.as_str();27
let option_account;28
{29
let query = format!(30
"31
SELECT32
account.*,33
(34
SELECT35
sum(playtime)36
FROM get_playtime(account.id)37
)38
AS playtime39
FROM account40
INNER JOIN device41
ON account.id = device.account_id42
WHERE device.uid = '{}'43
",44
&token,45
);46
let mut conn = req.sqlx_conn::<Postgres>().await;47
option_account = unwrap_result_or_throw!(48
sqlx::query_as::<_, model::Account>(&query)49
.fetch_optional(unwrap_result_or_throw!(50
conn.acquire().await,51
"cannot acquire connection to database!"52
))53
.await,54
"cannot acquire account for given device!"55
);56
}57
req.set_ext(unwrap_option_or_throw!(58
option_account,59
"no account found for given token!"60
));61
}56
req.set_ext(unwrap_option_or_throw!(57
option_account,58
"no account found for given token!"59
));60
}61
None => {62
if !(path_url.eq("/api/account") && req.method() == Method::Post) {63
return Response::throw("no token was provided!");62
None => {63
if !(path_url.eq("/api/account") && req.method() == Method::Post) {64
return Response::throw("no token was provided!");65
}66
}67
}68
}