yagcdn/backend/src/data.rs
2019-08-07 21:44:20 +02:00

50 lines
1.1 KiB
Rust

use crate::service;
use std::sync::{Arc, RwLock};
use time_cache::Cache;
pub(crate) type State = Arc<RwLock<Cache<Key, String>>>;
#[derive(Deserialize, Debug)]
pub(crate) struct FilePath {
pub(crate) user: Arc<String>,
pub(crate) repo: Arc<String>,
pub(crate) commit: Arc<String>,
pub(crate) file: Arc<String>,
}
impl FilePath {
pub(crate) fn path(&self) -> String {
format!("{}/{}/{}/{}", self.user, self.repo, self.commit, self.file)
}
pub(crate) fn to_key<T: service::Service>(&self) -> Key {
Key::new(
T::cache_service(),
self.user.clone(),
self.repo.clone(),
self.commit.clone(),
)
}
}
#[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)
}
}