mirror of
https://github.com/agersant/polaris
synced 2024-11-10 10:14:12 +00:00
Last FM auth API now returns HTML content supplied by caller
This commit is contained in:
parent
cd40ce374e
commit
3fba584671
5 changed files with 24 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1392,6 +1392,7 @@ version = "0.7.1"
|
|||
dependencies = [
|
||||
"ape 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel_migrations 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -9,6 +9,7 @@ ui = []
|
|||
[dependencies]
|
||||
ape = "0.2.0"
|
||||
app_dirs = "1.1.1"
|
||||
base64 = "0.9.3"
|
||||
diesel = { version = "1.3.3", features = ["sqlite"] }
|
||||
diesel_migrations = { version = "1.3.0", features = ["sqlite"] }
|
||||
error-chain = "0.12.0"
|
||||
|
|
21
src/api.rs
21
src/api.rs
|
@ -1,5 +1,7 @@
|
|||
use base64;
|
||||
use diesel::prelude::*;
|
||||
use iron::headers::{Authorization, Basic, Range};
|
||||
use iron::mime::Mime;
|
||||
use iron::prelude::*;
|
||||
use iron::{status, AroundMiddleware, Handler};
|
||||
use mount::Mount;
|
||||
|
@ -726,7 +728,24 @@ fn lastfm_auth(request: &mut Request, db: &DB) -> IronResult<Response> {
|
|||
|
||||
lastfm::auth(db, &username, &token)?;
|
||||
|
||||
Ok(Response::with(status::Ok))
|
||||
let url_encoded_content = match input.find(&["content"]) {
|
||||
Some(¶ms::Value::String(ref content)) => content.clone(),
|
||||
_ => return Err(Error::from(ErrorKind::MissingDesiredResponse).into()),
|
||||
};
|
||||
|
||||
let base64_content = match percent_decode(url_encoded_content.as_bytes()).decode_utf8() {
|
||||
Ok(s) => s,
|
||||
Err(_) => return Err(Error::from(ErrorKind::EncodingError).into()),
|
||||
};
|
||||
|
||||
let popup_content = match base64::decode(base64_content.as_bytes()) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return Err(Error::from(ErrorKind::EncodingError).into()),
|
||||
};
|
||||
|
||||
let mime = "text/html".parse::<Mime>().unwrap();
|
||||
|
||||
Ok(Response::with((mime, status::Ok, popup_content)))
|
||||
}
|
||||
|
||||
fn lastfm_now_playing(request: &mut Request, db: &DB) -> IronResult<Response> {
|
||||
|
|
|
@ -56,6 +56,7 @@ error_chain! {
|
|||
MissingLastFMCredentials {}
|
||||
LastFMAuthError {}
|
||||
LastFMDeserializationError {}
|
||||
MissingDesiredResponse {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
extern crate ape;
|
||||
extern crate app_dirs;
|
||||
extern crate base64;
|
||||
extern crate core;
|
||||
extern crate crypto;
|
||||
#[macro_use]
|
||||
|
|
Loading…
Reference in a new issue