fixes frontend getting resources from backend
This commit is contained in:
@@ -1,2 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Emma Tebibyte <emma@tebibyte.media>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This file is part of Mintee.
|
||||
*
|
||||
* Mintee is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* Mintee is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Mintee. If not, see https://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
pub mod git;
|
||||
pub mod render;
|
||||
|
||||
const MINTEE_DIR: &str = "/var/mintee";
|
||||
const MINTEE_ASSETS: &str = "/usr/local/share/mintee";
|
||||
|
||||
pub mod srv {
|
||||
use std::{
|
||||
error::Error,
|
||||
fs::File,
|
||||
io::{ BufReader, BufWriter, Write, copy },
|
||||
path::Path,
|
||||
};
|
||||
use crate::backend::MINTEE_ASSETS;
|
||||
|
||||
pub fn get_res<T, W>(path: T, dest: &mut W) -> Result<(), Box<dyn Error>>
|
||||
where T: AsRef<Path>, W: Write {
|
||||
let path_absolute = Path::new(MINTEE_ASSETS).join("res").join(path);
|
||||
|
||||
let mut reader = BufReader::new(File::open(path_absolute)?);
|
||||
let mut writer = BufWriter::new(dest);
|
||||
|
||||
copy(&mut reader, &mut writer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,11 @@ use std::{
|
||||
use gix::open;
|
||||
use tera::Tera;
|
||||
|
||||
use crate::backend::git::ToContext;
|
||||
use crate::backend::{
|
||||
MINTEE_DIR,
|
||||
MINTEE_ASSETS,
|
||||
git::ToContext,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
/// A revision for which a repository page may be rendered
|
||||
@@ -134,9 +138,8 @@ impl Page {
|
||||
pub fn render<W: Write>(
|
||||
&self, dest: &mut W
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
/* TODO: replace ./assets/ with the actual templates directory,
|
||||
* i.e. /usr/local/share/mintee/ */
|
||||
let tera = Tera::new("./assets/templates/**/*")?;
|
||||
let assets = format!("{}/templates/**/*", MINTEE_ASSETS);
|
||||
let tera = Tera::new(&assets)?;
|
||||
let mut page_template = self.kind.to_string();
|
||||
|
||||
use PageKind::*;
|
||||
@@ -145,7 +148,11 @@ impl Page {
|
||||
todo!()
|
||||
},
|
||||
Repo(r) => {
|
||||
let repo = open(format!("{}/{}", r.entity, r.name))?;
|
||||
|
||||
let mut repo_path = PathBuf::from(MINTEE_DIR.to_string());
|
||||
repo_path.push(r.entity);
|
||||
repo_path.push(r.name);
|
||||
let repo = open(repo_path)?;
|
||||
/* TODO: handle specifying a commit, tag, or branch */
|
||||
let head_tree = repo.head_tree()?;
|
||||
let object;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2025, 2026 silt <silt@tebibyte.media>
|
||||
* Copyright (c) 2026 Emma Tebibyte <emma@tebibyte.media>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*
|
||||
* This file is part of Mintee.
|
||||
@@ -31,7 +32,14 @@ use std::{
|
||||
};
|
||||
use typed_path::{Utf8Component, Utf8UnixComponent, Utf8UnixPath, Utf8UnixPathBuf};
|
||||
|
||||
use mintee::{backend::{self, render::{Page, Repo, Revision}}, util::yapper::{eyap, yap}};
|
||||
use mintee::{
|
||||
backend::{
|
||||
self,
|
||||
render::{ Page, PageKind Repo, Revision },
|
||||
srv::get_res,
|
||||
},
|
||||
util::yapper::{eyap, yap},
|
||||
};
|
||||
|
||||
pub use super::manager::{Frontend, FrontendImpl};
|
||||
|
||||
@@ -415,12 +423,12 @@ impl<'a> ReqResp<'a> for (Request<'a>, Response<'_>) {
|
||||
Some(("tag", tag)) => Some(Revision::Tag(tag.to_string())),
|
||||
_ => None
|
||||
};
|
||||
Page::new(backend::render::PageKind::Repo(Repo::new(user.to_string(), repo.to_string(), revision, None)), None).render(&mut response.body).unwrap();
|
||||
self
|
||||
Page::new(PageKind::Repo(Repo::new(user.to_string(), repo.to_string(), revision, None)), None).render(&mut response.body).unwrap();
|
||||
} else {
|
||||
response.status = Some(MethodNotAllowed { allow: vec![GET] });
|
||||
self
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
(method, ["/", project], _, _) if project.starts_with('+') => {
|
||||
if matches!(method, GET) {
|
||||
@@ -440,10 +448,22 @@ impl<'a> ReqResp<'a> for (Request<'a>, Response<'_>) {
|
||||
self
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.1.status = Some(NotFound);
|
||||
(method, ["/", "res", x @ ..], _, _) => {
|
||||
if matches!(method, GET) {
|
||||
match get_res(x.join("/"), &mut response.body) {
|
||||
Ok(_) => response.status = Some(Okay),
|
||||
Err(e) => { eyap!(e.to_string()); },
|
||||
}
|
||||
} else {
|
||||
response.status = Some(MethodNotAllowed { allow: vec![GET] });
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
_ => {
|
||||
response.status = Some(NotFound);
|
||||
self
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user