const fs = require('fs');
const { execSync } = require('child_process');

module.exports = function(app, checkApiKey) {
    app.get('/action/getrepos', checkApiKey, (req, res) => {
        const repoPath = '/var/svn';  // Updated correct path
        
        try {
            // Read the repositories directory
            const repos = fs.readdirSync(repoPath)
                .filter(item => fs.statSync(`${repoPath}/${item}`).isDirectory())
                .filter(item => fs.existsSync(`${repoPath}/${item}/format`)); // Verify it's a SVN repo

            res.json({
                repositories: repos,
                count: repos.length
            });
            
        } catch (error) {
            res.status(500).json({
                error: "Error reading repositories",
                details: error.message
            });
        }
    });
};
