(mut source: CameraSource)
| 323 | } |
| 324 | |
| 325 | fn normalize_source(mut source: CameraSource) -> Result<CameraSource, AppError> { |
| 326 | if let Some(arg) = source.arg.as_deref() { |
| 327 | let trimmed = arg.trim(); |
| 328 | source.arg = (!trimmed.is_empty()).then(|| trimmed.to_owned()); |
| 329 | } |
| 330 | match source.kind { |
| 331 | CameraSourceKind::Placeholder => { |
| 332 | source.arg = None; |
| 333 | } |
| 334 | CameraSourceKind::Image | CameraSourceKind::Video => { |
| 335 | let arg = source.arg.as_deref().ok_or_else(|| { |
| 336 | AppError::bad_request("Camera file or stream source requires `arg`.") |
| 337 | })?; |
| 338 | if !is_url(arg) { |
| 339 | let path = Path::new(arg); |
| 340 | if !path.is_absolute() { |
| 341 | return Err(AppError::bad_request( |
| 342 | "Camera file source must be an absolute path.", |
| 343 | )); |
| 344 | } |
| 345 | if !path.exists() { |
| 346 | return Err(AppError::not_found(format!( |
| 347 | "Camera media source does not exist: {}", |
| 348 | path.display() |
| 349 | ))); |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | CameraSourceKind::Webcam => {} |
| 354 | } |
| 355 | Ok(source) |
| 356 | } |
| 357 | |
| 358 | pub fn file_source(path_or_url: &str) -> CameraSource { |
| 359 | let kind = if is_video_source(path_or_url) { |
no test coverage detected