A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
71
ADD CONSTRAINT favorite_station_id72
FOREIGN KEY (station_id)73
REFERENCES station(id);75
CREATE TABLE station_stats (76
id SERIAL PRIMARY KEY,77
account_id INTEGER,78
station_id INTEGER,79
playtime INTEGER DEFAULT 080
);82
ALTER TABLE station_stats83
ADD CONSTRAINT station_stats_unique84
UNIQUE(account_id, station_id);86
ALTER TABLE station_stats87
ADD CONSTRAINT station_stats_account_id88
FOREIGN KEY (account_id)89
REFERENCES account(id);91
ALTER TABLE station_stats92
ADD CONSTRAINT station_stats_station_id93
FOREIGN KEY (station_id)94
REFERENCES station(id);
60
}62
pub async fn get_song(req: tide::Request<()>) -> tide::Result {63
let account =64
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");65
let station = req.query::<model::Station>()?;66
let mut response = surf::get(&station.url).header("icy-metadata", "1").await?;67
let meta_int = match response.header("icy-metaint") {
97
}98
total += len;99
}100
let sql = format!(101
r#"102
INSERT INTO103
station_stats104
(account_id, station_id, playtime)105
VALUES106
({account_id}, {station_id}, 1)107
ON CONFLICT (account_id, station_id)108
DO UPDATE109
SET playtime = station_stats.playtime + EXCLUDED.playtime;110
"#,111
account_id = account.id,112
station_id = station.id,113
);114
let mut conn = req.sqlx_conn::<Postgres>().await;115
sqlx::query(&sql).execute(conn.acquire().await?).await?;116
Response::with(title)117
}