UNPKG

@nerdo/code-reviewer

Version:

A web-based visual git diff tool for reviewing code changes between commits, branches, and tags

81 lines (80 loc) 3.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fileRouter = void 0; const express_1 = require("express"); const GitFileRepository_1 = require("../../infrastructure/git/GitFileRepository"); const FileTreeService_1 = require("../../domain/services/FileTreeService"); exports.fileRouter = (0, express_1.Router)(); const fileRepository = new GitFileRepository_1.GitFileRepository(); const fileTreeService = new FileTreeService_1.FileTreeService(); exports.fileRouter.post('/tree', async (req, res) => { try { const { path, commitHash } = req.body; if (!path || !commitHash) { return res.status(400).json({ error: 'Repository path and commit hash are required' }); } const tree = await fileRepository.getFileTree(path, commitHash); const sortedTree = fileTreeService.sortFileTree(tree); res.json(sortedTree); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } }); exports.fileRouter.post('/changes', async (req, res) => { try { const { path, fromHash, toHash } = req.body; if (!path || !fromHash || !toHash) { return res.status(400).json({ error: 'Repository path, fromHash, and toHash are required' }); } const changes = await fileRepository.getFileChanges(path, fromHash, toHash); res.json(changes); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } }); exports.fileRouter.post('/tree-with-changes', async (req, res) => { try { const { path, commitHash, fromHash, toHash } = req.body; if (!path || !commitHash || !fromHash || !toHash) { return res.status(400).json({ error: 'All parameters are required' }); } const [tree, changes] = await Promise.all([ fileRepository.getFileTree(path, commitHash), fileRepository.getFileChanges(path, fromHash, toHash) ]); const treeWithChanges = fileTreeService.buildFileTreeWithChanges(tree, changes); const sortedTree = fileTreeService.sortFileTree(treeWithChanges); res.json(sortedTree); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } }); exports.fileRouter.post('/diff', async (req, res) => { try { const { path, fromHash, toHash, filePath } = req.body; if (!path || !fromHash || !toHash || !filePath) { return res.status(400).json({ error: 'All parameters are required' }); } const diff = await fileRepository.getFileDiff(path, fromHash, toHash, filePath); res.json(diff); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } }); exports.fileRouter.post('/content', async (req, res) => { try { const { path, commitHash, filePath } = req.body; if (!path || !commitHash || !filePath) { return res.status(400).json({ error: 'All parameters are required' }); } const content = await fileRepository.getFileContent(path, commitHash, filePath); res.json({ content }); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } });