add: small littleweb browser changes

This commit is contained in:
trisua 2025-07-08 17:38:24 -04:00
parent e7febc7c7e
commit 388ccbf58c
9 changed files with 194 additions and 21 deletions

View file

@ -110,9 +110,14 @@ pub async fn delete_request(
}
pub async fn get_file_request(
Path(addr): Path<String>,
Path(mut addr): Path<String>,
Extension(data): Extension<State>,
) -> impl IntoResponse {
if !addr.starts_with("atto://") {
addr = format!("atto://{addr}");
}
// ...
let data = &(data.read().await).0;
let (subdomain, domain, tld, path) = Domain::from_str(&addr);

View file

@ -1,18 +1,22 @@
use super::render_error;
use crate::{assets::initial_context, get_lang, get_user_from_token, State};
use crate::{
assets::initial_context, get_lang, get_user_from_token,
routes::pages::misc::NotificationsProps, State,
};
use axum::{
response::{Html, IntoResponse},
extract::{Query, Path},
Extension,
};
use axum_extra::extract::CookieJar;
use tetratto_core::model::{littleweb::TLDS_VEC, Error};
use tetratto_core::model::{littleweb::TLDS_VEC, permissions::SecondaryPermission, Error};
use serde::Deserialize;
/// `/services`
pub async fn services_request(
jar: CookieJar,
Extension(data): Extension<State>,
Query(props): Query<NotificationsProps>,
) -> impl IntoResponse {
let data = data.read().await;
let user = match get_user_from_token!(jar, data.0) {
@ -24,7 +28,26 @@ pub async fn services_request(
}
};
let list = match data.0.get_services_by_user(user.id).await {
let profile = if props.id != 0 {
match data.0.get_user_by_id(props.id).await {
Ok(x) => x,
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
}
} else {
user.clone()
};
if profile.id != user.id
&& !user
.secondary_permissions
.check(SecondaryPermission::MANAGE_SERVICES)
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
let list = match data.0.get_services_by_user(profile.id).await {
Ok(x) => x,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
@ -32,6 +55,7 @@ pub async fn services_request(
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
context.insert("list", &list);
context.insert("profile", &profile);
// return
Ok(Html(
@ -43,6 +67,7 @@ pub async fn services_request(
pub async fn domains_request(
jar: CookieJar,
Extension(data): Extension<State>,
Query(props): Query<NotificationsProps>,
) -> impl IntoResponse {
let data = data.read().await;
let user = match get_user_from_token!(jar, data.0) {
@ -54,6 +79,25 @@ pub async fn domains_request(
}
};
let profile = if props.id != 0 {
match data.0.get_user_by_id(props.id).await {
Ok(x) => x,
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
}
} else {
user.clone()
};
if profile.id != user.id
&& !user
.secondary_permissions
.check(SecondaryPermission::MANAGE_DOMAINS)
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
}
let list = match data.0.get_domains_by_user(user.id).await {
Ok(x) => x,
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
@ -64,6 +108,7 @@ pub async fn domains_request(
context.insert("list", &list);
context.insert("tlds", &*TLDS_VEC);
context.insert("profile", &profile);
// return
Ok(Html(
@ -99,7 +144,11 @@ pub async fn service_request(
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
if user.id != service.owner {
if user.id != service.owner
&& !user
.secondary_permissions
.check(SecondaryPermission::MANAGE_SERVICES)
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
@ -153,7 +202,11 @@ pub async fn domain_request(
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
};
if user.id != domain.owner {
if user.id != domain.owner
&& !user
.secondary_permissions
.check(SecondaryPermission::MANAGE_DOMAINS)
{
return Err(Html(
render_error(Error::NotAllowed, &jar, &data, &None).await,
));
@ -204,7 +257,7 @@ pub async fn browser_request(
let lang = get_lang!(jar, data.0);
let mut context = initial_context(&data.0.0.0, lang, &user).await;
context.insert("path", &uri);
context.insert("path", &uri.replace("atto://", ""));
// return
Html(data.1.render("littleweb/browser.html", &context).unwrap())