add: global notes
This commit is contained in:
parent
59581f69c9
commit
2cd04b0db0
24 changed files with 371 additions and 608 deletions
|
@ -81,7 +81,7 @@ pub async fn app_request(
|
|||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user.clone())).await;
|
||||
|
||||
context.insert("selected_journal", &selected_journal);
|
||||
context.insert("selected_note", &selected_note);
|
||||
|
@ -89,6 +89,7 @@ pub async fn app_request(
|
|||
context.insert("journal", &journal);
|
||||
context.insert("note", ¬e);
|
||||
|
||||
context.insert("owner", &user);
|
||||
context.insert("journals", &journals);
|
||||
context.insert("notes", ¬es);
|
||||
|
||||
|
@ -185,6 +186,10 @@ pub async fn view_request(
|
|||
context.insert("selected_note", &0);
|
||||
} else {
|
||||
context.insert("selected_note", &selected_note);
|
||||
context.insert(
|
||||
"redis_views",
|
||||
&data.0.get_note_views(note.as_ref().unwrap().id).await,
|
||||
);
|
||||
}
|
||||
|
||||
context.insert("journal", &journal);
|
||||
|
@ -292,3 +297,70 @@ pub async fn index_view_request(
|
|||
// return
|
||||
Ok(Html(data.1.render("journals/app.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/x/{note}`
|
||||
pub async fn global_view_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(mut selected_note): Path<String>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => Some(ua),
|
||||
None => None,
|
||||
};
|
||||
|
||||
if selected_note == "index" {
|
||||
selected_note = String::new();
|
||||
}
|
||||
|
||||
// if we don't have a selected journal, we shouldn't be here probably
|
||||
if selected_note == "journal.css" {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &user).await,
|
||||
));
|
||||
}
|
||||
|
||||
// ...
|
||||
let note = match data.0.get_global_note_by_title(&selected_note).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
let journal = match data.0.get_journal_by_id(note.journal).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
};
|
||||
|
||||
// get owner
|
||||
let owner = match data.0.get_user_by_id(note.owner).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => {
|
||||
return Err(Html(render_error(e, &jar, &data, &user).await));
|
||||
}
|
||||
};
|
||||
|
||||
check_user_blocked_or_private!(user, owner, data, jar);
|
||||
|
||||
// ...
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &user).await;
|
||||
data.0.incr_note_views(note.id).await;
|
||||
|
||||
context.insert("selected_journal", ¬e.journal);
|
||||
context.insert("selected_note", &selected_note);
|
||||
context.insert("redis_views", &data.0.get_note_views(note.id).await);
|
||||
|
||||
context.insert("journal", &journal);
|
||||
context.insert("note", ¬e);
|
||||
|
||||
context.insert("owner", &owner);
|
||||
context.insert::<[i8; 0], &str>("notes", &[]);
|
||||
|
||||
context.insert("view_mode", &true);
|
||||
context.insert("is_editor", &false);
|
||||
context.insert("global_mode", &true);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("journals/app.html", &context).unwrap()))
|
||||
}
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
use axum::{
|
||||
extract::Path,
|
||||
response::{Html, IntoResponse},
|
||||
Extension,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{permissions::FinePermission, Error};
|
||||
use crate::{get_user_from_token, State};
|
||||
use super::render_error;
|
||||
|
||||
/// `/links/{id}`
|
||||
pub async fn navigate_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let link = match data.0.get_link_by_id(id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let owner = match data.0.get_user_by_id(link.owner).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
if owner.permissions.check(FinePermission::SUPPORTER) {
|
||||
if let Err(e) = data.0.incr_link_clicks(link.id).await {
|
||||
return Err(Html(render_error(e, &jar, &data, &Some(user)).await));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Html(format!(
|
||||
"<!doctype html /><html><head><meta http-equiv=\"refresh\" content=\"0; url={}\" /></head><body>Navigating...</body></html>",
|
||||
link.href
|
||||
)))
|
||||
}
|
|
@ -4,7 +4,6 @@ pub mod communities;
|
|||
pub mod developer;
|
||||
pub mod forge;
|
||||
pub mod journals;
|
||||
pub mod links;
|
||||
pub mod misc;
|
||||
pub mod mod_panel;
|
||||
pub mod profile;
|
||||
|
@ -138,8 +137,7 @@ pub fn routes() -> Router {
|
|||
.route("/journals/{journal}/{note}", get(journals::app_request))
|
||||
.route("/@{owner}/{journal}", get(journals::index_view_request))
|
||||
.route("/@{owner}/{journal}/{note}", get(journals::view_request))
|
||||
// links
|
||||
.route("/links/{id}", get(links::navigate_request))
|
||||
.route("/x/{note}", get(journals::global_view_request))
|
||||
}
|
||||
|
||||
pub async fn render_error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue