yagcdn/backend/src/data.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

2019-08-07 21:44:20 +02:00
use crate::service;
2019-08-07 18:50:52 +02:00
use std::sync::{Arc, RwLock};
2019-08-07 21:44:20 +02:00
use time_cache::Cache;
2019-08-07 18:50:52 +02:00
pub(crate) type State = Arc<RwLock<Cache<Key, String>>>;
2019-07-24 17:54:00 +02:00
#[derive(Deserialize, Debug)]
pub(crate) struct FilePath {
2019-08-07 20:41:01 +02:00
pub(crate) user: Arc<String>,
pub(crate) repo: Arc<String>,
pub(crate) commit: Arc<String>,
pub(crate) file: Arc<String>,
2019-07-24 17:54:00 +02:00
}
2019-08-07 18:50:52 +02:00
impl FilePath {
pub(crate) fn path(&self) -> String {
format!("{}/{}/{}/{}", self.user, self.repo, self.commit, self.file)
}
2019-08-07 21:44:20 +02:00
pub(crate) fn to_key<T: service::Service>(&self) -> Key {
2019-08-07 18:50:52 +02:00
Key::new(
T::cache_service(),
self.user.clone(),
self.repo.clone(),
self.commit.clone(),
)
}
}
2019-08-07 21:44:20 +02:00
#[derive(Eq, PartialEq, Hash, Debug)]
pub(crate) struct Key(Service, Arc<String>, Arc<String>, Arc<String>);
#[derive(Eq, PartialEq, Hash, Debug)]
pub(crate) enum Service {
GitHub,
GitLab,
Bitbucket,
}
impl Key {
pub(crate) fn new(
service: Service,
user: Arc<String>,
repo: Arc<String>,
branch: Arc<String>,
) -> Self {
Key(service, user, repo, branch)
}
}