"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const traceProcessorController_1 = require("../controllers/traceProcessorController");
const auth_1 = require("../middleware/auth");
const path_1 = __importDefault(require("path"));
const router = (0, express_1.Router)();
// Public routes
router.get('/', traceProcessorController_1.listTraces);
router.get('/:traceId/status', traceProcessorController_1.getTraceStatus);
router.get('/:traceId/metadata', traceProcessorController_1.getTraceMetadata);
// Serve trace files for Perfetto UI
router.get('/:traceId/file', (req, res) => {
    const { traceId } = req.params;
    const tracePath = path_1.default.join(__dirname, '../../../uploads/traces', `${traceId}.trace`);
    res.sendFile(tracePath, (err) => {
        if (err) {
            res.status(404).json({ error: 'Trace file not found' });
        }
    });
});
// Protected routes (require authentication)
router.use(auth_1.authenticate);
// Upload routes
router.post('/initialize', traceProcessorController_1.initializeUpload);
router.post('/upload', traceProcessorController_1.uploadTrace, traceProcessorController_1.handleUpload);
router.post('/:traceId/upload', traceProcessorController_1.uploadChunk);
router.post('/:traceId/complete', traceProcessorController_1.completeUpload);
// Trace management
router.delete('/:traceId', traceProcessorController_1.deleteTrace);
// Query execution
router.get('/:traceId/query', traceProcessorController_1.queryTrace);
exports.default = router;
//# sourceMappingURL=traceProcessorRoutes.js.map