mirror of
https://github.com/asabino2/dockerbackup.git
synced 2026-09-24 06:36:59 +00:00
atualiza versão para 0.0.5; adiciona modal de navegador de diretórios e nova rota API para listar subdiretórios
This commit is contained in:
@@ -479,6 +479,30 @@ async function main() {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/browse-dirs', authMiddleware, async (request, response) => {
|
||||
try {
|
||||
const rawPath = typeof request.query.path === 'string' ? request.query.path : '/';
|
||||
const dirPath = path.resolve('/', rawPath.replace(/\0/g, ''));
|
||||
|
||||
let entries;
|
||||
try {
|
||||
entries = await fs.readdir(dirPath, { withFileTypes: true });
|
||||
} catch {
|
||||
return response.status(400).json({ error: 'Não foi possível ler o diretório.' });
|
||||
}
|
||||
|
||||
const dirs = entries
|
||||
.filter((e) => e.isDirectory() && !e.name.startsWith('.'))
|
||||
.map((e) => ({ name: e.name, path: path.join(dirPath, e.name) }))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
const parent = dirPath !== '/' ? path.dirname(dirPath) : null;
|
||||
response.json({ current: dirPath, parent, dirs });
|
||||
} catch (error) {
|
||||
response.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(config.port, () => {
|
||||
console.log(`Docker Backup app ouvindo na porta ${config.port}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user