mirror of
https://github.com/DumbWareio/DumbDrop.git
synced 2025-10-23 07:41:58 +00:00
added storage placeholder for total size of upload folder
This commit is contained in:
@@ -10,5 +10,5 @@ DUMBDROP_PIN= # Optional PIN protection (4-10 digits, leave empty to
|
||||
|
||||
# Notifications
|
||||
APPRISE_URL= # Apprise URL for notifications (leave empty to disable)
|
||||
APPRISE_MESSAGE= # Custom message for notifications (default: "New file uploaded: {filename} ({size})")
|
||||
APPRISE_MESSAGE= # Custom message for notifications (default: "New file uploaded: {filename} ({size}), Storage used: {storage}")
|
||||
APPRISE_SIZE_UNIT= # Size unit for notifications (B, KB, MB, GB, TB). Leave empty for auto
|
||||
|
@@ -30,23 +30,26 @@ No auth (unless you want it now!), no storage, no nothing. Just a simple file up
|
||||
| DUMBDROP_PIN | PIN protection (4-10 digits) | None | No |
|
||||
| DUMBDROP_TITLE | Site title displayed in header | DumbDrop| No |
|
||||
| APPRISE_URL | Apprise URL for notifications | None | No |
|
||||
| APPRISE_MESSAGE | Notification message template | "New file uploaded: {filename} ({size})" | No |
|
||||
| APPRISE_MESSAGE | Notification message template | New file uploaded {filename} ({size}), Storage used {storage} | No |
|
||||
| APPRISE_SIZE_UNIT| Size unit for notifications | Auto | No |
|
||||
|
||||
## Notification Templates
|
||||
The notification message supports the following placeholders:
|
||||
- `{filename}`: Name of the uploaded file
|
||||
- `{size}`: Size of the file (formatted according to APPRISE_SIZE_UNIT)
|
||||
- `{storage}`: Total size of all files in upload directory
|
||||
|
||||
Example message template:
|
||||
```env
|
||||
APPRISE_MESSAGE="New file uploaded: {filename} ({size})"
|
||||
APPRISE_MESSAGE: New file uploaded {filename} ({size}), Storage used {storage}
|
||||
```
|
||||
|
||||
Size formatting examples:
|
||||
- Auto (default): Chooses nearest unit (e.g., "1.44MB", "256KB")
|
||||
- Fixed unit: Set APPRISE_SIZE_UNIT to B, KB, MB, GB, or TB
|
||||
|
||||
Both {size} and {storage} use the same formatting rules based on APPRISE_SIZE_UNIT.
|
||||
|
||||
## Security Features
|
||||
|
||||
- Variable-length PIN support (4-10 digits)
|
||||
|
@@ -6,7 +6,11 @@ services:
|
||||
volumes:
|
||||
- ./local_uploads:/app/uploads
|
||||
environment:
|
||||
- DUMBDROP_PIN=123456
|
||||
- APPRISE_URL= # i.e. tgram://bottoken/ChatID
|
||||
- APPRISE_MESSAGE= # dont add quotes here
|
||||
image: abite3/dumbdrop:latest
|
||||
DUMBDROP_TITLE: DumbDrop fo shizzle
|
||||
MAX_FILE_SIZE: 1024
|
||||
DUMBDROP_PIN: 123456
|
||||
# APPRISE_URL: ntfys://
|
||||
APPRISE_MESSAGE: New file uploaded - {filename} ({size}), Storage used {storage}
|
||||
APPRISE_SIZE_UNIT: auto
|
||||
image: abite3/dumbdrop:latest
|
||||
# build: .
|
27
server.js
27
server.js
@@ -15,7 +15,7 @@ const port = process.env.PORT || 3000;
|
||||
const uploadDir = './uploads'; // Local development
|
||||
const maxFileSize = parseInt(process.env.MAX_FILE_SIZE || '1024') * 1024 * 1024; // Convert MB to bytes
|
||||
const APPRISE_URL = process.env.APPRISE_URL;
|
||||
const APPRISE_MESSAGE = process.env.APPRISE_MESSAGE || 'New file uploaded: {filename} ({size})';
|
||||
const APPRISE_MESSAGE = process.env.APPRISE_MESSAGE || 'New file uploaded - {filename} ({size}), Storage used: {storage}';
|
||||
const siteTitle = process.env.DUMBDROP_TITLE || 'DumbDrop';
|
||||
const APPRISE_SIZE_UNIT = process.env.APPRISE_SIZE_UNIT;
|
||||
|
||||
@@ -373,18 +373,37 @@ function formatFileSize(bytes) {
|
||||
return size.toFixed(2) + units[unitIndex];
|
||||
}
|
||||
|
||||
// Add this helper function
|
||||
function calculateDirectorySize(directoryPath) {
|
||||
let totalSize = 0;
|
||||
const files = fs.readdirSync(directoryPath);
|
||||
|
||||
files.forEach(file => {
|
||||
const filePath = path.join(directoryPath, file);
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.isFile()) {
|
||||
totalSize += stats.size;
|
||||
}
|
||||
});
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
// Modify the sendNotification function
|
||||
async function sendNotification(filename, fileSize) {
|
||||
if (!APPRISE_URL) return;
|
||||
|
||||
try {
|
||||
const formattedSize = formatFileSize(fileSize); // No await needed here
|
||||
const formattedSize = formatFileSize(fileSize);
|
||||
const totalStorage = formatFileSize(calculateDirectorySize(uploadDir));
|
||||
const message = APPRISE_MESSAGE
|
||||
.replace('{filename}', filename)
|
||||
.replace('{size}', formattedSize);
|
||||
.replace('{size}', formattedSize)
|
||||
.replace('{storage}', totalStorage);
|
||||
|
||||
// Execute apprise command
|
||||
await execAsync(`apprise "${APPRISE_URL}" -b "${message}"`);
|
||||
log.info(`Notification sent for: ${filename} (${formattedSize})`);
|
||||
log.info(`Notification sent for: ${filename} (${formattedSize}, Total storage: ${totalStorage})`);
|
||||
} catch (err) {
|
||||
log.error(`Failed to send notification: ${err.message}`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user