feat: database management - auto/USB backup toggles, folder browser, cron jobs
This commit is contained in:
@@ -318,6 +318,88 @@ router.delete("/destination/:id", async (req, res) => {
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
// GET directory listing for folder browser
|
||||
router.get("/browse", async (req, res) => {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
const requestedPath = (req.query.path as string) || "/";
|
||||
|
||||
// Resolve and sanitize — must be absolute
|
||||
const resolved = path.resolve(requestedPath);
|
||||
|
||||
try {
|
||||
const entries = fs.readdirSync(resolved, { withFileTypes: true });
|
||||
const dirs = entries
|
||||
.filter((e) => e.isDirectory())
|
||||
.map((e) => ({
|
||||
name: e.name,
|
||||
path: path.join(resolved, e.name),
|
||||
}))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
const parent = resolved !== "/" ? path.dirname(resolved) : null;
|
||||
|
||||
res.json({ current: resolved, parent, dirs });
|
||||
} catch (err: any) {
|
||||
res.status(400).json({ error: err.message || "Cannot read directory" });
|
||||
}
|
||||
});
|
||||
|
||||
// GET usb backup setting
|
||||
router.get("/usb-backup-setting", async (req, res) => {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
const user = await storage.getUser(userId);
|
||||
if (!user) return res.status(404).json({ error: "User not found" });
|
||||
|
||||
res.json({ usbBackupEnabled: user.usbBackupEnabled });
|
||||
});
|
||||
|
||||
// PUT usb backup setting
|
||||
router.put("/usb-backup-setting", async (req, res) => {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
const { usbBackupEnabled } = req.body;
|
||||
if (typeof usbBackupEnabled !== "boolean") {
|
||||
return res.status(400).json({ error: "usbBackupEnabled must be a boolean" });
|
||||
}
|
||||
|
||||
const updated = await storage.updateUser(userId, { usbBackupEnabled });
|
||||
if (!updated) return res.status(404).json({ error: "User not found" });
|
||||
|
||||
res.json({ usbBackupEnabled: updated.usbBackupEnabled });
|
||||
});
|
||||
|
||||
// GET auto backup setting
|
||||
router.get("/auto-backup-setting", async (req, res) => {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
const user = await storage.getUser(userId);
|
||||
if (!user) return res.status(404).json({ error: "User not found" });
|
||||
|
||||
res.json({ autoBackupEnabled: user.autoBackupEnabled });
|
||||
});
|
||||
|
||||
// PUT auto backup setting
|
||||
router.put("/auto-backup-setting", async (req, res) => {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
const { autoBackupEnabled } = req.body;
|
||||
if (typeof autoBackupEnabled !== "boolean") {
|
||||
return res.status(400).json({ error: "autoBackupEnabled must be a boolean" });
|
||||
}
|
||||
|
||||
const updated = await storage.updateUser(userId, { autoBackupEnabled });
|
||||
if (!updated) return res.status(404).json({ error: "User not found" });
|
||||
|
||||
res.json({ autoBackupEnabled: updated.autoBackupEnabled });
|
||||
});
|
||||
|
||||
router.post("/backup-path", async (req, res) => {
|
||||
const userId = req.user?.id;
|
||||
if (!userId) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
Reference in New Issue
Block a user