A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
61
},62
async loadRecommended() {63
for(const id of this.popular) {64
this.recommended.push(await http`get::/api/station`(id));64
this.recommended.push(await http`get::/api/station/${id}`());65
}66
},67
async loadFilters() {
84
}85
}87
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]88
pub struct Id(pub i32);90
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]87
#[derive(Debug, Clone, Serialize, FromRow)]88
pub struct Country(pub String);93
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]90
#[derive(Debug, Clone, Serialize, FromRow)]91
pub struct Language(pub String);96
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]93
#[derive(Debug, Clone, Serialize, FromRow)]94
pub struct Tag(pub String);
7
use crate::model;8
use crate::model::Country;9
use crate::model::Id;9
use crate::model::Language;10
use crate::model::Tag;11
use crate::unwrap_option_or_throw;
169
}171
pub async fn get_station(req: tide::Request<()>) -> tide::Result {173
let station_id = req.query::<Id>()?;172
let station_id = unwrap_result_or_throw!(req.param("id"), "no station id found!");173
let account =174
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");175
let sql = format!(
194
AND station_status.is_hidden IS NOT true195
"#,196
account_id = account.id,198
station_id = station_id.0,197
station_id = station_id,198
);199
let mut conn = req.sqlx_conn::<Postgres>().await;200
let result = sqlx::query_as::<_, model::Station>(&sql)
204
}206
pub async fn get_countries(req: tide::Request<()>) -> tide::Result {208
let sql = format!(209
r#"207
let sql = r#"208
SELECT209
country210
FROM station211
WHERE country != ''212
GROUP BY country213
ORDER BY COUNT(*) DESC;216
"#,217
);214
"#215
.to_string();216
let mut conn = req.sqlx_conn::<Postgres>().await;217
let result = sqlx::query_as::<_, Country>(&sql)218
.fetch_all(conn.acquire().await?)
221
}223
pub async fn get_languages(req: tide::Request<()>) -> tide::Result {226
let sql = format!(227
r#"224
let sql = r#"225
SELECT226
UNNEST(languages) AS language227
FROM station228
GROUP BY UNNEST(languages)229
ORDER BY COUNT(*) DESC;233
"#,234
);230
"#231
.to_string();232
let mut conn = req.sqlx_conn::<Postgres>().await;233
let result = sqlx::query_as::<_, Language>(&sql)234
.fetch_all(conn.acquire().await?)
237
}239
pub async fn get_tags(req: tide::Request<()>) -> tide::Result {243
let sql = format!(244
r#"240
let sql = r#"241
SELECT242
UNNEST(tags) AS tag243
FROM station244
GROUP BY UNNEST(tags)245
ORDER BY COUNT(*) DESC;250
"#,251
);246
"#247
.to_string();248
let mut conn = req.sqlx_conn::<Postgres>().await;249
let result = sqlx::query_as::<_, Tag>(&sql)250
.fetch_all(conn.acquire().await?)
53
app.at("/api/favorite").get(route::get_favorites);54
app.at("/api/favorite").post(route::add_favorite);55
app.at("/api/favorite").delete(route::delete_favorite);56
app.at("/api/station").get(route::get_station);56
app.at("/api/station/:id").get(route::get_station);57
app.at("/api/countries").get(route::get_countries);58
app.at("/api/languages").get(route::get_languages);59
app.at("/api/tags").get(route::get_tags);61
let address =62
unwrap_result_or_abort!(config.server.to_url(), "cannot parse server address!");63
info!("starting server on {}", address);63
info!("starting server on http://{}", address);64
let listener = if config.server.is_tls() {65
app.listen(66
TlsListener::build()