fix(#104): enforce storage quota on uploads & fix usage tracking
Backend: - Add QuotaExceeded error kind mapped to HTTP 507 Insufficient Storage - Add check_storage_quota() and get_user_storage_info() to StorageUsagePort - Enforce quota in upload_file_with_cache, upload_file_with_thumbnails (AuthUser extractor) - Enforce quota in chunked upload create_upload handler - Add update_user_storage_usage_by_username() for username-based lookup - Fix extract_username_from_path() to handle subfolders (take first segment only) - Fix maybe_update_storage_usage() to use username-based lookup instead of passing username to get_user_by_id (which always failed silently) Frontend: - Parse and display quota error messages on upload failure (507 / QuotaExceeded) - Stop remaining uploads when quota is exceeded - Call refreshUserData() after uploads to update storage usage display - Bump service worker cache to v9
This commit is contained in:
@@ -31,6 +31,8 @@ pub enum ErrorKind {
|
||||
UnsupportedOperation,
|
||||
/// Database error
|
||||
DatabaseError,
|
||||
/// Storage quota exceeded
|
||||
QuotaExceeded,
|
||||
}
|
||||
|
||||
impl Display for ErrorKind {
|
||||
@@ -45,6 +47,7 @@ impl Display for ErrorKind {
|
||||
ErrorKind::NotImplemented => write!(f, "Not Implemented"),
|
||||
ErrorKind::UnsupportedOperation => write!(f, "Unsupported Operation"),
|
||||
ErrorKind::DatabaseError => write!(f, "Database Error"),
|
||||
ErrorKind::QuotaExceeded => write!(f, "Quota Exceeded"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,6 +165,17 @@ impl DomainError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a storage quota exceeded error
|
||||
pub fn quota_exceeded<S: Into<String>>(message: S) -> Self {
|
||||
Self {
|
||||
kind: ErrorKind::QuotaExceeded,
|
||||
entity_type: "Storage",
|
||||
entity_id: None,
|
||||
message: message.into(),
|
||||
source: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a validation error
|
||||
pub fn validation_error<S: Into<String>>(message: S) -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user