MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / normalize_source

Function normalize_source

packages/server/src/camera.rs:325–356  ·  view source on GitHub ↗
(mut source: CameraSource)

Source from the content-addressed store, hash-verified

323}
324
325fn 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
358pub fn file_source(path_or_url: &str) -> CameraSource {
359 let kind = if is_video_source(path_or_url) {

Callers 2

start_cameraFunction · 0.85
switch_cameraFunction · 0.85

Calls 2

is_urlFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected