2 Commits

Author SHA1 Message Date
9a1256f005 Update dependency @eslint/js to ^9.39.1
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2025-11-04 00:14:00 +00:00
4cd448208b Improve backend code quality
Some checks failed
continuous-integration/drone/push Build is failing
2025-11-03 19:08:46 +01:00
8 changed files with 39 additions and 62 deletions

View File

@@ -22,10 +22,6 @@ pub struct AppConfig {
#[clap(short = 'S', long, env, default_value = "")]
secret: String,
/// Specify whether the cookie should be transmitted only over secure connections
#[clap(long, env)]
pub cookie_secure: bool,
/// Unsecure : for development, bypass authentication, using the account with the given
/// email address by default
#[clap(long, env)]
@@ -161,23 +157,6 @@ impl AppConfig {
self.unsecure_auto_login_email().is_some()
}
/// Get auth cookie domain
pub fn cookie_domain(&self) -> Option<String> {
if cfg!(debug_assertions) {
let domain = self.website_origin.split_once("://")?.1;
Some(
domain
.split_once(':')
.map(|s| s.0)
.unwrap_or(domain)
.to_string(),
)
} else {
// In release mode, the web app is hosted on the same origin as the API
None
}
}
/// Get app secret
pub fn secret(&self) -> &str {
let mut secret = self.secret.as_str();

View File

@@ -63,24 +63,23 @@ pub async fn download(
pub async fn serve_file(req: HttpRequest, file: &File, download_file: bool) -> HttpResult {
if !download_file {
// Check if the browser already knows the etag
if let Some(c) = req.headers().get(header::IF_NONE_MATCH) {
if c.to_str().unwrap_or("") == file.sha512.as_str() {
if let Some(c) = req.headers().get(header::IF_NONE_MATCH)
&& c.to_str().unwrap_or("") == file.sha512.as_str()
{
return Ok(HttpResponse::NotModified().finish());
}
}
// Check if the browser already knows the file by date
if let Some(c) = req.headers().get(header::IF_MODIFIED_SINCE) {
let date_str = c.to_str().unwrap_or("");
if let Ok(date) = httpdate::parse_http_date(date_str) {
if date.add(Duration::from_secs(1))
if let Ok(date) = httpdate::parse_http_date(date_str)
&& date.add(Duration::from_secs(1))
>= time_utils::unix_to_system_time(file.time_create as u64)
{
return Ok(HttpResponse::NotModified().finish());
}
}
}
}
let mut res = HttpResponse::Ok();
res.content_type(file.mime_type.as_str())
.insert_header(("etag", file.sha512.as_str()))

View File

@@ -64,11 +64,11 @@ pub async fn get_list_of_account(
});
}
if let Some(limit) = query.limit {
if list.len() > limit {
if let Some(limit) = query.limit
&& list.len() > limit
{
list = list[..limit].to_vec();
}
}
Ok(HttpResponse::Ok().json(list))
}

View File

@@ -120,8 +120,9 @@ impl FromRequest for AuthExtractor {
}
// Check IP restriction
if let Some(net) = token.ip_net() {
if !net.contains(&remote_ip.0) {
if let Some(net) = token.ip_net()
&& !net.contains(&remote_ip.0)
{
log::error!(
"Trying to use token {:?} from unauthorized IP address: {remote_ip:?}",
token.id()
@@ -130,7 +131,6 @@ impl FromRequest for AuthExtractor {
"This token cannot be used from this IP address!",
));
}
}
// Check for write access
if token.read_only && !req.method().is_safe() {
@@ -163,11 +163,11 @@ impl FromRequest for AuthExtractor {
};
// Update last use (if needed)
if token.shall_update_time_used() {
if let Err(e) = tokens_service::update_time_used(&token).await {
if token.shall_update_time_used()
&& let Err(e) = tokens_service::update_time_used(&token).await
{
log::error!("Failed to refresh last usage of token! {e}");
}
}
// Handle tokens expiration
if token.is_expired() {

View File

@@ -23,11 +23,11 @@ impl UpdateInboxEntryQuery {
let constraints = ServerConstraints::default();
// Check inbox entry label
if let Some(label) = &self.label {
if !constraints.inbox_entry_label.check_str(label) {
if let Some(label) = &self.label
&& !constraints.inbox_entry_label.check_str(label)
{
return Ok(Some("Invalid inbox entry label length!"));
}
}
// Check the referenced movement
if let Some(movement_id) = self.movement_id {

View File

@@ -55,13 +55,12 @@ impl UpdateMovementQuery {
if let Ok(movement) =
get_by_account_label_amount_time(self.account_id, &self.label, self.amount, self.time)
.await
&& Some(movement.id()) != ref_movement
{
if Some(movement.id()) != ref_movement {
return Ok(Some(
"A movement taken at the same time with the same label and the same amount already exists!",
));
}
}
Ok(None)
}

View File

@@ -30,7 +30,7 @@
"ts-pattern": "^5.8.0"
},
"devDependencies": {
"@eslint/js": "^9.38.0",
"@eslint/js": "^9.39.1",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"@vitejs/plugin-react": "^4.7.0",
@@ -1877,9 +1877,9 @@
}
},
"node_modules/@eslint/js": {
"version": "9.38.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.38.0.tgz",
"integrity": "sha512-UZ1VpFvXf9J06YG9xQBdnzU+kthors6KjhMAl6f4gH4usHyh31rUf2DLGInT8RFYIReYXNSydgPY0V2LuWgl7A==",
"version": "9.39.1",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.1.tgz",
"integrity": "sha512-S26Stp4zCy88tH94QbBv3XCuzRQiZ9yXofEILmglYTh/Ug/a9/umqvgFtYBAo3Lp0nsI/5/qH1CCrbdK3AP1Tw==",
"dev": true,
"license": "MIT",
"engines": {

View File

@@ -32,7 +32,7 @@
"ts-pattern": "^5.8.0"
},
"devDependencies": {
"@eslint/js": "^9.38.0",
"@eslint/js": "^9.39.1",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"@vitejs/plugin-react": "^4.7.0",