fix: display unlimited quota (∞) when storage_quota_bytes = 0

- Added formatQuotaSize() function to display ∞ for unlimited (0) quota
- Added format_quota_size() Rust function matching JavaScript behavior
- Updated quota defaulting logic from '||' to '== null' check
- This allows 0 (unlimited) to pass through while defaulting to 10 GB
  only when the value is null/undefined
- Call sites now use dedicated formatQuotaSize() or format_quota_size()
  instead of options parameter for cleaner API
This commit is contained in:
George Wu
2026-02-20 19:02:01 -08:00
parent 269a5fe940
commit 283a80a302
4 changed files with 34 additions and 7 deletions
+19
View File
@@ -367,6 +367,16 @@ pub fn format_file_size(bytes: u64) -> String {
format!("{} {}", formatted, SIZES[i])
}
/// Formats a byte count for quota display. When bytes is 0, returns "∞" (unlimited).
///
/// Matches the JavaScript `formatQuotaSize()` output.
pub fn format_quota_size(bytes: u64) -> String {
if bytes == 0 {
return "∞".to_string();
}
format_file_size(bytes)
}
#[cfg(test)]
mod tests {
use super::*;
@@ -382,6 +392,15 @@ mod tests {
assert_eq!(format_file_size(1_073_741_824), "1 GB");
}
#[test]
fn test_format_quota_size() {
// Unlimited quota (0) should show infinity symbol
assert_eq!(format_quota_size(0), "∞");
// Non-zero values should format normally
assert_eq!(format_quota_size(500), "500 Bytes");
assert_eq!(format_quota_size(1_073_741_824), "1 GB");
}
#[test]
fn test_icon_class_for_with_extension_fallback() {
// Specific MIME types