Skip to main content

eureka_mmanager/files_dirs/messages/pull/chapter/
chapter_image_data_pull.rs

1use std::{fs::File, path::Path};
2
3use actix::prelude::*;
4use mangadex_api_input_types::PathBuf;
5use uuid::Uuid;
6
7use crate::{DirsOptions, ManagerCoreResult};
8
9#[derive(Debug, Clone, Hash, Default)]
10pub struct ChapterImageDataPullMessage<P: AsRef<Path>>(pub Uuid, pub P);
11
12impl<P: AsRef<Path>> From<(Uuid, P)> for ChapterImageDataPullMessage<P> {
13    fn from((id, path): (Uuid, P)) -> Self {
14        Self(id, path)
15    }
16}
17
18impl<P: AsRef<Path>> From<ChapterImageDataPullMessage<P>> for Uuid {
19    fn from(value: ChapterImageDataPullMessage<P>) -> Self {
20        value.0
21    }
22}
23
24impl<P> From<ChapterImageDataPullMessage<P>> for PathBuf
25where
26    P: AsRef<Path>,
27{
28    fn from(value: ChapterImageDataPullMessage<P>) -> Self {
29        value.1.as_ref().to_path_buf().into()
30    }
31}
32
33impl<P: AsRef<Path>> Message for ChapterImageDataPullMessage<P> {
34    type Result = ManagerCoreResult<File>;
35}
36
37impl<P: AsRef<Path>> Handler<ChapterImageDataPullMessage<P>> for DirsOptions {
38    type Result = <ChapterImageDataPullMessage<P> as Message>::Result;
39    fn handle(
40        &mut self,
41        msg: ChapterImageDataPullMessage<P>,
42        _ctx: &mut Self::Context,
43    ) -> Self::Result {
44        Ok(File::open(self.chapters_id_data_add(msg.0).join(msg.1))?)
45    }
46}