A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
10
const VERSION = '{{version}}';11
const SWIPE_THRESHOLD = 70;13
export const TOKEN_NAME = 'verbal-token';15
export const state = {16
app: null,17
tab: 'search',18
tabs: ['search', 'favorites', 'account'],19
account: null,20
devices: null,21
token: null,22
station: null,23
authenticated: false,24
open: false,
28
(async () => {29
state.locale = await http`get::/asset/json/locale.json`();30
new Vue({31
el: '#app',32
data: {
51
async init() {52
try {53
state.account = await http`get::/api/account`();54
state.devices = await http`get::/api/devices`();55
state.token = localStorage.getItem(TOKEN_NAME);56
}57
catch(error) {58
// ignore
1
import {$lang} from '../utils.js';1
import {$lang, http} from '../utils.js';2
import VTab from '../component/tab.js';4
export default {5
props: ['state'],6
data() {7
const {name, language} = this.state.account;8
return {9
name,10
language11
};12
},13
components: {14
VTab15
},16
methods: {10
$lang17
$lang,18
isCurrentDevice(device) {19
return device.uid === this.state.token;20
},21
async updateAccount(type, value) {22
const account = {...this.state.account};23
account[type] = value;24
try {25
this.state.account = await http`put::/api/account`(account);26
}27
catch(err) {28
this.state.app.showError(err);29
this.reset();30
}31
},32
reset() {33
const {name, language} = this.state.account;34
this.name = name;35
this.language = language;36
}37
},38
template: `39
<v-tab id="account" :tab="state.tab">14
<div class="pb-8 sm:pb-[100px] pt-2">15
<p class="text-md text-gray-400 text-center">Verbal</p>16
<p class="text-md text-gray-400 text-center">{{state.version}}</p>17
<p class="text-md text-gray-400 text-center pt-2">18
Created by19
<a class="text-gray-200 hover:underline font-bold" href="https://github.com/typable" target="_blank">@typable</a>20
</p>40
<div class="flex flex-col flex-1 gap-[32px] pb-8 sm:pb-[100px] pt-2">41
<div>42
<h3 class="text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('account.settings')}}</h3>43
<div class="flex flex-col gap-8">44
<div class="flex flex-col gap-2">45
<label for="username" class="text-white text-md">{{$lang('account.username')}}</label>46
<span class="text-gray-400 text-sm">{{$lang('account.username.info')}}</span>47
<input48
v-model="name"49
id="username"50
type="text"51
maxlength="20"52
spellcheck="false"53
autocomplete="off"54
@change="updateAccount('name', name)"55
class="rounded-md w-full h-[52px] px-4 mt-2 text-md bg-zinc-900 text-white placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none"56
>57
</div>58
<div class="flex flex-col gap-2">59
<label for="language" class="text-white text-md">{{$lang('account.language')}}</label>60
<span class="text-gray-400 text-sm">{{$lang('account.language.info')}}</span>61
<select62
v-model="language"63
id="language"64
autocomplete="off"65
@change="updateAccount('language', language)"66
class="rounded-md w-full h-[52px] px-4 mt-2 text-md bg-zinc-900 text-white placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none appearance-none"67
>68
<option value="en">English</option>69
<option value="de">Deutsch</option>70
</select>71
</div>72
</div>73
</div>74
<div v-if="state.devices">75
<h3 class="text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('account.devices')}}</h3>76
<ul class="flex flex-col gap-4">77
<li v-for="device in state.devices" class="w-full rounded-md bg-zinc-900 p-5 flex flex-col gap-1">78
<p class="text-md text-white flex justify-between items-center">79
{{device.name ?? $lang('account.devices.unknown')}}80
<span81
v-if="isCurrentDevice(device)"82
class="text-sm text-white px-[7px] bg-blue-600/70 rounded-[4px] h-[24px] leading-[24px]"83
>84
{{$lang('account.devices.current')}}85
</span>86
</p>87
<p class="text-sm text-gray-500">{{device.uid}}</p>88
</li>89
</ul>90
</div>91
<div>92
<p class="text-md text-gray-400 text-center">Verbal</p>93
<p class="text-md text-gray-400 text-center">{{state.version}}</p>94
<p class="text-md text-gray-400 text-center pt-2">95
Created by96
<a class="text-gray-200" href="https://github.com/typable" target="_blank">@typable</a>97
</p>98
</div>99
</div>100
</v-tab>101
`
111
@change="doSearch"112
class="w-full h-[56px] px-5 pl-11 text-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer appearance-none"113
>114
<option value="" selected>All</option>114
<option value="">{{$lang('search.input.all')}}</option>115
<option v-for="country in countries" :value="country">{{country}}</option>116
</select>117
</div>
127
@change="doSearch"128
class="w-full h-[56px] px-5 pl-11 text-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer appearance-none"129
>130
<option value="">All</option>130
<option value="">{{$lang('search.input.all')}}</option>131
<option v-for="language in languages" :value="language">{{language}}</option>132
</select>133
</div>
143
</li>144
</ul>145
<div v-else>146
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>146
<h3 class="text-white text-[24px] font-bold pb-6 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>147
<ul class="flex flex-col">148
<li149
:key="station.id"
1
import {state} from './main.js';1
import {state, TOKEN_NAME} from './main.js';3
const ltr = (parts, values) => {4
let string = '';
22
const headers = {23
'content-type': 'application/json',24
}25
const token = localStorage.getItem('verbal-token');25
const token = localStorage.getItem(TOKEN_NAME);26
if(token) {27
headers['verbal-token'] = token;28
}
43
CREATE TABLE device (44
id SERIAL PRIMARY KEY,45
uid TEXT UNIQUE NOT NULL,46
name TEXT,47
account_id INTEGER48
);
1
/* ### create a test user ### */3
INSERT INTO account (id, username) VALUES (1, 'Test User');3
INSERT INTO account (id, name) VALUES (1, 'Test User');4
INSERT INTO device (uid, account_id) VALUES ('test-token', 1);
17
pub struct Device {18
pub id: i32,19
pub uid: String,20
pub name: Option<String>,21
pub account_id: i32,22
}
86
}88
#[derive(Debug, Clone, Serialize, FromRow)]88
pub struct Country(pub String);90
#[derive(Debug, Clone, Serialize, FromRow)]91
pub struct Language(pub String);93
#[derive(Debug, Clone, Serialize, FromRow)]94
pub struct Tag(pub String);89
pub struct Value(pub String);
5
use tide_sqlx::SQLxRequestExt;7
use crate::model;8
use crate::model::Country;9
use crate::model::Language;10
use crate::model::Tag;8
use crate::unwrap_option_or_throw;9
use crate::unwrap_result_or_throw;10
use crate::Response;
211
"#212
.to_string();213
let mut conn = req.sqlx_conn::<Postgres>().await;217
let result = sqlx::query_as::<_, Country>(&sql)214
let result = sqlx::query_as::<_, model::Value>(&sql)215
.fetch_all(conn.acquire().await?)216
.await?;217
Response::with(result)
227
"#228
.to_string();229
let mut conn = req.sqlx_conn::<Postgres>().await;233
let result = sqlx::query_as::<_, Language>(&sql)230
let result = sqlx::query_as::<_, model::Value>(&sql)231
.fetch_all(conn.acquire().await?)232
.await?;233
Response::with(result)
244
"#245
.to_string();246
let mut conn = req.sqlx_conn::<Postgres>().await;250
let result = sqlx::query_as::<_, Tag>(&sql)247
let result = sqlx::query_as::<_, model::Value>(&sql)248
.fetch_all(conn.acquire().await?)249
.await?;250
Response::with(result)251
}253
pub async fn get_devices(req: tide::Request<()>) -> tide::Result {254
let account =255
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");256
let sql = format!(257
r#"258
SELECT259
device.*260
FROM device261
WHERE device.account_id = {account_id}262
"#,263
account_id = account.id,264
);265
let mut conn = req.sqlx_conn::<Postgres>().await;266
let result = sqlx::query_as::<_, model::Device>(&sql)267
.fetch_all(conn.acquire().await?)268
.await?;269
Response::with(result)270
}272
pub async fn update_account(mut req: tide::Request<()>) -> tide::Result {273
let updated_account = req.body_json::<model::Account>().await?;274
let account =275
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");276
let sql = format!(277
r#"278
UPDATE279
account280
SET281
name = '{name}',282
language = '{language}'283
WHERE account.id = {account_id}284
RETURNING *285
"#,286
account_id = account.id,287
name = updated_account.name.unwrap_or_default(),288
language = updated_account.language,289
);290
let mut conn = req.sqlx_conn::<Postgres>().await;291
let result = sqlx::query_as::<_, model::Account>(&sql)292
.fetch_one(conn.acquire().await?)293
.await?;294
Response::with(result)295
}
50
/* handle api requests */51
app.at("/api/account").get(route::get_account);52
app.at("/api/account").put(route::update_account);53
app.at("/api/search").get(route::do_search);54
app.at("/api/song").get(route::get_song);55
app.at("/api/favorite").get(route::get_favorites);
59
app.at("/api/countries").get(route::get_countries);60
app.at("/api/languages").get(route::get_languages);61
app.at("/api/tags").get(route::get_tags);62
app.at("/api/devices").get(route::get_devices);64
let address =65
unwrap_result_or_abort!(config.server.to_url(), "cannot parse server address!");
24
"global.welcome": "Welcome",25
"player.loading": "Loading...",26
"player.no-song-title": "- No song title available -",27
"search.input.all": "All",28
"search.input.placeholder": "Search for stations",29
"search.list.end": "You've reached the end",30
"search.list.empty": "No results found",
37
"account.player": "Player",38
"account.playback-history": "Show Playback History",39
"account.playback-history.info": "Displays the recently played songs for the current station",39
"account.devices": "Devices"40
"account.devices": "Linked devices",41
"account.devices.unknown": "Unknown device",42
"account.devices.current": "Current"43
},44
"de": {45
"global.none": "-",
66
"global.welcome": "Willkommen",67
"player.loading": "Laden...",68
"player.no-song-title": "- Song Titel nicht verfügbar -",69
"search.input.all": "Alle",70
"search.input.placeholder": "Suche nach Sender",71
"search.list.end": "Du hast das Ende erreicht",72
"search.list.empty": "Keine Ergebnisse gefunden",
79
"account.player": "Wiedergabe",80
"account.playback-history": "Wiedergabeverlauf anzeigen",81
"account.playback-history.info": "Zeigt die zuletzt gespielten Songs für den aktuellen Sender an",78
"account.devices": "Geräte"82
"account.devices": "Verbundene Geräte",83
"account.devices.unknown": "Unbekanntes Gerät",84
"account.devices.current": "Aktuelles"85
}86
}