flatten frames to data block when needed

This commit is contained in:
Miquel Farre 2024-11-25 13:58:37 +00:00 committed by drbh
parent e65ead12bb
commit 36e095b38d
2 changed files with 13 additions and 3 deletions

View File

@ -79,10 +79,14 @@ impl ChunksToString for Vec<InputChunk> {
let encoded = STANDARD.encode(data);
output.push_str(&format!("![](data:{};base64,{})", mimetype, encoded))
}
Some(Chunk::Video(Video { data, mimetype })) => {
let encoded = STANDARD.encode(data);
output.push_str(&format!("<video>(data:{};base64,{})", mimetype, encoded))
Some(Chunk::Video(video)) => {
let encoded = STANDARD.encode(&video.as_bytes());
output.push_str(&format!("<video>(data:{};base64,{})", video.mimetype, encoded))
}
// Some(Chunk::Video(Video { data, mimetype })) => {
// let encoded = STANDARD.encode(data);
// output.push_str(&format!("<video>(data:{};base64,{})", mimetype, encoded))
// }
// We don't create empty chunks, so this should be unreachable.
None => unreachable!("Chunks should never be empty"),
});

View File

@ -816,6 +816,12 @@ pub struct Video {
pub mimetype: String,
}
impl Video {
pub fn as_bytes(&self) -> Vec<u8> {
self.frames.iter().flatten().cloned().collect()
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Chunk {
Text(String),