feat: add HTTP API and integration coverage
Expose the daemon request surface over /v1 with Axum, reuse shared key parsing between CLI and HTTP, and add an isolated end-to-end HTTP test that boots a real daemon process with temp XDG paths.
This commit is contained in:
+5
-41
@@ -12,7 +12,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
adapters::{AppInfo, Device, DeviceState, TvKey},
|
||||
adapters::{AppInfo, Device, DeviceState, TvKey, parse_normalized_tv_key},
|
||||
daemon::{
|
||||
self,
|
||||
config::{RuntimePaths, TvctlConfig, default_config_path, systemd_unit_path},
|
||||
@@ -1409,46 +1409,10 @@ fn is_secret_config_key(key: &str) -> bool {
|
||||
}
|
||||
|
||||
fn parse_tv_key(input: &str) -> Result<TvKey, CliError> {
|
||||
if let Some(literal) = input.strip_prefix("literal:") {
|
||||
return Ok(TvKey::Literal(literal.to_string()));
|
||||
}
|
||||
|
||||
match input.to_ascii_lowercase().as_str() {
|
||||
"home" => Ok(TvKey::Home),
|
||||
"back" => Ok(TvKey::Back),
|
||||
"up" => Ok(TvKey::Up),
|
||||
"down" => Ok(TvKey::Down),
|
||||
"left" => Ok(TvKey::Left),
|
||||
"right" => Ok(TvKey::Right),
|
||||
"select" => Ok(TvKey::Select),
|
||||
"play" => Ok(TvKey::Play),
|
||||
"pause" => Ok(TvKey::Pause),
|
||||
"play-pause" => Ok(TvKey::PlayPause),
|
||||
"stop" => Ok(TvKey::Stop),
|
||||
"rewind" => Ok(TvKey::Rewind),
|
||||
"fast-forward" => Ok(TvKey::FastForward),
|
||||
"replay" => Ok(TvKey::Replay),
|
||||
"skip" => Ok(TvKey::Skip),
|
||||
"channel-up" => Ok(TvKey::ChannelUp),
|
||||
"channel-down" => Ok(TvKey::ChannelDown),
|
||||
"volume-up" => Ok(TvKey::VolumeUp),
|
||||
"volume-down" => Ok(TvKey::VolumeDown),
|
||||
"mute" => Ok(TvKey::Mute),
|
||||
"power" => Ok(TvKey::Power),
|
||||
"power-on" => Ok(TvKey::PowerOn),
|
||||
"power-off" => Ok(TvKey::PowerOff),
|
||||
"input-hdmi1" => Ok(TvKey::InputHdmi1),
|
||||
"input-hdmi2" => Ok(TvKey::InputHdmi2),
|
||||
"input-hdmi3" => Ok(TvKey::InputHdmi3),
|
||||
"input-hdmi4" => Ok(TvKey::InputHdmi4),
|
||||
"input-av" => Ok(TvKey::InputAv),
|
||||
"input-tuner" => Ok(TvKey::InputTuner),
|
||||
"search" => Ok(TvKey::Search),
|
||||
"info" => Ok(TvKey::Info),
|
||||
"options" => Ok(TvKey::Options),
|
||||
_ => Err(CliError::new(
|
||||
parse_normalized_tv_key(input).map_err(|_| {
|
||||
CliError::new(
|
||||
format!("Unknown key '{input}'."),
|
||||
"Use a normalized key like `home`, `down`, `volume-up`, or `literal:text`.",
|
||||
)),
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user