os_checker_types/
info.rs

1use crate::prelude::*;
2
3#[derive(Debug, Encode, Decode, Clone)]
4pub struct InfoKey {
5    pub repo: crate::db::CacheRepo,
6    #[musli(with = musli::serde)]
7    pub config: crate::db::RepoConfig,
8}
9
10impl InfoKey {
11    pub fn user_repo(&self) -> [&str; 2] {
12        self.repo.user_repo()
13    }
14}
15
16redb_value!(@key InfoKey, name: "OsCheckerInfoKey",
17    read_err: "Not a valid info key.",
18    write_err: "Info key can't be encoded to bytes."
19);
20
21#[derive(Debug, Encode, Decode)]
22pub struct Info {
23    /// 该仓库的检查是否全部完成
24    pub complete: bool,
25    /// 缓存信息
26    pub caches: Vec<crate::db::CacheRepoKey>,
27    /// 仓库最新提交信息
28    pub latest_commit: LatestCommit,
29}
30
31redb_value!(Info, name: "OsCheckerInfo",
32    read_err: "Not a valid info value.",
33    write_err: "Info value can't be encoded to bytes."
34);
35
36#[derive(Debug, Encode, Decode)]
37pub struct LatestCommit {
38    pub sha: String,
39    pub mes: String,
40    pub author: Committer,
41    pub committer: Committer,
42}
43
44#[derive(Encode, Decode)]
45pub struct Committer {
46    // store as unix timestemp milli
47    pub datetime: u64,
48    #[musli(with = musli::serde)]
49    pub email: String,
50    #[musli(with = musli::serde)]
51    pub name: XString,
52}
53
54impl fmt::Debug for Committer {
55    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56        f.debug_struct("Committer")
57            .field(
58                "datetime",
59                &super::parse_unix_timestamp_milli(self.datetime),
60            )
61            .field("email", &self.email)
62            .field("name", &self.name)
63            .finish()
64    }
65}
66
67// fn deserialize_date<'de, D>(deserializer: D) -> Result<u64, D::Error>
68// where
69//     D: serde::Deserializer<'de>,
70// {
71//     let dt = <&str>::deserialize(deserializer)?;
72//     Ok(parse_datetime(dt))
73// }
74//
75// fn parse_datetime(dt: &str) -> u64 {
76//     const DESC: &[time::format_description::BorrowedFormatItem<'static>] =
77//         time::macros::format_description!("[year]-[month]-[day]T[hour]:[minute]:[second]Z");
78//     let utc = time::PrimitiveDateTime::parse(dt, DESC)
79//         .unwrap()
80//         .assume_utc();
81//     let local = utc.to_offset(time::UtcOffset::from_hms(8, 0, 0).unwrap());
82//     unix_timestamp_milli(local)
83// }