add: service edit date + browser session ids
This commit is contained in:
parent
9aee80493f
commit
cfcc2358f4
17 changed files with 148 additions and 29 deletions
|
@ -3,13 +3,21 @@ use crate::{
|
|||
routes::api::v1::{CreateDomain, UpdateDomainData},
|
||||
State,
|
||||
};
|
||||
use axum::{extract::Path, response::IntoResponse, http::StatusCode, Extension, Json};
|
||||
use axum::{
|
||||
extract::{Path, Query},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
Extension, Json,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{
|
||||
auth::AchievementName,
|
||||
littleweb::{Domain, ServiceFsMime},
|
||||
oauth, ApiReturn, Error,
|
||||
oauth,
|
||||
permissions::FinePermission,
|
||||
ApiReturn, Error,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub async fn get_request(
|
||||
Path(id): Path<usize>,
|
||||
|
@ -119,9 +127,16 @@ pub async fn delete_request(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GetFileQuery {
|
||||
#[serde(default, alias = "s")]
|
||||
pub session: String,
|
||||
}
|
||||
|
||||
pub async fn get_file_request(
|
||||
Path(mut addr): Path<String>,
|
||||
Extension(data): Extension<State>,
|
||||
Query(props): Query<GetFileQuery>,
|
||||
) -> impl IntoResponse {
|
||||
if !addr.starts_with("atto://") {
|
||||
addr = format!("atto://{addr}");
|
||||
|
@ -129,8 +144,21 @@ pub async fn get_file_request(
|
|||
|
||||
// ...
|
||||
let data = &(data.read().await).0;
|
||||
let user = get_user_from_token!(--browser_session = props.session, data);
|
||||
let (subdomain, domain, tld, path) = Domain::from_str(&addr);
|
||||
|
||||
if path.starts_with("$") && user.is_none() {
|
||||
return Err((StatusCode::BAD_REQUEST, Error::NotAllowed.to_string()));
|
||||
} else if let Some(ref ua) = user
|
||||
&& path.starts_with("$paid")
|
||||
&& !ua.permissions.check(FinePermission::SUPPORTER)
|
||||
{
|
||||
return Err((
|
||||
StatusCode::BAD_REQUEST,
|
||||
Error::RequiresSupporter.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
// resolve domain
|
||||
let domain = match data.get_domain_by_name_tld(&domain, &tld).await {
|
||||
Ok(x) => x,
|
||||
|
@ -160,17 +188,28 @@ pub async fn get_file_request(
|
|||
Some((f, _)) => Ok((
|
||||
[("Content-Type".to_string(), f.mime.to_string())],
|
||||
if f.mime == ServiceFsMime::Html {
|
||||
f.content.replace(
|
||||
"</body>",
|
||||
&format!(
|
||||
"<script src=\"{}/js/proto_links.js\" defer></script></body>",
|
||||
data.0.0.host
|
||||
),
|
||||
)
|
||||
f.content
|
||||
.replace(
|
||||
"</body>",
|
||||
&format!(
|
||||
"<script src=\"{}/js/proto_links.js\" defer></script><script>
|
||||
globalThis.SECRET_SESSION = \"{}\";
|
||||
</script></body>",
|
||||
data.0.0.host, props.session
|
||||
),
|
||||
)
|
||||
.replace(
|
||||
".js\"",
|
||||
&format!(".js?r={}&s={}\"", service.revision, props.session),
|
||||
)
|
||||
.replace(
|
||||
".css\"",
|
||||
&format!(".css?r={}&s={}\"", service.revision, props.session),
|
||||
)
|
||||
} else {
|
||||
f.content
|
||||
}
|
||||
.replace("atto://", "/api/v1/net/atto://"),
|
||||
.replace("atto://", "/api/v1/net/"),
|
||||
)),
|
||||
None => {
|
||||
return Err((
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
|||
use axum::{extract::Path, response::IntoResponse, Extension, Json};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{auth::AchievementName, littleweb::Service, oauth, ApiReturn, Error};
|
||||
use tetratto_shared::unix_epoch_timestamp;
|
||||
|
||||
pub async fn get_request(
|
||||
Path(id): Path<usize>,
|
||||
|
@ -156,11 +157,17 @@ pub async fn update_content_request(
|
|||
|
||||
// ...
|
||||
match data.update_service_files(id, &user, service.files).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Service updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Ok(_) => match data
|
||||
.update_service_revision(id, unix_epoch_timestamp() as i64)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Service updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
},
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue