Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/backend/src/routes/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import unzipper from 'unzipper';
import { readTemplateManifest, addTemplateToManifest } from '../services/templateService.js';
import { TEMPLATE_DIR } from '../config/constants.js';
import { ensureDir } from '../utils/fsUtils.js';
import { ensureDir, listFilesRecursive } from '../utils/fsUtils.js';
import { sanitizeUploadPath } from '../utils/pathUtils.js';
import { safeJoin } from '../utils/pathUtils.js';

Expand All @@ -16,6 +16,29 @@ export function registerHealthRoutes(fastify) {
return { templates, categories };
});

fastify.get('/api/templates/:templateId/files', async (req, reply) => {
const { templateId } = req.params || {};
if (!templateId) {
return reply.code(400).send({ error: 'templateId is required.' });
}

let templateRoot;
try {
templateRoot = safeJoin(TEMPLATE_DIR, templateId);
await fs.access(templateRoot);
} catch {
return reply.code(404).send({ error: `Template not found: ${templateId}` });
}

const allFiles = await listFilesRecursive(templateRoot);
const texFiles = allFiles
.filter(f => f.type === 'file' && f.path.toLowerCase().endsWith('.tex'))
.map(f => f.path)
.sort((a, b) => a.localeCompare(b));

return { files: texFiles };
});

fastify.post('/api/templates/upload', async (req, reply) => {
await ensureDir(TEMPLATE_DIR);
let templateId = '';
Expand Down
Loading