app.utilities.helpersο
Helper utility functions for the Mail List Shield application.
This module provides general-purpose helper functions including file size formatting, code generation, and API key generation.
Functionsο
|
Convert a file size in bytes to a human-readable string. |
Generate a random n-digit numeric code. |
|
Generate a new API key and its bcrypt hash. |
Module Contentsο
- app.utilities.helpers.readable_file_size(size_in_bytes, significant_digits=0)[source]ο
Convert a file size in bytes to a human-readable string.
- Parameters:
size_in_bytes β The size in bytes to convert.
significant_digits β Number of decimal places to include.
- Returns:
Human-readable size string (e.g., β5 MBβ, β1.5 GBβ).
- Return type:
str
- app.utilities.helpers.generate_n_digit_code(n)[source]ο
Generate a random n-digit numeric code.
Each digit is between 1-9 (no zeros) for better readability.
- Parameters:
n β The number of digits in the code.
- Returns:
A string of n random digits.
- Return type:
str
- app.utilities.helpers.generate_api_key_and_hash()[source]ο
Generate a new API key and its bcrypt hash.
Creates a 64-character random API key and hashes it for secure storage.
- Returns:
- A tuple containing (plaintext_key, hashed_key).
The plaintext key should be shown to the user once, while the hash is stored in the database.
- Return type:
tuple