-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better tasking less locks #318
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
xml, | ||
}; | ||
use crate::video_stream::types::VideoAndStreamInformation; | ||
use actix_web::http::header; | ||
Check warning on line 11 in src/server/pages.rs GitHub Actions / build (ubuntu-22.04, x86_64-unknown-linux-gnu, linux-desktop)
|
||
use actix_web::{ | ||
web::{self, Json}, | ||
HttpRequest, HttpResponse, | ||
|
@@ -70,7 +70,7 @@ | |
|
||
#[derive(Apiv2Schema, Debug, Deserialize, Validate)] | ||
pub struct ThumbnailFileRequest { | ||
source: String, | ||
Check warning on line 73 in src/server/pages.rs GitHub Actions / build (ubuntu-22.04, x86_64-unknown-linux-gnu, linux-desktop)
|
||
/// The Quality level (a percentage value as an integer between 1 and 100) is inversely proportional to JPEG compression level, which means the higher, the best. | ||
#[validate(range(min = 1, max = 100))] | ||
quality: Option<u8>, | ||
|
@@ -232,7 +232,7 @@ | |
pub async fn reset_settings(query: web::Query<ResetSettings>) -> HttpResponse { | ||
if query.all.unwrap_or_default() { | ||
settings::manager::reset(); | ||
if let Err(error) = stream_manager::start_default() { | ||
if let Err(error) = stream_manager::start_default().await { | ||
return HttpResponse::InternalServerError() | ||
.content_type("text/plain") | ||
.body(format!("{error:#?}")); | ||
|
@@ -269,7 +269,7 @@ | |
|
||
#[api_v2_operation] | ||
/// Create a video stream | ||
pub fn streams_post(json: web::Json<PostStream>) -> HttpResponse { | ||
pub async fn streams_post(json: web::Json<PostStream>) -> HttpResponse { | ||
let json = json.into_inner(); | ||
|
||
let video_source = match video_source::get_video_source(&json.source) { | ||
|
@@ -285,7 +285,9 @@ | |
name: json.name, | ||
stream_information: json.stream_information, | ||
video_source, | ||
}) { | ||
}) | ||
.await | ||
{ | ||
return HttpResponse::NotAcceptable() | ||
.content_type("text/plain") | ||
.body(format!("{error:#?}")); | ||
|
@@ -424,41 +426,41 @@ | |
} | ||
} | ||
|
||
#[api_v2_operation] | ||
/// Provides a thumbnail file of the given source | ||
pub async fn thumbnail(thumbnail_file_request: web::Query<ThumbnailFileRequest>) -> HttpResponse { | ||
// Ideally, we should be using `actix_web_validator::Query` instead of `web::Query`, | ||
// but because paperclip (at least until 0.8) is using `actix-web-validator 3.x`, | ||
// and `validator 0.14`, the newest api needed to use it along #[api_v2_operation] | ||
// wasn't implemented yet, it doesn't compile. | ||
// To workaround this, we are manually calling the validator here, using actix to | ||
// automatically handle the validation error for us as it normally would. | ||
// TODO: update this function to use `actix_web_validator::Query` directly and get | ||
// rid of this workaround. | ||
if let Err(errors) = thumbnail_file_request.validate() { | ||
warn!("Failed validating ThumbnailFileRequest. Reason: {errors:?}"); | ||
return actix_web::ResponseError::error_response(&actix_web_validator::Error::from(errors)); | ||
} | ||
|
||
let source = thumbnail_file_request.source.clone(); | ||
let quality = thumbnail_file_request.quality.unwrap_or(70u8); | ||
let target_height = thumbnail_file_request.target_height.map(|v| v as u32); | ||
|
||
match stream_manager::get_jpeg_thumbnail_from_source(source, quality, target_height).await { | ||
Some(Ok(image)) => HttpResponse::Ok().content_type("image/jpeg").body(image), | ||
None => HttpResponse::NotFound() | ||
.content_type("text/plain") | ||
.body(format!( | ||
"Thumbnail not found for source {:?}.", | ||
thumbnail_file_request.source | ||
)), | ||
Some(Err(error)) => HttpResponse::ServiceUnavailable() | ||
.reason("Thumbnail temporarily unavailable") | ||
.insert_header((header::RETRY_AFTER, 10)) | ||
.content_type("text/plain") | ||
.body(format!( | ||
"Thumbnail for source {:?} is temporarily unavailable. Try again later. Details: {error:?}", | ||
thumbnail_file_request.source | ||
)), | ||
} | ||
} | ||
// #[api_v2_operation] | ||
// /// Provides a thumbnail file of the given source | ||
// pub async fn thumbnail(thumbnail_file_request: web::Query<ThumbnailFileRequest>) -> HttpResponse { | ||
// Ideally, we should be using `actix_web_validator::Query` instead of `web::Query`, | ||
// but because paperclip (at least until 0.8) is using `actix-web-validator 3.x`, | ||
// and `validator 0.14`, the newest api needed to use it along #[api_v2_operation] | ||
// wasn't implemented yet, it doesn't compile. | ||
// To workaround this, we are manually calling the validator here, using actix to | ||
// automatically handle the validation error for us as it normally would. | ||
// TODO: update this function to use `actix_web_validator::Query` directly and get | ||
// rid of this workaround. | ||
// if let Err(errors) = thumbnail_file_request.validate() { | ||
// warn!("Failed validating ThumbnailFileRequest. Reason: {errors:?}"); | ||
// return actix_web::ResponseError::error_response(&actix_web_validator::Error::from(errors)); | ||
// } | ||
|
||
// let source = thumbnail_file_request.source.clone(); | ||
// let quality = thumbnail_file_request.quality.unwrap_or(70u8); | ||
// let target_height = thumbnail_file_request.target_height.map(|v| v as u32); | ||
|
||
// match stream_manager::get_jpeg_thumbnail_from_source(source, quality, target_height).await { | ||
// Some(Ok(image)) => HttpResponse::Ok().content_type("image/jpeg").body(image), | ||
// None => HttpResponse::NotFound() | ||
// .content_type("text/plain") | ||
// .body(format!( | ||
// "Thumbnail not found for source {:?}.", | ||
// thumbnail_file_request.source | ||
// )), | ||
// Some(Err(error)) => HttpResponse::ServiceUnavailable() | ||
// .reason("Thumbnail temporarily unavailable") | ||
// .insert_header((header::RETRY_AFTER, 10)) | ||
// .content_type("text/plain") | ||
// .body(format!( | ||
// "Thumbnail for source {:?} is temporarily unavailable. Try again later. Details: {error:?}", | ||
// thumbnail_file_request.source | ||
// )), | ||
// } | ||
// } | ||
Comment on lines
+429
to
+466
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be reworked with care to work with only one worker... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be reworked with care to work with only one worker...