A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
8
import VAccount from './page/account.js';9
import VNotfound from './page/notfound.js';10
import VAuth from './page/auth.js';11
import VProfile from './page/profile.js';12
import VDetail from './component/detail.js';14
export const VERSION = '{{version}}';
22
'^\/account$': 'account',23
'^\/station\/(\\d+)$': 'detail',24
'^@not-found$': 'not-found',24
'^\/auth$': 'auth'25
'^\/auth$': 'auth',26
'^\/profile$': 'profile',27
'^\/profile/(\\d+)$': 'profile'28
};30
export const state = reactive({
57
VAuth,58
VPlayer,59
VPopup,57
VDetail60
VDetail,61
VProfile62
},63
mounted() {64
document.body.style.display = '';
159
<v-search ref="search" :state="state"></v-search>160
<v-favorites ref="favorites" :state="state"></v-favorites>161
<v-account :state="state"></v-account>162
<v-profile ref="profile" :state="state"></v-profile>163
</div>164
<v-player ref="player" :station="state.station"></v-player>165
<v-detail ref="detail"></v-detail>
1
import {$lang, $route, http, duration} from '../utils.js';2
import VTab from '../component/tab.js';3
import VButton from '../element/button.js';4
import VIcon from '../element/icon.js';6
export default {7
props: ['state'],8
data() {9
return {10
account: null11
};12
},13
components: {14
VTab,15
VButton,16
VIcon17
},18
methods: {19
$lang,20
$route,21
duration,22
async show(id) {23
this.account = await http`get::/api/account/${id}`();24
if(this.account === null) {25
$route('@not-found', { update: false });26
return;27
}28
}29
},30
mounted() {31
const path = window.location.pathname;32
if(/^\/profile$/.test(path)) {33
this.show(this.state.account.id);34
return;35
}36
const match = /^\/profile\/(\d+)$/.exec(path);37
if(match) {38
const id = match[1];39
this.show(id);40
}41
},42
template: `43
<v-tab id="profile" :tab="state.tab">44
<div v-if="account" class="flex flex-col flex-1 gap-[32px] pb-8 sm:pb-[100px] pt-2">45
<p46
class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"47
>48
{{account.name}}49
</p>50
<span class="text-md text-gray-400 overflow-hidden flex flex-wrap gap-x-3 gap-y-1 pt-1">51
<span52
v-if="account.playtime && duration(account.playtime ?? 0).length > 0"53
class="text-gray-400 inline-flex items-center gap-[5px]"54
:title="$lang('detail.playtime')"55
>56
<v-icon57
id="clock"58
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"59
size="100%"60
></v-icon>61
<p>{{duration(account.playtime ?? 0)}}</p>62
</span>63
</span>64
</div>65
</v-tab>66
`67
}
93
state.app.$refs.detail.show({ id: match[1] });94
}95
}96
if(value === 'profile') {97
if(state.app.$refs.profile) {98
state.app.$refs.profile.show(match[1] ?? state.account.id);99
}100
}101
}102
if(update) {103
window.history.pushState(null, null, path);
243
Response::with(())244
}246
pub async fn get_station(req: tide::Request<()>) -> tide::Result {246
pub async fn get_account_by_id(req: tide::Request<()>) -> tide::Result {247
let account_id = unwrap_result_or_throw!(req.param("id"), "no account id found!");248
let sql = format!(249
r#"250
SELECT251
account.*,252
(253
SELECT254
sum(playtime)255
FROM get_playtime(account.id)256
)257
AS playtime258
FROM account259
WHERE account.id = {account_id}260
"#,261
account_id = account_id,262
);263
let mut conn = req.sqlx_conn::<Postgres>().await;264
let result = sqlx::query_as::<_, model::Account>(&sql)265
.fetch_optional(conn.acquire().await?)266
.await?;267
Response::with(result)268
}270
pub async fn get_station_by_id(req: tide::Request<()>) -> tide::Result {271
let station_id = unwrap_result_or_throw!(req.param("id"), "no station id found!");272
let account =273
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");
58
app.at("/api/favorite").get(route::get_favorites);59
app.at("/api/favorite").post(route::add_favorite);60
app.at("/api/favorite").delete(route::delete_favorite);61
app.at("/api/station/:id").get(route::get_station);61
app.at("/api/account/:id").get(route::get_account_by_id);62
app.at("/api/station/:id").get(route::get_station_by_id);63
app.at("/api/category/:kind").get(route::get_category);64
app.at("/api/group/:id").get(route::get_group);65
app.at("/api/countries").get(route::get_countries);