-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from victor-iyi/master
Minor changes and refactor
- Loading branch information
Showing
12 changed files
with
381 additions
and
452 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,48 @@ | ||
use actix_web::{http::StatusCode, web, App, HttpServer, HttpResponse}; | ||
//use actix_cors::Cors; | ||
use actix_web::{middleware::Logger}; | ||
use crate::types::MusicRequest; | ||
use crate::engines::mp3red; | ||
use crate::engines::freemp3cloud; | ||
use log::{error, debug}; | ||
use crate::engines::mp3red; | ||
use crate::types::MusicRequest; | ||
|
||
use actix_web::{http::StatusCode, web, App, HttpResponse, HttpServer}; | ||
//use actix_cors::Cors; | ||
use actix_web::middleware::Logger; | ||
use log::{debug, error}; | ||
|
||
async fn search(web::Query(info): web::Query<MusicRequest>) -> HttpResponse { | ||
debug!("Request for client with engine={} and query={}!", info.engine, info.query); | ||
let query = info.query.clone(); | ||
let engine = info.engine.clone(); | ||
let engine_match = engine.as_str(); | ||
match engine_match { | ||
"mp3red" => { | ||
let e = mp3red::MP3Red{}; | ||
let res = e.search(query).await.ok(); | ||
HttpResponse::Ok().json(res.unwrap()) | ||
}, | ||
"freemp3cloud" => { | ||
let e = freemp3cloud::FreeMP3Cloud{}; | ||
let res = e.search(query).await.ok(); | ||
HttpResponse::Ok().json(res.unwrap()) | ||
}, | ||
_ => { | ||
error!("Engine {} is unsupported", engine_match); | ||
HttpResponse::new(StatusCode::NOT_FOUND) | ||
}, | ||
debug!( | ||
"Request for client with engine={} and query={}!", | ||
info.engine, info.query | ||
); | ||
let query = info.query.clone(); | ||
let engine = info.engine.clone(); | ||
let engine_match = engine.as_str(); | ||
match engine_match { | ||
"mp3red" => { | ||
let e = mp3red::MP3Red {}; | ||
let res = e.search(query).await.ok(); | ||
HttpResponse::Ok().json(res.unwrap()) | ||
} | ||
"freemp3cloud" => { | ||
let e = freemp3cloud::FreeMP3Cloud {}; | ||
let res = e.search(query).await.ok(); | ||
HttpResponse::Ok().json(res.unwrap()) | ||
} | ||
_ => { | ||
error!("Engine {} is unsupported", engine_match); | ||
HttpResponse::new(StatusCode::NOT_FOUND) | ||
} | ||
} | ||
} | ||
|
||
pub async fn api(port: &str) -> std::io::Result<()> { | ||
let address: &str = &(format!("0.0.0.0:{}", port))[..]; | ||
HttpServer::new(|| | ||
App::new() | ||
.wrap(Logger::default()) | ||
.wrap(Logger::new("%a %{User-Agent}i")) | ||
.service( | ||
web::resource("/search") | ||
.route( | ||
web::get().to(search) | ||
) | ||
) | ||
) | ||
.bind(address) | ||
.unwrap() | ||
.run() | ||
.await | ||
HttpServer::new(|| { | ||
App::new() | ||
.wrap(Logger::default()) | ||
.wrap(Logger::new("%a %{User-Agent}i")) | ||
.service(web::resource("/search").route(web::get().to(search))) | ||
}) | ||
.bind(address) | ||
.unwrap() | ||
.run() | ||
.await | ||
} |
Oops, something went wrong.