A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
19
more: true,20
countries: [],21
languages: [],22
recommended: [],23
popular: [24
45761,25
44366,26
37156,27
33977,28
56254,29
3061530
]22
playtime: null,23
latest: null,24
};25
},26
components: {
52
}53
this.results.push(...result);54
},62
async loadRecommended() {63
for(const id of this.popular) {64
this.recommended.push(await http`get::/api/station/${id}`());65
}55
async loadCategories() {56
this.playtime = await http`get::/api/category/playtime`();57
this.latest = await http`get::/api/category/latest`();58
},59
async loadFilters() {60
this.countries = await http`get::/api/countries`();
68
};69
this.searching = false;70
this.results = [];79
this.loadRecommended();71
this.loadCategories();72
}73
},74
mounted() {83
this.loadRecommended();75
this.loadCategories();76
this.loadFilters();77
},78
template: `
135
</li>136
</ul>137
<div v-else>146
<h3 class="text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>138
<h3 class="text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.latest')}}</h3>139
<ul class="flex flex-col">140
<li141
:key="station.id"142
v-for="station in latest"143
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"144
>145
<v-station :station="station"></v-station>146
</li>147
</ul>148
<h3 class="mt-[32px] text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.playtime')}}</h3>149
<ul class="flex flex-col">150
<li151
:key="station.id"150
v-for="station in recommended"152
v-for="station in playtime"153
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"154
>155
<v-station :station="station"></v-station>
84
fn to_url(&self) -> Result<String>;85
}87
pub enum Category {88
Playtime,89
Latest,90
}92
impl Category {93
pub fn from(kind: &str) -> Result<Self> {94
match kind {95
"playtime" => Ok(Self::Playtime),96
"latest" => Ok(Self::Latest),97
_ => Err(Error::new("not a valid category!")),98
}99
}100
}102
impl ToSql for Category {103
fn to_sql(&self) -> Result<String> {104
Ok(match self {105
Self::Playtime => "AND station_stats.playtime > 0 ORDER BY station_stats.playtime DESC",106
Self::Latest => "AND station_stats.playtime > 0 ORDER BY station_stats.latest_at DESC",107
}108
.to_string())109
}110
}112
pub fn init_logger() {113
Builder::new()114
.format_timestamp_secs()
8
use crate::model;9
use crate::unwrap_option_or_throw;10
use crate::unwrap_result_or_throw;11
use crate::Category;12
use crate::Response;13
use crate::ToSql;
275
}277
pub async fn get_group(req: tide::Request<()>) -> tide::Result {277
let group_id = unwrap_result_or_throw!(req.param("id"), "no group id found!");278
let group_id = unwrap_result_or_throw!(req.param("id"), "no group id was provided!");279
let account =280
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");281
let mut conn = req.sqlx_conn::<Postgres>().await;
335
Response::with(result)336
}338
pub async fn get_category(req: tide::Request<()>) -> tide::Result {339
let kind = unwrap_result_or_throw!(req.param("kind"), "no kind was provided!");340
let account =341
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");342
let category = unwrap_result_or_throw!(Category::from(kind), "invalid category provided!");343
let mut conn = req.sqlx_conn::<Postgres>().await;344
let sql = format!(345
r#"346
SELECT347
station.*,348
station_status.is_icon,349
CASE350
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}351
THEN false352
ELSE true353
END AS is_favorite354
FROM station355
LEFT JOIN favorite356
ON station.id = favorite.station_id357
LEFT JOIN station_status358
ON station.id = station_status.station_id359
LEFT JOIN station_stats360
ON station.id = station_stats.station_id361
AND station_stats.account_id = {account_id}362
WHERE station_status.is_hidden IS NOT true363
{category}364
LIMIT 5365
"#,366
account_id = account.id,367
category = unwrap_result_or_throw!(category.to_sql(), "cannot parse sql statement!"),368
);369
let result = sqlx::query_as::<_, model::Station>(&sql)370
.fetch_all(conn.acquire().await?)371
.await?;372
Response::with(result)373
}375
pub async fn get_countries(req: tide::Request<()>) -> tide::Result {376
let sql = r#"377
SELECT
58
app.at("/api/favorite").post(route::add_favorite);59
app.at("/api/favorite").delete(route::delete_favorite);60
app.at("/api/station/:id").get(route::get_station);61
app.at("/api/category/:kind").get(route::get_category);62
app.at("/api/group/:id").get(route::get_group);63
app.at("/api/countries").get(route::get_countries);64
app.at("/api/languages").get(route::get_languages);
32
"search.list.end": "You've reached the end",33
"search.list.empty": "No results found",34
"search.recommended": "Recommended",35
"search.latest": "Recently played",36
"search.playtime": "Your top stations",37
"account.settings": "Settings",38
"account.username": "Username",39
"account.username.info": "This is your primary account name which is visible to everyone",
83
"search.list.end": "Du hast das Ende erreicht",84
"search.list.empty": "Keine Ergebnisse gefunden",85
"search.recommended": "Empfohlen",86
"search.latest": "Zuletzt gespielt",87
"search.playtime": "Deine Lieblingssender",88
"account.settings": "Einstellungen",89
"account.username": "Nutzername",90
"account.username.info": "Dies ist Ihr primärer Kontoname, der von allen gesehen werden kann",