wip render repo
This commit is contained in:
parent
44c310ac11
commit
145e3c592e
6 changed files with 190 additions and 50 deletions
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{cache, config::Config, repo::ReadRepoMetadataError};
|
||||
use crate::{cache, config::Config, repo::ReadRepoMetadataError, templates};
|
||||
|
||||
use askama::Template;
|
||||
use async_lock::Mutex;
|
||||
use log::error;
|
||||
use std::{collections::HashMap, io::ErrorKind, path::PathBuf};
|
||||
use std::{collections::{BTreeMap, BTreeSet, HashMap}, io::ErrorKind, path::PathBuf};
|
||||
use trillium::{Conn, Handler};
|
||||
use trillium_router::{Router, RouterConnExt};
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
};
|
||||
|
||||
let mut client = client.lock().await;
|
||||
let repo_index = crate::api_client::fetch_repo_tree_index_at_commit(
|
||||
let (repo_index, mut repo_metadata) = crate::api_client::fetch_repo_tree_index_at_commit(
|
||||
&mut client,
|
||||
&repo_url,
|
||||
&commit_hash,
|
||||
|
|
@ -59,7 +59,7 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
)
|
||||
.await
|
||||
.expect("todo handle error");
|
||||
crate::api_client::fetch_repo_files(config, &mut client, &repo_index, None)
|
||||
crate::api_client::fetch_repo_files(config, &mut client, &repo_index, &mut repo_metadata, None)
|
||||
.await
|
||||
.expect("todo handle error");
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
|
||||
let cache_fetch = |key| {
|
||||
let mut repo_hash = [0; 32];
|
||||
if base64_turbo::URL_SAFE.decode_into(repo_hash_str, &mut repo_hash)
|
||||
if base64_turbo::URL_SAFE.decode_into(key, &mut repo_hash)
|
||||
!= Ok(32)
|
||||
{
|
||||
return None;
|
||||
|
|
@ -95,11 +95,19 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
return None;
|
||||
}
|
||||
};
|
||||
let mut files = HashMap::new();
|
||||
for file in repo_metadata.iter_files() {
|
||||
match file {
|
||||
Ok(file) => {
|
||||
files.insert(file.file_path.to_string(), file.hash.to_string());
|
||||
let mut entries = templates::Directory::default();
|
||||
for entry in repo_metadata.iter_files() {
|
||||
match entry {
|
||||
Ok(entry) => {
|
||||
let Some(name) = entry.file_path.rsplit('/').next() else {
|
||||
error!("Entry has no name");
|
||||
continue;
|
||||
};
|
||||
let path = entry.file_path.split('/').peekable();
|
||||
let template_entry = match entry {
|
||||
|
||||
}
|
||||
entries.insert(, path);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Reading repo metadata file index: {e:?}")
|
||||
|
|
@ -109,10 +117,12 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
Some(files)
|
||||
};
|
||||
// TODO replace mutex with better thing (less contention or async mutex)
|
||||
metadata_cache
|
||||
let Some(metadata) = metadata_cache
|
||||
.lock()
|
||||
.await
|
||||
.fetch(repo_hash_str.to_string(), cache_fetch);
|
||||
.fetch(repo_hash_str.to_string(), cache_fetch) else {
|
||||
return conn.with_status(404);
|
||||
};
|
||||
|
||||
let hl_options = giallo::HighlightOptions::new(
|
||||
"py",
|
||||
|
|
@ -130,6 +140,7 @@ pub fn make_router(config: &'static Config) -> impl Handler {
|
|||
);
|
||||
conn.ok(crate::templates::Repo {
|
||||
content: html.clone(),
|
||||
entries: Vec::new(),
|
||||
}
|
||||
.render()
|
||||
.unwrap())
|
||||
|
|
|
|||
Loading…
Reference in a new issue