2025-03-22 22:17:47 -04:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! write_template {
|
2025-03-23 12:31:48 -04:00
|
|
|
($into:ident->$path:literal($as:expr)) => {
|
|
|
|
std::fs::write($into.join($path), $as).unwrap();
|
2025-03-22 22:17:47 -04:00
|
|
|
};
|
|
|
|
|
2025-03-23 12:31:48 -04:00
|
|
|
($into:ident->$path:literal($as:expr) --config=$config:ident) => {
|
|
|
|
std::fs::write(
|
|
|
|
$into.join($path),
|
2025-03-31 15:39:49 -04:00
|
|
|
$crate::assets::replace_in_html($as, &$config).await,
|
2025-03-23 12:31:48 -04:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
};
|
|
|
|
|
|
|
|
($into:ident->$path:literal($as:expr) -d $dir_path:literal) => {
|
|
|
|
let dir = $into.join($dir_path);
|
2025-03-22 22:17:47 -04:00
|
|
|
if !std::fs::exists(&dir).unwrap() {
|
|
|
|
std::fs::create_dir(dir).unwrap();
|
|
|
|
}
|
|
|
|
|
2025-03-23 12:31:48 -04:00
|
|
|
std::fs::write($into.join($path), $as).unwrap();
|
|
|
|
};
|
|
|
|
|
|
|
|
($into:ident->$path:literal($as:expr) -d $dir_path:literal --config=$config:ident) => {
|
|
|
|
let dir = $into.join($dir_path);
|
|
|
|
if !std::fs::exists(&dir).unwrap() {
|
|
|
|
std::fs::create_dir(dir).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::fs::write(
|
|
|
|
$into.join($path),
|
2025-03-31 15:39:49 -04:00
|
|
|
$crate::assets::replace_in_html($as, &$config).await,
|
2025-03-23 12:31:48 -04:00
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! write_if_track {
|
|
|
|
($into:ident->$path:literal($as:expr) --config=$config:ident) => {
|
|
|
|
if !$config.no_track.contains(&$path.to_string()) {
|
|
|
|
write_template!($into->$path($as));
|
|
|
|
}
|
2025-03-22 22:17:47 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! create_dir_if_not_exists {
|
|
|
|
($dir_path:expr) => {
|
|
|
|
if !std::fs::exists(&$dir_path).unwrap() {
|
|
|
|
std::fs::create_dir($dir_path).unwrap();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! get_user_from_token {
|
2025-03-23 16:37:43 -04:00
|
|
|
($jar:ident, $db:expr) => {{
|
2025-03-22 22:17:47 -04:00
|
|
|
if let Some(token) = $jar.get("__Secure-atto-token") {
|
|
|
|
match $db
|
2025-03-23 12:31:48 -04:00
|
|
|
.get_user_by_token(&tetratto_shared::hash::hash(
|
2025-03-22 22:17:47 -04:00
|
|
|
token.to_string().replace("__Secure-atto-token=", ""),
|
|
|
|
))
|
|
|
|
.await
|
|
|
|
{
|
2025-04-02 11:39:51 -04:00
|
|
|
Ok(ua) => {
|
|
|
|
if ua.permissions.check_banned() {
|
|
|
|
Some(tetratto_core::model::auth::User::banned())
|
|
|
|
} else {
|
|
|
|
Some(ua)
|
|
|
|
}
|
|
|
|
}
|
2025-03-22 22:17:47 -04:00
|
|
|
Err(_) => None,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
2025-03-23 12:31:48 -04:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! get_lang {
|
|
|
|
($jar:ident, $db:expr) => {{
|
|
|
|
if let Some(lang) = $jar.get("__Secure-atto-lang") {
|
|
|
|
match $db
|
|
|
|
.1
|
|
|
|
.get(&lang.to_string().replace("__Secure-atto-lang=", ""))
|
|
|
|
{
|
|
|
|
Some(lang) => lang,
|
|
|
|
None => $db.1.get("com.tetratto.langs:en-US").unwrap(),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$db.1.get("com.tetratto.langs:en-US").unwrap()
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
2025-04-24 16:40:03 -04:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! check_user_blocked_or_private {
|
|
|
|
($user:ident, $other_user:ident, $data:ident, $jar:ident) => {
|
2025-05-16 21:29:25 -04:00
|
|
|
// check require_account
|
|
|
|
if $user.is_none() && $other_user.settings.require_account {
|
|
|
|
return Err(Html(
|
|
|
|
render_error(
|
|
|
|
Error::MiscError(
|
|
|
|
"This profile requires you are logged in to view it.".to_string(),
|
|
|
|
),
|
|
|
|
&$jar,
|
|
|
|
&$data,
|
|
|
|
&$user,
|
|
|
|
)
|
|
|
|
.await,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2025-05-16 00:25:44 -04:00
|
|
|
// check if other user is banned
|
|
|
|
if $other_user.permissions.check_banned() {
|
|
|
|
let lang = get_lang!($jar, $data.0);
|
|
|
|
let mut context = initial_context(&$data.0.0, lang, &$user).await;
|
|
|
|
context.insert("profile", &$other_user);
|
|
|
|
|
|
|
|
return Ok(Html(
|
|
|
|
$data.1.render("profile/banned.html", &context).unwrap(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2025-04-24 16:40:03 -04:00
|
|
|
// check if we're blocked
|
|
|
|
if let Some(ref ua) = $user {
|
|
|
|
if $data
|
|
|
|
.0
|
|
|
|
.get_userblock_by_initiator_receiver($other_user.id, ua.id)
|
|
|
|
.await
|
|
|
|
.is_ok()
|
2025-05-02 20:08:35 -04:00
|
|
|
&& !ua.permissions.check(FinePermission::MANAGE_USERS)
|
2025-04-24 16:40:03 -04:00
|
|
|
{
|
|
|
|
let lang = get_lang!($jar, $data.0);
|
|
|
|
let mut context = initial_context(&$data.0.0, lang, &$user).await;
|
|
|
|
|
|
|
|
context.insert("profile", &$other_user);
|
|
|
|
context.insert(
|
|
|
|
"is_blocking",
|
|
|
|
&$data
|
|
|
|
.0
|
|
|
|
.get_userblock_by_initiator_receiver(ua.id, $other_user.id)
|
|
|
|
.await
|
|
|
|
.is_ok(),
|
|
|
|
);
|
|
|
|
|
|
|
|
return Ok(Html(
|
|
|
|
$data.1.render("profile/blocked.html", &context).unwrap(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for private profile
|
|
|
|
if $other_user.settings.private_profile {
|
|
|
|
if let Some(ref ua) = $user {
|
|
|
|
if (ua.id != $other_user.id)
|
|
|
|
&& !ua.permissions.check(FinePermission::MANAGE_USERS)
|
|
|
|
&& $data
|
|
|
|
.0
|
|
|
|
.get_userfollow_by_initiator_receiver($other_user.id, ua.id)
|
|
|
|
.await
|
|
|
|
.is_err()
|
|
|
|
{
|
|
|
|
let lang = get_lang!($jar, $data.0);
|
|
|
|
let mut context = initial_context(&$data.0.0, lang, &$user).await;
|
|
|
|
|
|
|
|
context.insert("profile", &$other_user);
|
|
|
|
context.insert(
|
|
|
|
"follow_requested",
|
|
|
|
&$data
|
|
|
|
.0
|
|
|
|
.get_request_by_id_linked_asset(ua.id, $other_user.id)
|
|
|
|
.await
|
|
|
|
.is_ok(),
|
|
|
|
);
|
|
|
|
context.insert(
|
|
|
|
"is_blocking",
|
|
|
|
&$data
|
|
|
|
.0
|
|
|
|
.get_userblock_by_initiator_receiver(ua.id, $other_user.id)
|
|
|
|
.await
|
|
|
|
.is_ok(),
|
|
|
|
);
|
2025-05-07 21:54:21 -04:00
|
|
|
context.insert(
|
|
|
|
"is_following",
|
|
|
|
&$data
|
|
|
|
.0
|
|
|
|
.get_userfollow_by_initiator_receiver(ua.id, $other_user.id)
|
|
|
|
.await
|
|
|
|
.is_ok(),
|
|
|
|
);
|
2025-04-24 16:40:03 -04:00
|
|
|
|
|
|
|
return Ok(Html(
|
|
|
|
$data.1.render("profile/private.html", &context).unwrap(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let lang = get_lang!($jar, $data.0);
|
|
|
|
let mut context = initial_context(&$data.0.0, lang, &$user).await;
|
|
|
|
|
|
|
|
context.insert("profile", &$other_user);
|
|
|
|
context.insert("follow_requested", &false);
|
|
|
|
context.insert("is_following", &false);
|
|
|
|
|
|
|
|
return Ok(Html(
|
|
|
|
$data.1.render("profile/private.html", &context).unwrap(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|