feat: define gitea webhook routes

This commit is contained in:
Aravinth Manivannan 2022-12-28 04:38:57 +05:30
parent 8b19a8cac5
commit 745b1eb0d5
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
2 changed files with 35 additions and 1 deletions

View File

@ -24,6 +24,7 @@ pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES};
use crate::db::Event;
use crate::db::LibrePagesEvent;
pub mod gitea;
pub mod home;
pub mod sites;
@ -49,9 +50,11 @@ impl From<LibrePagesEvent> for TemplateSiteEvent {
pub fn register_templates(t: &mut tera::Tera) {
home::DASH_HOME.register(t).expect(home::DASH_HOME.name);
sites::register_templates(t);
gitea::register_templates(t);
}
pub fn services(cfg: &mut web::ServiceConfig) {
home::services(cfg);
sites::services(cfg);
gitea::services(cfg);
}

View File

@ -72,6 +72,7 @@ pub struct Dash {
/// home route
pub home: &'static str,
pub site: DashSite,
pub gitea_webhook: GiteaWebhook,
}
impl Dash {
@ -79,7 +80,37 @@ impl Dash {
pub const fn new() -> Dash {
let home = "/dash";
let site = DashSite::new();
Dash { home, site }
let gitea_webhook = GiteaWebhook::new();
Dash {
home,
site,
gitea_webhook,
}
}
}
#[derive(Serialize)]
/// Dashboard GiteaWebhook routes
pub struct GiteaWebhook {
/// add gitea webhook route
pub add: &'static str,
/// view gitea webhook route
pub view: &'static str,
/// list gitea webhooks route
pub list: &'static str,
}
impl GiteaWebhook {
/// create new instance of GiteaWebhook route
pub const fn new() -> GiteaWebhook {
let add = "/dash/gitea/webhook/add";
let list = "/dash/gitea/webhook/list";
let view = "/dash/gitea/webhook/view/{auth_token}";
GiteaWebhook { add, view, list }
}
pub fn get_view(&self, auth_token: &str) -> String {
self.view.replace("{auth_token}", auth_token)
}
}