1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
use serde_derive::Deserialize;
use std::collections::HashMap;
use crate::config::{parse_config_file, Flattenable};
use crate::PREVIEW_FILE;
#[derive(Debug, Deserialize)]
pub struct JoshutoPreviewEntry {
pub program: String,
pub args: Option<Vec<String>>,
}
#[derive(Debug, Deserialize)]
pub struct JoshutoRawPreview {
pub mimetype: Option<HashMap<String, JoshutoPreviewEntry>>,
pub extension: Option<HashMap<String, JoshutoPreviewEntry>>,
}
impl JoshutoRawPreview {
#[allow(dead_code)]
pub fn new() -> Self {
JoshutoRawPreview {
mimetype: None,
extension: None,
}
}
}
impl Flattenable<JoshutoPreview> for JoshutoRawPreview {
fn flatten(self) -> JoshutoPreview {
let mimetype = self.mimetype.unwrap_or_default();
let extension = self.extension.unwrap_or_default();
JoshutoPreview {
mimetype,
extension,
}
}
}
#[derive(Debug)]
pub struct JoshutoPreview {
pub mimetype: HashMap<String, JoshutoPreviewEntry>,
pub extension: HashMap<String, JoshutoPreviewEntry>,
}
impl JoshutoPreview {
pub fn new() -> Self {
JoshutoPreview {
mimetype: HashMap::new(),
extension: HashMap::new(),
}
}
pub fn get_config() -> JoshutoPreview {
parse_config_file::<JoshutoRawPreview, JoshutoPreview>(PREVIEW_FILE)
.unwrap_or_else(JoshutoPreview::new)
}
}
|