refactor(indexeddb): add fns to get and put media cleanup time

Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
This commit is contained in:
Michael Goldenberg
2025-10-01 21:13:05 -04:00
committed by Benjamin Bouvier
parent e4243b7af3
commit 22bfe8fbd3
@@ -23,7 +23,7 @@ use crate::{
serializer::indexed_types::{
IndexedCoreIdKey, IndexedLeaseIdKey, IndexedMediaIdKey, IndexedMediaUriKey,
},
types::{Lease, Media, UnixTime},
types::{Lease, Media, MediaCleanupTime, UnixTime},
},
serializer::IndexedTypeSerializer,
transaction::{Transaction, TransactionError},
@@ -80,6 +80,23 @@ impl<'a> IndexeddbMediaStoreTransaction<'a> {
.await
}
/// Query IndexedDB for the stored [`MediaCleanupTime`]
pub async fn get_media_cleanup_time(
&self,
) -> Result<Option<MediaCleanupTime>, TransactionError> {
self.transaction.get_item_by_key_components::<MediaCleanupTime, IndexedCoreIdKey>(()).await
}
/// Puts a media clean up time into IndexedDB. If one already exists, it
/// will be overwritten.
pub async fn put_media_cleanup_time(
&self,
time: impl Into<MediaCleanupTime>,
) -> Result<(), TransactionError> {
let time: MediaCleanupTime = time.into();
self.transaction.put_item(&time).await
}
/// Query IndexedDB for [`Media`] that matches the given
/// [`MediaRequestParameters`]. If more than one item is found, an error
/// is returned.