chore: refactor into a RecordingDataManager, lay the ground work for a RenderManager

This commit is contained in:
2026-05-27 01:28:47 -04:00
parent f86c094dda
commit e72633f26a
22 changed files with 830 additions and 49 deletions

57
src/recording_data/day.rs Normal file
View File

@@ -0,0 +1,57 @@
use futures::{TryStream, TryStreamExt as _};
use snafu::{OptionExt as _, ResultExt as _, Snafu};
use std::num::ParseIntError;
use super::{CreateListerSnafu, ListError, Month, RecordingDataManager, Year};
pub type Day = u8;
#[derive(Debug, Snafu)]
pub enum TakeError {
/// days are supposed to be directories, but this wasn't (because it didn't end with `/`)
NotADirectory,
/// could not parse the day as an integer
ParseIntegerError { source: ParseIntError },
}
pub fn take(s: &str) -> Result<(Day, &str), TakeError> {
let (day, rest) = s.split_once('/').context(NotADirectorySnafu)?;
let day = day.parse().context(ParseIntegerSnafu)?;
Ok((day, rest))
}
#[derive(Debug, Snafu)]
pub enum DayEntryError {
/// failed to get an entry from the storage operator's lister
ReceiveEntryError { source: opendal::Error },
/// failed to parse the entry as a day
ParseError { source: TakeError },
}
impl RecordingDataManager {
pub async fn days(
&self,
year: Year,
month: Month,
) -> Result<impl TryStream<Ok = Day, Error = DayEntryError> + Unpin, ListError> {
let lister = self
.operator
.lister(&format!("{year}/{month}/"))
.await
.context(CreateListerSnafu)?;
Ok(lister
.map_err(|error| DayEntryError::ReceiveEntryError { source: error })
.and_then(|entry| {
std::future::ready(
take(entry.name())
.map(|(day, rest)| day)
.context(ParseSnafu),
)
}))
}
}