add: littleweb full

This commit is contained in:
trisua 2025-07-08 13:35:23 -04:00
parent 3fc0872867
commit d67e7c9c33
32 changed files with 1699 additions and 71 deletions

View file

@ -3,15 +3,12 @@ use crate::{
routes::api::v1::{CreateDomain, UpdateDomainData},
State,
};
use axum::{
extract::{Path, Query},
response::IntoResponse,
http::StatusCode,
Extension, Json,
};
use axum::{extract::Path, response::IntoResponse, http::StatusCode, Extension, Json};
use axum_extra::extract::CookieJar;
use tetratto_core::model::{littleweb::Domain, oauth, ApiReturn, Error};
use serde::Deserialize;
use tetratto_core::model::{
littleweb::{Domain, ServiceFsMime},
oauth, ApiReturn, Error,
};
pub async fn get_request(
Path(id): Path<usize>,
@ -112,17 +109,12 @@ pub async fn delete_request(
}
}
#[derive(Deserialize)]
pub struct GetFileQuery {
pub addr: String,
}
pub async fn get_file_request(
Path(addr): Path<String>,
Extension(data): Extension<State>,
Query(props): Query<GetFileQuery>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let (subdomain, domain, tld, path) = Domain::from_str(&props.addr);
let (subdomain, domain, tld, path) = Domain::from_str(&addr);
// resolve domain
let domain = match data.get_domain_by_name_tld(&domain, &tld).await {
@ -150,9 +142,19 @@ pub async fn get_file_request(
// resolve file
match service.file(&path) {
Some(f) => Ok((
Some((f, _)) => Ok((
[("Content-Type".to_string(), f.mime.to_string())],
f.content,
if f.mime == ServiceFsMime::Html {
f.content.replace(
"</body>",
&format!(
"<script src=\"{}/js/proto_links.js\" defer></script></body>",
data.0.0.host
),
)
} else {
f.content
},
)),
None => {
return Err((