aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-07 02:56:46 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-07 02:56:46 -0800
commit2f414df00e378728701e4061cdb3bebad5df798a (patch)
tree01a262f07dbfb3ba999ebb803dc33063262c6f9f
parent73bb6f114d3fe9233af4f9ab91c8fc2b09b3c6c0 (diff)
downloadadenosine-2f414df00e378728701e4061cdb3bebad5df798a.tar.gz
adenosine-2f414df00e378728701e4061cdb3bebad5df798a.zip
pds: initial pass at crude web interface
-rw-r--r--Cargo.lock151
-rw-r--r--adenosine-pds/Cargo.toml1
-rw-r--r--adenosine-pds/src/lib.rs180
-rw-r--r--adenosine-pds/src/repo.rs1
-rw-r--r--adenosine-pds/src/web.rs66
-rw-r--r--adenosine-pds/templates/about.html6
-rw-r--r--adenosine-pds/templates/adenosine.css626
-rw-r--r--adenosine-pds/templates/at_collection.html12
-rw-r--r--adenosine-pds/templates/at_record.html8
-rw-r--r--adenosine-pds/templates/at_repo.html18
-rw-r--r--adenosine-pds/templates/base.html32
-rw-r--r--adenosine-pds/templates/favicon.pngbin0 -> 2301 bytes
-rw-r--r--adenosine-pds/templates/home.html7
-rw-r--r--adenosine-pds/templates/logo_128.pngbin0 -> 16651 bytes
-rw-r--r--adenosine-pds/templates/post.html5
-rw-r--r--adenosine-pds/templates/profile.html7
-rw-r--r--adenosine-pds/templates/robots.txt1
17 files changed, 1040 insertions, 81 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e9eeb20..2460743 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -25,7 +25,7 @@ dependencies = [
"env_logger 0.9.1",
"lazy_static",
"log",
- "rand 0.7.3",
+ "rand",
"regex",
"reqwest",
"serde_json",
@@ -39,6 +39,7 @@ version = "0.1.0-dev.0"
dependencies = [
"adenosine-cli",
"anyhow",
+ "askama",
"async-trait",
"bcrypt",
"bs58",
@@ -81,7 +82,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
- "getrandom 0.2.8",
+ "getrandom",
"once_cell",
"version_check",
]
@@ -93,7 +94,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e6e951cfbb2db8de1828d49073a113a29fd7117b1596caa781a258c7e38d72"
dependencies = [
"cfg-if",
- "getrandom 0.2.8",
+ "getrandom",
"once_cell",
"serde",
"version_check",
@@ -166,6 +167,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16"
[[package]]
+name = "askama"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139"
+dependencies = [
+ "askama_derive",
+ "askama_escape",
+ "askama_shared",
+]
+
+[[package]]
+name = "askama_derive"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71"
+dependencies = [
+ "askama_shared",
+ "proc-macro2",
+ "syn",
+]
+
+[[package]]
+name = "askama_escape"
+version = "0.10.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
+
+[[package]]
+name = "askama_shared"
+version = "0.12.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0"
+dependencies = [
+ "askama_escape",
+ "humansize",
+ "mime",
+ "mime_guess",
+ "nom",
+ "num-traits",
+ "percent-encoding",
+ "proc-macro2",
+ "quote",
+ "serde",
+ "syn",
+ "toml",
+]
+
+[[package]]
name = "async-channel"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -344,7 +393,7 @@ checksum = "a7e7c93a3fb23b2fdde989b2c9ec4dd153063ec81f408507f84c090cd91c6641"
dependencies = [
"base64",
"blowfish",
- "getrandom 0.2.8",
+ "getrandom",
"zeroize",
]
@@ -746,7 +795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef"
dependencies = [
"generic-array",
- "rand_core 0.6.4",
+ "rand_core",
"subtle",
"zeroize",
]
@@ -938,7 +987,7 @@ dependencies = [
"generic-array",
"group",
"pkcs8",
- "rand_core 0.6.4",
+ "rand_core",
"sec1",
"subtle",
"zeroize",
@@ -1022,7 +1071,7 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160"
dependencies = [
- "rand_core 0.6.4",
+ "rand_core",
"subtle",
]
@@ -1200,17 +1249,6 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.1.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
-dependencies = [
- "cfg-if",
- "libc",
- "wasi 0.9.0+wasi-snapshot-preview1",
-]
-
-[[package]]
-name = "getrandom"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
@@ -1218,7 +1256,7 @@ dependencies = [
"cfg-if",
"js-sys",
"libc",
- "wasi 0.11.0+wasi-snapshot-preview1",
+ "wasi",
"wasm-bindgen",
]
@@ -1241,7 +1279,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7"
dependencies = [
"ff",
- "rand_core 0.6.4",
+ "rand_core",
"subtle",
]
@@ -1371,6 +1409,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
+name = "humansize"
+version = "1.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026"
+
+[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1791,7 +1835,7 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
dependencies = [
"libc",
"log",
- "wasi 0.11.0+wasi-snapshot-preview1",
+ "wasi",
"windows-sys 0.36.1",
]
@@ -1857,7 +1901,7 @@ dependencies = [
"mime",
"mime_guess",
"quick-error",
- "rand 0.8.5",
+ "rand",
"safemem",
"tempfile",
"twoway",
@@ -2310,36 +2354,13 @@ dependencies = [
[[package]]
name = "rand"
-version = "0.7.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
-dependencies = [
- "getrandom 0.1.16",
- "libc",
- "rand_chacha 0.2.2",
- "rand_core 0.5.1",
- "rand_hc",
-]
-
-[[package]]
-name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
- "rand_chacha 0.3.1",
- "rand_core 0.6.4",
-]
-
-[[package]]
-name = "rand_chacha"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
-dependencies = [
- "ppv-lite86",
- "rand_core 0.5.1",
+ "rand_chacha",
+ "rand_core",
]
[[package]]
@@ -2349,16 +2370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core 0.6.4",
-]
-
-[[package]]
-name = "rand_core"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
-dependencies = [
- "getrandom 0.1.16",
+ "rand_core",
]
[[package]]
@@ -2367,16 +2379,7 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
- "getrandom 0.2.8",
-]
-
-[[package]]
-name = "rand_hc"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
-dependencies = [
- "rand_core 0.5.1",
+ "getrandom",
]
[[package]]
@@ -2476,7 +2479,7 @@ dependencies = [
"multipart",
"num_cpus",
"percent-encoding",
- "rand 0.8.5",
+ "rand",
"serde",
"serde_derive",
"serde_json",
@@ -2829,7 +2832,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c"
dependencies = [
"digest 0.10.5",
- "rand_core 0.6.4",
+ "rand_core",
]
[[package]]
@@ -3254,12 +3257,12 @@ dependencies = [
"base64",
"bs58",
"cid",
- "getrandom 0.2.8",
+ "getrandom",
"instant",
"libipld-core",
"libipld-json",
"log",
- "rand 0.8.5",
+ "rand",
"serde",
"serde_json",
"strum",
@@ -3395,12 +3398,6 @@ dependencies = [
[[package]]
name = "wasi"
-version = "0.9.0+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
-
-[[package]]
-name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
diff --git a/adenosine-pds/Cargo.toml b/adenosine-pds/Cargo.toml
index 64765a4..7075e65 100644
--- a/adenosine-pds/Cargo.toml
+++ b/adenosine-pds/Cargo.toml
@@ -43,6 +43,7 @@ ucan = "0.7.0-alpha.1"
bs58 = "*"
async-trait = "*"
dotenv = "*"
+askama = "0.11"
# for vendored iroh-car
thiserror = "1.0"
diff --git a/adenosine-pds/src/lib.rs b/adenosine-pds/src/lib.rs
index a11b862..ee281e1 100644
--- a/adenosine-pds/src/lib.rs
+++ b/adenosine-pds/src/lib.rs
@@ -10,6 +10,7 @@ use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Mutex;
+use askama::Template;
mod car;
mod crypto;
@@ -28,6 +29,7 @@ pub use db::AtpDatabase;
pub use models::*;
pub use repo::{Mutation, RepoCommit, RepoStore};
pub use ucan_p256::P256KeyMaterial;
+use web::*;
struct AtpService {
pub repo: RepoStore,
@@ -74,6 +76,25 @@ fn xrpc_wrap<S: serde::Serialize>(resp: Result<S>) -> Response {
}
}
+/// Helper to take a Askama render Result and transform it to a rouille response, including more
+/// friendly HTML 404s, etc.
+fn web_wrap(resp: Result<String>) -> Response {
+ match resp {
+ Ok(val) => Response::html(val),
+ Err(e) => {
+ let msg = e.to_string();
+ let code = match e.downcast_ref::<XrpcError>() {
+ Some(XrpcError::BadRequest(_)) => 400,
+ Some(XrpcError::NotFound(_)) => 404,
+ Some(XrpcError::Forbidden(_)) => 403,
+ None => 500,
+ };
+ warn!("HTTP {}: {}", code, msg);
+ Response::html(format!("<html><body><h1>{}</h1><p>{}</body></html>", code, msg))
+ }
+ }
+}
+
pub fn run_server(
port: u16,
blockstore_db_path: &PathBuf,
@@ -100,13 +121,44 @@ pub fn run_server(
);
};
- // TODO: robots.txt
// TODO: some static files? https://github.com/tomaka/rouille/blob/master/examples/static-files.rs
rouille::start_server(format!("localhost:{}", port), move |request| {
rouille::log_custom(request, log_ok, log_err, || {
router!(request,
(GET) ["/"] => {
- Response::text("Not much to see here yet!")
+ let view = GenericHomeView { domain: "domain.todo".to_string() };
+ Response::html(view.render().unwrap())
+ },
+ (GET) ["/about"] => {
+ let view = AboutView { domain: "domain.todo".to_string() };
+ Response::html(view.render().unwrap())
+ },
+ (GET) ["/robots.txt"] => {
+ Response::text(include_str!("../templates/robots.txt"))
+ },
+ (GET) ["/u/{did}", did: Did] => {
+ web_wrap(profile_handler(&srv, &did, request))
+ },
+ (GET) ["/u/{did}/{collection}/{tid}", did: Did, collection: Nsid, tid: Tid] => {
+ web_wrap(post_handler(&srv, &did, &collection, &tid, request))
+ },
+ (GET) ["/at/{did}", did: Did] => {
+ web_wrap(repo_handler(&srv, &did, request))
+ },
+ (GET) ["/at/{did}/{collection}", did: Did, collection: Nsid] => {
+ web_wrap(collection_handler(&srv, &did, &collection, request))
+ },
+ (GET) ["/at/{did}/{collection}/{tid}", did: Did, collection: Nsid, tid: Tid] => {
+ web_wrap(record_handler(&srv, &did, &collection, &tid, request))
+ },
+ (GET) ["/static/adenosine.css"] => {
+ Response::from_data("text/css", include_str!("../templates/adenosine.css"))
+ },
+ (GET) ["/static/favicon.png"] => {
+ Response::from_data("image/png", include_bytes!("../templates/favicon.png").to_vec())
+ },
+ (GET) ["/static/logo_128.png"] => {
+ Response::from_data("image/png", include_bytes!("../templates/logo_128.png").to_vec())
},
(POST) ["/xrpc/{endpoint}", endpoint: String] => {
xrpc_wrap(xrpc_post_handler(&srv, &endpoint, request))
@@ -114,7 +166,7 @@ pub fn run_server(
(GET) ["/xrpc/{endpoint}", endpoint: String] => {
xrpc_wrap(xrpc_get_handler(&srv, &endpoint, request))
},
- _ => rouille::Response::empty_404()
+ _ => Response::text("404: Not Found")
)
})
});
@@ -205,7 +257,7 @@ fn xrpc_get_handler(
"com.atproto.server.getAccountsConfig" => {
Ok(json!({"availableUserDomains": ["test"], "inviteCodeRequired": false}))
}
- "com.atproto.repoGetRecord" => {
+ "com.atproto.repo.getRecord" => {
let did = Did::from_str(&xrpc_required_param(request, "user")?)?;
let collection = Nsid::from_str(&xrpc_required_param(request, "collection")?)?;
let rkey = Tid::from_str(&xrpc_required_param(request, "rkey")?)?;
@@ -456,3 +508,123 @@ fn xrpc_post_handler(
)))),
}
}
+
+fn profile_handler(srv: &Mutex<AtpService>, did: &str, _request: &Request) -> Result<String> {
+ let did = Did::from_str(did)?;
+ let mut _srv = srv.lock().expect("service mutex");
+
+ // TODO: get profile (bsky helper)
+ // TODO: get feed (bsky helper)
+
+ Ok(ProfileView {
+ domain: "domain.todo".to_string(),
+ did: did,
+ profile: json!({}),
+ feed: vec![],
+ }.render()?)
+}
+
+fn post_handler(srv: &Mutex<AtpService>, did: &str, collection: &str, tid: &str, _request: &Request) -> Result<String> {
+ let did = Did::from_str(did)?;
+ let collection = Nsid::from_str(collection)?;
+ let rkey = Tid::from_str(tid)?;
+ let mut srv = srv.lock().expect("service mutex");
+
+ let post = match srv.repo.get_atp_record(&did, &collection, &rkey) {
+ // TODO: format as JSON, not text debug
+ Ok(Some(ipld)) => ipld_into_json_value(ipld),
+ Ok(None) => Err(anyhow!(XrpcError::NotFound(format!(
+ "could not find record: /{}/{}", collection, rkey
+ ))))?,
+ Err(e) => Err(e)?,
+ };
+
+ Ok(PostView {
+ domain: "domain.todo".to_string(),
+ did: did,
+ collection: collection,
+ tid: rkey,
+ post_text: post["text"].as_str().unwrap().to_string(), // TODO: unwrap
+ post_created_at: "some-time".to_string(),
+ }.render()?)
+}
+
+fn repo_handler(srv: &Mutex<AtpService>, did: &str, _request: &Request) -> Result<String> {
+ let did = Did::from_str(did)?;
+
+ let mut srv = srv.lock().expect("service mutex");
+ let did_doc = srv.atp_db.get_did_doc(&did)?;
+ let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap();
+ let commit = srv.repo.get_commit(commit_cid)?;
+ let collections: Vec<String> = srv.repo.collections(&did)?;
+ let desc = RepoDescribe {
+ name: did.to_string(), // TODO
+ did: did.to_string(),
+ didDoc: did_doc,
+ collections: collections,
+ nameIsCorrect: true,
+ };
+
+ Ok(RepoView {
+ domain: "domain.todo".to_string(),
+ did: did,
+ commit: commit,
+ describe: desc,
+ }.render()?)
+}
+
+fn collection_handler(srv: &Mutex<AtpService>, did: &str, collection: &str, _request: &Request) -> Result<String> {
+ let did = Did::from_str(did)?;
+ let collection = Nsid::from_str(collection)?;
+
+ let mut record_list: Vec<Value> = vec![];
+ let mut srv = srv.lock().expect("service mutex");
+ let commit_cid = &srv.repo.lookup_commit(&did)?.unwrap();
+ let last_commit = srv.repo.get_commit(commit_cid)?;
+ let full_map = srv.repo.mst_to_map(&last_commit.mst_cid)?;
+ let prefix = format!("/{}/", collection);
+ for (mst_key, cid) in full_map.iter() {
+ debug!("{}", mst_key);
+ if mst_key.starts_with(&prefix) {
+ let record = srv.repo.get_ipld(cid)?;
+ record_list.push(json!({
+ "uri": format!("at://{}{}", did, mst_key),
+ "tid": mst_key.split('/').nth(2).unwrap(),
+ "cid": cid,
+ "value": ipld_into_json_value(record),
+ }));
+ }
+ }
+
+ Ok(CollectionView {
+ domain: "domain.todo".to_string(),
+ did: did,
+ collection: collection,
+ records: record_list,
+ }.render()?)
+}
+
+fn record_handler(srv: &Mutex<AtpService>, did: &str, collection: &str, tid: &str, _request: &Request) -> Result<String> {
+
+ let did = Did::from_str(did)?;
+ let collection = Nsid::from_str(collection)?;
+ let rkey = Tid::from_str(tid)?;
+
+ let mut srv = srv.lock().expect("service mutex");
+ let key = format!("/{}/{}", collection, rkey);
+ let record = match srv.repo.get_atp_record(&did, &collection, &rkey) {
+ Ok(Some(ipld)) => ipld_into_json_value(ipld),
+ Ok(None) => Err(anyhow!(XrpcError::NotFound(format!(
+ "could not find record: {}",
+ key
+ ))))?,
+ Err(e) => Err(e)?,
+ };
+ Ok(RecordView {
+ domain: "domain.todo".to_string(),
+ did,
+ collection,
+ tid: rkey,
+ record,
+ }.render()?)
+}
diff --git a/adenosine-pds/src/repo.rs b/adenosine-pds/src/repo.rs
index 1bfc581..7b6f7e6 100644
--- a/adenosine-pds/src/repo.rs
+++ b/adenosine-pds/src/repo.rs
@@ -14,6 +14,7 @@ use std::collections::HashSet;
use std::path::PathBuf;
use std::str::FromStr;
+#[derive(Debug)]
pub struct RepoCommit {
pub sig: Box<[u8]>,
pub commit_cid: Cid,
diff --git a/adenosine-pds/src/web.rs b/adenosine-pds/src/web.rs
new file mode 100644
index 0000000..81e62be
--- /dev/null
+++ b/adenosine-pds/src/web.rs
@@ -0,0 +1,66 @@
+
+use adenosine_cli::identifiers::{Did, Nsid, Tid};
+use serde_json;
+use askama::Template;
+use crate::repo::RepoCommit;
+use crate::models::*;
+
+#[derive(Template)]
+#[template(path = "home.html")]
+pub struct GenericHomeView {
+ pub domain: String,
+}
+
+#[derive(Template)]
+#[template(path = "about.html")]
+pub struct AboutView {
+ pub domain: String,
+}
+
+#[derive(Template)]
+#[template(path = "profile.html")]
+pub struct ProfileView {
+ pub domain: String,
+ pub did: Did,
+ pub profile: serde_json::Value,
+ pub feed: Vec<serde_json::Value>,
+}
+
+#[derive(Template)]
+#[template(path = "post.html")]
+pub struct PostView {
+ pub domain: String,
+ pub did: Did,
+ pub collection: Nsid,
+ pub tid: Tid,
+ pub post_text: String,
+ pub post_created_at: String,
+}
+
+#[derive(Template)]
+#[template(path = "at_repo.html")]
+pub struct RepoView {
+ pub domain: String,
+ pub did: Did,
+ pub commit: RepoCommit,
+ pub describe: RepoDescribe,
+}
+
+#[derive(Template)]
+#[template(path = "at_collection.html")]
+pub struct CollectionView {
+ pub domain: String,
+ pub did: Did,
+ pub collection: Nsid,
+ pub records: Vec<serde_json::Value>,
+}
+
+#[derive(Template)]
+#[template(path = "at_record.html")]
+pub struct RecordView {
+ pub domain: String,
+ pub did: Did,
+ pub collection: Nsid,
+ pub tid: Tid,
+ pub record: serde_json::Value,
+}
diff --git a/adenosine-pds/templates/about.html b/adenosine-pds/templates/about.html
new file mode 100644
index 0000000..6c30c6b
--- /dev/null
+++ b/adenosine-pds/templates/about.html
@@ -0,0 +1,6 @@
+{% extends "base.html" %}
+
+{% block content %}
+This about page is the kind of place one would put policies, license details, etc.
+
+{% endblock %}
diff --git a/adenosine-pds/templates/adenosine.css b/adenosine-pds/templates/adenosine.css
new file mode 100644
index 0000000..0686f9e
--- /dev/null
+++ b/adenosine-pds/templates/adenosine.css
@@ -0,0 +1,626 @@
+/* This is simple.css, commit a73f11a: https://simplecss.org/
+ * adenosine styles are at the very bottom */
+/* Global variables. */
+:root {
+ /* Set sans-serif & mono fonts */
+ --sans-font: -apple-system, BlinkMacSystemFont, "Avenir Next", Avenir,
+ "Nimbus Sans L", Roboto, "Noto Sans", "Segoe UI", Arial, Helvetica,
+ "Helvetica Neue", sans-serif;
+ --mono-font: Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
+
+ /* Default (light) theme */
+ --bg: #fff;
+ --accent-bg: #f5f7ff;
+ --text: #212121;
+ --text-light: #585858;
+ --border: #898EA4;
+ --accent: #0d47a1;
+ --code: #d81b60;
+ --preformatted: #444;
+ --marked: #ffdd33;
+ --disabled: #efefef;
+}
+
+/* Dark theme */
+@media (prefers-color-scheme: dark) {
+ :root {
+ color-scheme: dark;
+ --bg: #212121;
+ --accent-bg: #2b2b2b;
+ --text: #dcdcdc;
+ --text-light: #ababab;
+ --accent: #ffb300;
+ --code: #f06292;
+ --preformatted: #ccc;
+ --disabled: #111;
+ }
+ /* Add a bit of transparency so light media isn't so glaring in dark mode */
+ img,
+ video {
+ opacity: 0.8;
+ }
+}
+
+/* Reset box-sizing */
+*, *::before, *::after {
+ box-sizing: border-box;
+}
+
+/* Reset default appearance */
+textarea,
+select,
+input,
+progress {
+ appearance: none;
+ -webkit-appearance: none;
+ -moz-appearance: none;
+}
+
+html {
+ /* Set the font globally */
+ font-family: var(--sans-font);
+ scroll-behavior: smooth;
+}
+
+/* Make the body a nice central block */
+body {
+ color: var(--text);
+ background-color: var(--bg);
+ font-size: 1.15rem;
+ line-height: 1.5;
+ display: grid;
+ grid-template-columns: 1fr min(45rem, 90%) 1fr;
+ margin: 0;
+}
+body > * {
+ grid-column: 2;
+}
+
+/* Make the header bg full width, but the content inline with body */
+body > header {
+ background-color: var(--accent-bg);
+ border-bottom: 1px solid var(--border);
+ text-align: center;
+ padding: 0 0.5rem 2rem 0.5rem;
+ grid-column: 1 / -1;
+}
+
+body > header h1 {
+ max-width: 1200px;
+ margin: 1rem auto;
+}
+
+body > header p {
+ max-width: 40rem;
+ margin: 1rem auto;
+}
+
+/* Add a little padding to ensure spacing is correct between content and header > nav */
+main {
+ padding-top: 1.5rem;
+}
+
+body > footer {
+ margin-top: 4rem;
+ padding: 2rem 1rem 1.5rem 1rem;
+ color: var(--text-light);
+ font-size: 0.9rem;
+ text-align: center;
+ border-top: 1px solid var(--border);
+}
+
+/* Format headers */
+h1 {
+ font-size: 3rem;
+}
+
+h2 {
+ font-size: 2.6rem;
+ margin-top: 3rem;
+}
+
+h3 {
+ font-size: 2rem;
+ margin-top: 3rem;
+}
+
+h4 {
+ font-size: 1.44rem;
+}
+
+h5 {
+ font-size: 1.15rem;
+}
+
+h6 {
+ font-size: 0.96rem;
+}
+
+/* Prevent long strings from overflowing container */
+p, h1, h2, h3, h4, h5, h6 {
+ overflow-wrap: break-word;
+}
+
+/* Fix line height when title wraps */
+h1,
+h2,
+h3 {
+ line-height: 1.1;
+}
+
+/* Reduce header size on mobile */
+@media only screen and (max-width: 720px) {
+ h1 {
+ font-size: 2.5rem;
+ }
+
+ h2 {
+ font-size: 2.1rem;
+ }
+
+ h3 {
+ font-size: 1.75rem;
+ }
+
+ h4 {
+ font-size: 1.25rem;
+ }
+}
+
+/* Format links & buttons */
+a,
+a:visited {
+ color: var(--accent);
+}
+
+a:hover {
+ text-decoration: none;
+}
+
+button,
+[role="button"],
+input[type="submit"],
+input[type="reset"],
+input[type="button"],
+label[type="button"] {
+ border: none;
+ border-radius: 5px;
+ background-color: var(--accent);
+ font-size: 1rem;
+ color: var(--bg);
+ padding: 0.7rem 0.9rem;
+ margin: 0.5rem 0;
+}
+
+button[disabled],
+[role="button"][aria-disabled="true"],
+input[type="submit"][disabled],
+input[type="reset"][disabled],
+input[type="button"][disabled],
+input[type="checkbox"][disabled],
+input[type="radio"][disabled],
+select[disabled] {
+ opacity: 0.5;
+ cursor: not-allowed;
+}
+
+input:disabled,
+textarea:disabled,
+select:disabled {
+ cursor: not-allowed;
+ background-color: var(--disabled);
+}
+
+input[type="range"] {
+ padding: 0;
+}
+
+/* Set the cursor to '?' on an abbreviation and style the abbreviation to show that there is more information underneath */
+abbr[title] {
+ cursor: help;
+ text-decoration-line: underline;
+ text-decoration-style: dotted;
+}
+
+button:focus,
+button:enabled:hover,
+[role="button"]:focus,
+[role="button"]:not([aria-disabled="true"]):hover,
+input[type="submit"]:focus,
+input[type="submit"]:enabled:hover,
+input[type="reset"]:focus,
+input[type="reset"]:enabled:hover,
+input[type="button"]:focus,
+input[type="button"]:enabled:hover,
+label[type="button"]:focus,
+label[type="button"]:hover {
+ filter: brightness(1.4);
+ cursor: pointer;
+}
+
+/* Format navigation */
+header > nav {
+ font-size: 1rem;
+ line-height: 2;
+ padding: 1rem 0 0 0;
+}
+
+/* Use flexbox to allow items to wrap, as needed */
+header > nav ul,
+header > nav ol {
+ align-content: space-around;
+ align-items: center;
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ justify-content: center;
+ list-style-type: none;
+ margin: 0;
+ padding: 0;
+}
+
+/* List items are inline elements, make them behave more like blocks */
+header > nav ul li,
+header > nav ol li {
+ display: inline-block;
+}
+
+header > nav a,
+header > nav a:visited {
+ margin: 0 0.5rem 1rem 0.5rem;
+ border: 1px solid var(--border);
+ border-radius: 5px;
+ color: var(--text);
+ display: inline-block;
+ padding: 0.1rem 1rem;
+ text-decoration: none;
+}
+
+header > nav a:hover {
+ border-color: var(--accent);
+ color: var(--accent);
+ cursor: pointer;
+}
+
+/* Reduce nav side on mobile */
+@media only screen and (max-width: 720px) {
+ header > nav a {
+ border: none;
+ padding: 0;
+ text-decoration: underline;
+ line-height: 1;
+ }
+}
+
+/* Consolidate box styling */
+aside, details, pre, progress {
+ background-color: var(--accent-bg);
+ border: 1px solid var(--border);
+ border-radius: 5px;
+ margin-bottom: 1rem;
+}
+
+aside {
+ font-size: 1rem;
+ width: 30%;
+ padding: 0 15px;
+ margin-left: 15px;
+ float: right;
+}
+
+/* Make aside full-width on mobile */
+@media only screen and (max-width: 720px) {
+ aside {
+ width: 100%;
+ float: none;
+ margin-left: 0;
+ }
+}
+
+article, fieldset {
+ border: 1px solid var(--border);
+ padding: 1rem;
+ border-radius: 5px;
+ margin-bottom: 1rem;
+}
+
+article h2:first-child,
+section h2:first-child {
+ margin-top: 1rem;
+}
+
+section {
+ border-top: 1px solid var(--border);
+ border-bottom: 1px solid var(--border);
+ padding: 2rem 1rem;
+ margin: 3rem 0;
+}
+
+/* Don't double separators when chaining sections */
+section + section,
+section:first-child {
+ border-top: 0;
+ padding-top: 0;
+}
+
+section:last-child {
+ border-bottom: 0;
+ padding-bottom: 0;
+}
+
+details {
+ padding: 0.7rem 1rem;
+}
+
+summary {
+ cursor: pointer;
+ font-weight: bold;
+ padding: 0.7rem 1rem;
+ margin: -0.7rem -1rem;
+ word-break: break-all;
+}
+
+details[open] > summary + * {
+ margin-top: 0;
+}
+
+details[open] > summary {
+ margin-bottom: 0.5rem;
+}
+
+details[open] > :last-child {
+ margin-bottom: 0;
+}
+
+/* Format tables */
+table {
+ border-collapse: collapse;
+ display: block;
+ margin: 1.5rem 0;
+ overflow: auto;
+ width: 100%;
+}
+
+td,
+th {
+ border: 1px solid var(--border);
+ text-align: left;
+ padding: 0.5rem;
+}
+
+th {
+ background-color: var(--accent-bg);
+ font-weight: bold;
+}
+
+tr:nth-child(even) {
+ /* Set every other cell slightly darker. Improves readability. */
+ background-color: var(--accent-bg);
+}
+
+table caption {
+ font-weight: bold;
+ margin-bottom: 0.5rem;
+}
+
+/* Format forms */
+textarea,
+select,
+input {
+ font-size: inherit;
+ font-family: inherit;
+ padding: 0.5rem;
+ margin-bottom: 0.5rem;
+ color: var(--text);
+ background-color: var(--bg);
+ border: 1px solid var(--border);
+ border-radius: 5px;
+ box-shadow: none;
+ max-width: 100%;
+ display: inline-block;
+}
+label {
+ display: block;
+}
+textarea:not([cols]) {
+ width: 100%;
+}
+
+/* Add arrow to drop-down */
+select:not([multiple]) {
+ background-image: linear-gradient(45deg, transparent 49%, var(--text) 51%),
+ linear-gradient(135deg, var(--text) 51%, transparent 49%);
+ background-position: calc(100% - 15px), calc(100% - 10px);
+ background-size: 5px 5px, 5px 5px;
+ background-repeat: no-repeat;
+ padding-right: 25px;
+}
+
+/* checkbox and radio button style */
+input[type="checkbox"],
+input[type="radio"] {
+ vertical-align: middle;
+ position: relative;
+ width: min-content;
+}
+
+input[type="checkbox"] + label,
+input[type="radio"] + label {
+ display: inline-block;
+}
+
+input[type="radio"] {
+ border-radius: 100%;
+}
+
+input[type="checkbox"]:checked,
+input[type="radio"]:checked {
+ background-color: var(--accent);
+}
+
+input[type="checkbox"]:checked::after {
+ /* Creates a rectangle with colored right and bottom borders which is rotated to look like a check mark */
+ content: " ";
+ width: 0.18em;
+ height: 0.32em;
+ border-radius: 0;
+ position: absolute;
+ top: 0.05em;
+ left: 0.17em;
+ background-color: transparent;
+ border-right: solid var(--bg) 0.08em;
+ border-bottom: solid var(--bg) 0.08em;
+ font-size: 1.8em;
+ transform: rotate(45deg);
+}
+input[type="radio"]:checked::after {
+ /* creates a colored circle for the checked radio button */
+ content: " ";
+ width: 0.25em;
+ height: 0.25em;
+ border-radius: 100%;
+ position: absolute;
+ top: 0.125em;
+ background-color: var(--bg);
+ left: 0.125em;
+ font-size: 32px;
+}
+
+/* Makes input fields wider on smaller screens */
+@media only screen and (max-width: 720px) {
+ textarea,
+ select,
+ input {
+ width: 100%;
+ }
+}
+
+/* Set a height for color input */
+input[type="color"] {
+ height: 2.5rem;
+ padding: 0.2rem;
+}
+
+/* do not show border around file selector button */
+input[type="file"] {
+ border: 0;
+}
+
+/* Misc body elements */
+hr {
+ border: none;
+ height: 1px;
+ background: var(--border);
+ margin: 1rem auto;
+}
+
+mark {
+ padding: 2px 5px;
+ border-radius: 4px;
+ background-color: var(--marked);
+}
+
+img,
+video {
+ max-width: 100%;
+ height: auto;
+ border-radius: 5px;
+}
+
+figure {
+ margin: 0;
+ text-align: center;
+}
+
+figcaption {
+ font-size: 0.9rem;
+ color: var(--text-light);
+ margin-bottom: 1rem;
+}
+
+blockquote {
+ margin: 2rem 0 2rem 2rem;
+ padding: 0.4rem 0.8rem;
+ border-left: 0.35rem solid var(--accent);
+ color: var(--text-light);
+ font-style: italic;
+}
+
+cite {
+ font-size: 0.9rem;
+ color: var(--text-light);
+ font-style: normal;
+}
+
+dt {
+ color: var(--text-light);
+}
+
+/* Use mono font for code elements */
+code,
+pre,
+pre span,
+kbd,
+samp {
+ font-family: var(--mono-font);
+ color: var(--code);
+}
+
+kbd {
+ color: var(--preformatted);
+ border: 1px solid var(--preformatted);
+ border-bottom: 3px solid var(--preformatted);
+ border-radius: 5px;
+ padding: 0.1rem 0.4rem;
+}
+
+pre {
+ padding: 1rem 1.4rem;
+ max-width: 100%;
+ overflow: auto;
+ color: var(--preformatted);
+}
+
+/* Fix embedded code within pre */
+pre code {
+ color: var(--preformatted);
+ background: none;
+ margin: 0;
+ padding: 0;
+}
+
+/* Progress bars */
+/* Declarations are repeated because you */
+/* cannot combine vendor-specific selectors */
+progress {
+ width: 100%;
+}
+
+progress:indeterminate {
+ background-color: var(--accent-bg);
+}
+
+progress::-webkit-progress-bar {
+ border-radius: 5px;
+ background-color: var(--accent-bg);
+}
+
+progress::-webkit-progress-value {
+ border-radius: 5px;
+ background-color: var(--accent);
+}
+
+progress::-moz-progress-bar {
+ border-radius: 5px;
+ background-color: var(--accent);
+ transition-property: width;
+ transition-duration: 0.3s;
+}
+
+progress:indeterminate::-moz-progress-bar {
+ background-color: var(--accent-bg);
+}
+
+/********** adenosine tweaks **********/
+body { font-family: var(--mono-font); }
+a { text-decoration: none; }
diff --git a/adenosine-pds/templates/at_collection.html b/adenosine-pds/templates/at_collection.html
new file mode 100644
index 0000000..b4b7036
--- /dev/null
+++ b/adenosine-pds/templates/at_collection.html
@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+
+{% block main %}
+<p><b>at://{{ did }}/{{ collection }}/</b>
+
+<p><b>records:</b>
+<ul>
+{% for record in records %}
+ <li><a href="/at/{{did}}/{{collection}}/{{record["tid"].as_str().unwrap() }}">{{ record["tid"].as_str().unwrap() }}</a>
+{% endfor %}
+</ul>
+{% endblock %}
diff --git a/adenosine-pds/templates/at_record.html b/adenosine-pds/templates/at_record.html
new file mode 100644
index 0000000..10ed838
--- /dev/null
+++ b/adenosine-pds/templates/at_record.html
@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block main %}
+<p><b>at://{{ did }}/{{ collection }}/{{ tid }}</b>
+
+<p><b>record json:</b>
+<pre><code>{{ record }}</code></pre>
+{% endblock %}
diff --git a/adenosine-pds/templates/at_repo.html b/adenosine-pds/templates/at_repo.html
new file mode 100644
index 0000000..dcf4d87
--- /dev/null
+++ b/adenosine-pds/templates/at_repo.html
@@ -0,0 +1,18 @@
+{% extends "base.html" %}
+
+{% block main %}
+<p><b>at://{{ did }}/</b>
+
+<p><b>collections:</b>
+<ul>
+{% for collection in describe.collections %}
+ <li><a href="/at/{{ did }}/{{ collection }}">{{collection}}/</a>
+{% endfor %}
+</ul>
+
+<p>repo commit:
+<pre><code>{{ "{:?}"|format(commit) }}</code></pre>
+
+<p>repo describe
+<pre><code>{{ "{:?}"|format(describe) }}</code></pre>
+{% endblock %}
diff --git a/adenosine-pds/templates/base.html b/adenosine-pds/templates/base.html
new file mode 100644
index 0000000..0ae2061
--- /dev/null
+++ b/adenosine-pds/templates/base.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="/static/adenosine.css" type="text/css">
+ <link rel="icon" href="/static/favicon.png" />
+ <title>{% block title -%}adenosine{%- endblock %}</title>
+ {% block head %}{% endblock %}
+ </head>
+ <body>
+ <nav>
+ <a href="/">
+ <h3>
+ <img src="/static/logo_128.png" width="64" height="64">{{ domain }}
+ </h3>
+ </a>
+ </nav>
+ <hr>
+ <main>
+ {% block main %}{% endblock %}
+ </main>
+ <hr>
+ <footer>
+ <nav>
+ <a href="/">home</a> -
+ <a href="/about">about</a> -
+ <a href="https://gitlab.com/bnewbold/adenosine">source code</a>
+ </nav>
+ </footer>
+ </body>
+</html>
diff --git a/adenosine-pds/templates/favicon.png b/adenosine-pds/templates/favicon.png
new file mode 100644
index 0000000..5be4e16
--- /dev/null
+++ b/adenosine-pds/templates/favicon.png
Binary files differ
diff --git a/adenosine-pds/templates/home.html b/adenosine-pds/templates/home.html
new file mode 100644
index 0000000..3854d4a
--- /dev/null
+++ b/adenosine-pds/templates/home.html
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+
+{% block content %}
+This is the homepage, which maybe would describe what adenosine is, and what
+this instance is specifically.
+
+{% endblock %}
diff --git a/adenosine-pds/templates/logo_128.png b/adenosine-pds/templates/logo_128.png
new file mode 100644
index 0000000..39ea824
--- /dev/null
+++ b/adenosine-pds/templates/logo_128.png
Binary files differ
diff --git a/adenosine-pds/templates/post.html b/adenosine-pds/templates/post.html
new file mode 100644
index 0000000..d7e6c85
--- /dev/null
+++ b/adenosine-pds/templates/post.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block post %}
+Post page (TODO)
+{% endblock %}
diff --git a/adenosine-pds/templates/profile.html b/adenosine-pds/templates/profile.html
new file mode 100644
index 0000000..7c17951
--- /dev/null
+++ b/adenosine-pds/templates/profile.html
@@ -0,0 +1,7 @@
+{% extends "base.html" %}
+
+{% block main %}
+<p><b>at://{{ did }}/</b>
+
+<p>Profile page (TODO)
+{% endblock %}
diff --git a/adenosine-pds/templates/robots.txt b/adenosine-pds/templates/robots.txt
new file mode 100644
index 0000000..2cba06f
--- /dev/null
+++ b/adenosine-pds/templates/robots.txt
@@ -0,0 +1 @@
+// this is the default adenosine PDS robots.txt file