mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 03:20:46 +02:00
Clean up
This commit is contained in:
@@ -11,9 +11,40 @@ export interface FileWithUrl extends File {
|
||||
|
||||
export interface StorageConfig {
|
||||
useIndexedDB: boolean;
|
||||
// Simplified - no thresholds needed, IndexedDB for everything
|
||||
maxFileSize: number; // Maximum size per file in bytes
|
||||
maxTotalStorage: number; // Maximum total storage in bytes
|
||||
warningThreshold: number; // Warning threshold (percentage 0-1)
|
||||
}
|
||||
|
||||
export const defaultStorageConfig: StorageConfig = {
|
||||
useIndexedDB: true,
|
||||
maxFileSize: 100 * 1024 * 1024, // 100MB per file
|
||||
maxTotalStorage: 1024 * 1024 * 1024, // 1GB default, will be updated dynamically
|
||||
warningThreshold: 0.8, // Warn at 80% capacity
|
||||
};
|
||||
|
||||
// Calculate and update storage limit: half of available storage or 10GB, whichever is smaller
|
||||
export const initializeStorageConfig = async (): Promise<StorageConfig> => {
|
||||
const tenGB = 10 * 1024 * 1024 * 1024; // 10GB in bytes
|
||||
const oneGB = 1024 * 1024 * 1024; // 1GB fallback
|
||||
|
||||
let maxTotalStorage = oneGB; // Default fallback
|
||||
|
||||
// Try to estimate available storage
|
||||
if ('storage' in navigator && 'estimate' in navigator.storage) {
|
||||
try {
|
||||
const estimate = await navigator.storage.estimate();
|
||||
if (estimate.quota) {
|
||||
const halfQuota = estimate.quota / 2;
|
||||
maxTotalStorage = Math.min(halfQuota, tenGB);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Could not estimate storage quota, using 1GB default:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...defaultStorageConfig,
|
||||
maxTotalStorage
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user