docs: Plan P2603.01 Automatización Zoom y actualizaciones P2601.09
This commit is contained in:
@@ -4,24 +4,21 @@ const path = require('path');
|
||||
module.exports = () => {
|
||||
const router = require('express').Router();
|
||||
|
||||
const DOCS_BASE = path.resolve('/app/docs/proy');
|
||||
const DOCS_BASE = path.resolve('/app/docs');
|
||||
|
||||
// GET /api/docs/:proyecto/:archivo — Servir .md crudo
|
||||
// Ejemplo: /api/docs/P2601_Dasuten/P2601.09_DASUTEN-sin-DC.md
|
||||
router.get('/:proyecto/:archivo', (req, res) => {
|
||||
const { proyecto, archivo } = req.params;
|
||||
// GET /api/docs/* — Servir .md crudo
|
||||
// Ejemplo: /api/docs/proy/P2601_Dasuten/P2601.09_DASUTEN-sin-DC.md
|
||||
router.get('/*', (req, res) => {
|
||||
if (req.path === '/') return; // Se maneja abajo
|
||||
|
||||
const fileRelPath = req.params[0];
|
||||
|
||||
// Sanitizar: solo permitir caracteres seguros
|
||||
if (!/^[A-Za-z0-9._-]+$/.test(proyecto) || !/^[A-Za-z0-9._-]+$/.test(archivo)) {
|
||||
return res.status(400).json({ error: 'Nombre de archivo inválido' });
|
||||
// Sanitizar y verificar extensión
|
||||
if (!fileRelPath || !fileRelPath.endsWith('.md') || fileRelPath.includes('..')) {
|
||||
return res.status(400).json({ error: 'Ruta de archivo inválida' });
|
||||
}
|
||||
|
||||
// Solo permitir .md
|
||||
if (!archivo.endsWith('.md')) {
|
||||
return res.status(400).json({ error: 'Solo se permiten archivos .md' });
|
||||
}
|
||||
|
||||
const filePath = path.join(DOCS_BASE, proyecto, archivo);
|
||||
const filePath = path.join(DOCS_BASE, fileRelPath);
|
||||
|
||||
// Verificar que no escapa del directorio base
|
||||
if (!filePath.startsWith(DOCS_BASE)) {
|
||||
@@ -38,8 +35,9 @@ module.exports = () => {
|
||||
}
|
||||
|
||||
res.json({
|
||||
proyecto,
|
||||
archivo,
|
||||
doc_path: fileRelPath,
|
||||
proyecto: path.basename(path.dirname(fileRelPath)),
|
||||
archivo: path.basename(fileRelPath),
|
||||
content,
|
||||
lastModified: fs.statSync(filePath).mtime.toISOString()
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user