fase(4): crawling infrastructure with migrated code
This commit is contained in:
56
dist/modules/crawling/infrastructure/http/CrawlingController.js
vendored
Normal file
56
dist/modules/crawling/infrastructure/http/CrawlingController.js
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createCrawlingRouter = createCrawlingRouter;
|
||||
/**
|
||||
* CrawlingController — thin Express controller for crawling routes.
|
||||
* Delegates to use cases; returns Result-based responses.
|
||||
*/
|
||||
const express_1 = require("express");
|
||||
function createCrawlingRouter(deps) {
|
||||
const router = (0, express_1.Router)();
|
||||
// POST /api/sessions — start a new crawl session
|
||||
router.post('/', async (req, res) => {
|
||||
const body = req.body;
|
||||
const { url, seed = 42, maxStates = 50, config } = body;
|
||||
if (!url || typeof url !== 'string') {
|
||||
res.status(400).json({ error: 'url is required' });
|
||||
return;
|
||||
}
|
||||
const result = await deps.startCrawl.execute({ url, seed, maxStates, config });
|
||||
if (!result.ok) {
|
||||
res.status(422).json({ error: result.error });
|
||||
return;
|
||||
}
|
||||
res.status(201).json(result.value);
|
||||
});
|
||||
// GET /api/sessions — list all sessions
|
||||
router.get('/', async (_req, res) => {
|
||||
const result = await deps.listSessions.execute({});
|
||||
if (!result.ok) {
|
||||
res.status(500).json({ error: result.error });
|
||||
return;
|
||||
}
|
||||
res.json(result.value);
|
||||
});
|
||||
// GET /api/sessions/:id — session detail
|
||||
router.get('/:id', async (req, res) => {
|
||||
const sessionId = req.params['id'];
|
||||
const result = await deps.getSession.execute({ sessionId });
|
||||
if (!result.ok) {
|
||||
res.status(404).json({ error: result.error });
|
||||
return;
|
||||
}
|
||||
res.json(result.value);
|
||||
});
|
||||
// DELETE /api/sessions/:id — stop a session
|
||||
router.delete('/:id', async (req, res) => {
|
||||
const sessionId = req.params['id'];
|
||||
const result = await deps.stopCrawl.execute({ sessionId });
|
||||
if (!result.ok) {
|
||||
res.status(404).json({ error: result.error });
|
||||
return;
|
||||
}
|
||||
res.json({ stopped: true });
|
||||
});
|
||||
return router;
|
||||
}
|
||||
Reference in New Issue
Block a user