diff --git a/README.md b/README.md index b770a6b..7c0ea0d 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,19 @@ Early development: not usable yet. * [ ] Error pages * [ ] Webdesign * [ ] Compatibility with other forges +* [ ] Serve at a subdirectory * [ ] Better logo (contribution welcome) +## Install + +Use `example_config.toml`. The settings that are important to look at are `listen_host`, `listen_port`, `data_dir`, `api_client_user_agent` and `origin`. + +The executable is self-contained. Serve it behind any reverse proxy. The process must have read/write access to `data_dir`, where the repositories will be stored. + +```bash +blindforge config.toml +``` + ## Design choices **Language**: It would have been simpler to use good old PHP and SQL. But I have more fun with Rust. diff --git a/example_config.toml b/example_config.toml index 963165f..68de225 100644 --- a/example_config.toml +++ b/example_config.toml @@ -12,7 +12,8 @@ data_dir = "/dev/shm/blindforge" # Client will connect to the Git forge API using this User-Agent. -#api_client_user_agent = "Blindforge" +# Please edit this with your instance's public address. +#api_client_user_agent = "Blindforge (https://git.zoai.re/tuxmain/blindforge)" # Client will download at most this number of pages. #api_client_max_page = 32 @@ -30,4 +31,25 @@ data_dir = "/dev/shm/blindforge" # Maximum length of an URL for the client. (characters) #api_client_max_url_len = 256 -#origin = "https://blindforge.zoai.re" +# Files that are served when showing a directory (separated by colon `:`, in order of decreasing priority) +#default_files = "README.md:README.MD:readme.md:README.txt:README.TXT:readme.txt:README:readme" + +# Maximum number of rendered webpages to keep in cache +#page_cache_size = 200 + +# Maximum number of repository trees to keep in cache +#repo_cache_size = 20 + +# File extensions that will be served as images (and associated MIME type) +#image_extensions = {ani="image/x-icon", apng="image/apng", bmp="image/bmp", cur="image/x-icon", gif="image/gif", ico="image/x-icon", jpeg="image/jpeg", jpg="image/jpeg", jxl="image/jxl", png="image/png", qoi="image/qoi", tif="image/tiff", tiff="image/tiff", webp="image/webp"} + +# File extensions that will be served as videos (and associated MIME type) +#video_extensions = {3gp="video/3gp", avi="video/x-msvideo", mkv="application/x-matroska", mp4="video/mp4", mpeg="video/mpeg", ogv="video/ogg", webm="video/webm"} + +# File extensions that will be served as audio (and associated MIME type) +#audio_extensions = {aac="audio/aac", flac="audio/flac", m4a="audio/mp4", m4b="audio/mp4", m4p="audio/mp4", m4r="audio/mp4", m4v="audio/mp4", mp3="audio/mp3", oga="audio/ogg", ogg="audio/ogg", opus="audio/opus", spx="audio/x-speex", wav="audio/x-wav", wave="audio/x-wav", wma="audio/x-ms-wma"} + +# Authorized origin for serving inline files (CORS) +# You should set your instance's address (e.g. "https://domain.tld") +# to prevent people using your server as a CDN. +#origin = "*" diff --git a/src/api_client.rs b/src/api_client.rs index 44ce89c..ee0fe17 100644 --- a/src/api_client.rs +++ b/src/api_client.rs @@ -1,3 +1,5 @@ +//! Client for downloading repositories from a forge's API. + use std::{collections::HashSet, io::Write, path::PathBuf}; use crate::{ diff --git a/src/cache.rs b/src/cache.rs index 50b977c..914fb5c 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,3 +1,5 @@ +//! Generic caching in-memory map. + use dashmap::DashMap; use std::{ borrow::Borrow, diff --git a/src/config.rs b/src/config.rs index ba334c6..fc6d56e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,5 @@ +//! Server configuration structure, reading and default. + use std::collections::HashMap; pub struct Config { @@ -41,7 +43,9 @@ impl Default for Config { listen_host: String::from("127.0.0.1"), listen_port: 44617, data_dir: String::from("/var/lib/blindforge"), - api_client_user_agent: String::from("Blindforge"), + api_client_user_agent: String::from( + "Blindforge (https://git.zoai.re/tuxmain/blindforge)", + ), api_client_max_page: 32, max_entries: 1024, max_file_size: 8 * 1024 * 1024, diff --git a/src/render.rs b/src/render.rs index e3f9762..6d171b6 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,3 +1,5 @@ +//! File rendering: code highlighting and markdown. + use crate::config::Config; use linemd::Parser; diff --git a/src/repo.rs b/src/repo.rs index adfc807..5657ea7 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,3 +1,5 @@ +//! Repository data structures and storage logic. + use crate::api_client::{MAX_PATH_SIZE, MAX_URL_SIZE}; use std::{ diff --git a/src/server.rs b/src/server.rs index e9a7bc6..e482026 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,3 +1,5 @@ +//! Where routes are defined and handled. + use crate::{cache, config::Config, render, repo, templates}; use askama::Template; @@ -315,9 +317,6 @@ pub fn make_router(config: &'static Config) -> impl Handler { .ok(file_content) } } - }) - .get("/e/:secret", |conn: Conn| async move { - conn.ok(crate::templates::Home {}.render().unwrap()) }), ) } diff --git a/src/templates.rs b/src/templates.rs index 2fb7a14..b395205 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -1,3 +1,5 @@ +//! Templates for storing data to be rendered as HTML. + use std::{collections::BTreeMap, iter::Peekable}; use log::warn;