π UserFileManager
UserFileManager handles user file operations inside products, including uploads, downloads, renames, deletes, and recycle bin functionality.
1const ufm = new DBMS.UserFileManager("Alice@example.com");
π Works per user and integrates with UserDB and ProductDB.
π Files are isolated per product to maintain safety.
β Create / Upload File
1await ufm.upload(req, "Alice@example.com", "Product1", "rename");
-
Handles HTTP file uploads via
formidable. -
Supports collision modes:
'skip'β skip if file exists'overwrite'β replace existing'rename'β auto-rename new file
-
Validates quota (
maxBytes) before saving. -
Stores files in:
/Users/Ae/Alice@example.com/Product1/<fileName>
- Adds metadata and tracks usage in the productβs config.
π Read File
1const content = await ufm.readFileContent("Alice@example.com", "Product1", "myfile.txt");
- Returns text content only (binary files will throw an error).
βοΈ Update File
1await ufm.updateFileContent("Alice@example.com", "Product1", "myfile.txt", "Updated text");
- Replaces file content.
- Validates text content.
- Updates usage tracking.
β Delete File
1await ufm.deleteFile("Alice@example.com", "Product1", "myfile.txt");
- Deletes a file.
- Updates usage accordingly.
π¦ Delete All Files in Product
1await ufm.deleteAllFiles("Alice@example.com", "Product1");
- Deletes all files/folders inside a product.
- Skips .config folder.
- Resets usage in config.
π Rename / Move File
1await ufm.renameFile("Alice@example.com", "Product1", "old.txt", "new.txt");2await ufm.moveFile("Alice@example.com", "Product1", "old.txt", "folder/new.txt");
- Moves or renames files safely inside product directories.
- Validates safe paths.
π Create Folder
1await ufm.createFolder("Alice@example.com", "Product1", "newFolder");
- Creates a directory inside a product.
π Recycle Bin
- Move to Bin:
1await ufm.BinFile("Alice@example.com", "Product1", "file.txt");
- Recover File:
1await ufm.RecoverFile("Alice@example.com", "Product1", "file.txt.hbhbin");
- List Trash:
1const trashFiles = await ufm.ListTrash("Alice@example.com", "Product1");
- Empty Trash:
1await ufm.EmptyTrash("Alice@example.com", "Product1");
π List Files / Directories
1await ufm.listFlat("Alice@example.com", "Product1"); // flat list2await ufm.listTree("Alice@example.com", "Product1"); // tree structure3await ufm.listDir("Alice@example.com", "Product1"); // directories only
- Filters .config folders automatically.
- Returns full metadata for files in tree/flat listings.
π Usage Info
1const { used, limit } = await ufm.usage("Alice@example.com", "Product1");
usedβ total bytes usedlimitβ maximum allowed bytes (defaultMAX_USER_STORAGE_BYTES)
βοΈ Product Management
1await ufm.createProduct("Product1");2await ufm.deleteProduct("Product1");
- Creates a product with initial config.
- Deletes product safely, including files.