@riligar/elysia-backup 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -5
- package/package.json +1 -1
- package/src/core/config.js +3 -1
- package/src/index.js +4 -2
package/README.md
CHANGED
|
@@ -41,7 +41,6 @@ const app = new Elysia()
|
|
|
41
41
|
.use(
|
|
42
42
|
r2Backup({
|
|
43
43
|
sourceDir: './data',
|
|
44
|
-
configPath: './backup-config.json',
|
|
45
44
|
})
|
|
46
45
|
)
|
|
47
46
|
.listen(3000)
|
|
@@ -60,10 +59,10 @@ On first run, you'll be guided through an onboarding wizard to configure:
|
|
|
60
59
|
|
|
61
60
|
### Plugin Options
|
|
62
61
|
|
|
63
|
-
| Option | Type | Required | Description
|
|
64
|
-
| ------------ | ------ | -------- |
|
|
65
|
-
| `sourceDir` | string | ✅ | Local directory to backup
|
|
66
|
-
| `configPath` | string | ❌ | Path to save runtime config (default:
|
|
62
|
+
| Option | Type | Required | Description |
|
|
63
|
+
| ------------ | ------ | -------- | ------------------------------------------------------------------- |
|
|
64
|
+
| `sourceDir` | string | ✅ | Local directory to backup |
|
|
65
|
+
| `configPath` | string | ❌ | Path to save runtime config (default: same directory as `sourceDir`) |
|
|
67
66
|
|
|
68
67
|
### Runtime Configuration (via UI or backup-config.json)
|
|
69
68
|
|
|
@@ -119,6 +118,27 @@ The plugin adds the following routes under `/backup`:
|
|
|
119
118
|
| POST | `/backup/api/totp/verify` | Verify and enable 2FA |
|
|
120
119
|
| POST | `/backup/api/totp/disable` | Disable 2FA |
|
|
121
120
|
|
|
121
|
+
## ☁️ Cloud Deployment (Fly.io, Railway, etc.)
|
|
122
|
+
|
|
123
|
+
For cloud platforms with ephemeral file systems, mount a persistent volume at your `sourceDir` path. The configuration file will be automatically saved alongside your data:
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { Elysia } from 'elysia'
|
|
127
|
+
import { r2Backup } from '@riligar/elysia-backup'
|
|
128
|
+
|
|
129
|
+
const app = new Elysia()
|
|
130
|
+
.use(
|
|
131
|
+
r2Backup({
|
|
132
|
+
// Mount your persistent volume here
|
|
133
|
+
// Config will be saved at /data/backup-config.json
|
|
134
|
+
sourceDir: '/data',
|
|
135
|
+
})
|
|
136
|
+
)
|
|
137
|
+
.listen(3000)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
This ensures both your backup data and configuration persist across deployments and restarts.
|
|
141
|
+
|
|
122
142
|
## 🔐 Security Features
|
|
123
143
|
|
|
124
144
|
### Session-Based Authentication
|
package/package.json
CHANGED
package/src/core/config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from 'node:fs'
|
|
2
2
|
import { writeFile } from 'node:fs/promises'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Load configuration from a JSON file
|
|
@@ -43,7 +44,8 @@ export const saveConfig = async (configPath, config) => {
|
|
|
43
44
|
* @returns {Object} Configuration manager with get/set/save methods
|
|
44
45
|
*/
|
|
45
46
|
export const createConfigManager = initialConfig => {
|
|
46
|
-
|
|
47
|
+
// If configPath not specified, save config alongside sourceDir for cloud deployments
|
|
48
|
+
const configPath = initialConfig.configPath || join(dirname(initialConfig.sourceDir), 'backup-config.json')
|
|
47
49
|
const savedConfig = loadConfig(configPath)
|
|
48
50
|
|
|
49
51
|
let config = { ...initialConfig, ...savedConfig }
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { authenticator } from 'otplib'
|
|
|
5
5
|
import QRCode from 'qrcode'
|
|
6
6
|
import { writeFile } from 'node:fs/promises'
|
|
7
7
|
import { readFileSync, existsSync } from 'node:fs'
|
|
8
|
+
import { dirname, join } from 'node:path'
|
|
8
9
|
// Helper to return HTML responses with proper Content-Type
|
|
9
10
|
const htmlResponse = content =>
|
|
10
11
|
new Response(content, {
|
|
@@ -36,11 +37,12 @@ const sessionManager = createSessionManager()
|
|
|
36
37
|
* @param {string} [config.prefix] - Optional prefix for S3 keys (e.g. 'backups/')
|
|
37
38
|
* @param {string} [config.cronSchedule] - Cron schedule expression
|
|
38
39
|
* @param {boolean} [config.cronEnabled] - Whether the cron schedule is enabled
|
|
39
|
-
* @param {string} [config.configPath] - Path to save runtime configuration (default:
|
|
40
|
+
* @param {string} [config.configPath] - Path to save runtime configuration (default: same directory as sourceDir)
|
|
40
41
|
*/
|
|
41
42
|
export const r2Backup = initialConfig => app => {
|
|
42
43
|
// State to hold runtime configuration (allows UI updates)
|
|
43
|
-
|
|
44
|
+
// If configPath not specified, save config alongside sourceDir for cloud deployments
|
|
45
|
+
const configPath = initialConfig.configPath || join(dirname(initialConfig.sourceDir), 'backup-config.json')
|
|
44
46
|
|
|
45
47
|
// Load saved config if exists
|
|
46
48
|
let savedConfig = {}
|