"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debugRouter = void 0;
const tslib_1 = require("tslib");
const express_1 = tslib_1.__importDefault(require("express"));
const inbox_manager_1 = require("../../../lib/activitypub/inbox-manager");
const remove_dangling_resumable_uploads_scheduler_1 = require("../../../lib/schedulers/remove-dangling-resumable-uploads-scheduler");
const video_views_buffer_scheduler_1 = require("../../../lib/schedulers/video-views-buffer-scheduler");
const video_views_manager_1 = require("../../../lib/views/video-views-manager");
const middlewares_1 = require("../../../middlewares");
const video_channel_sync_latest_scheduler_1 = require("../../../lib/schedulers/video-channel-sync-latest-scheduler");
const update_videos_scheduler_1 = require("../../../lib/schedulers/update-videos-scheduler");
const debugRouter = express_1.default.Router();
exports.debugRouter = debugRouter;
debugRouter.get('/debug', middlewares_1.authenticate, (0, middlewares_1.ensureUserHasRight)(4), getDebug);
debugRouter.post('/debug/run-command', middlewares_1.authenticate, (0, middlewares_1.ensureUserHasRight)(4), runCommand);
function getDebug(req, res) {
    return res.json({
        ip: req.ip,
        activityPubMessagesWaiting: inbox_manager_1.InboxManager.Instance.getActivityPubMessagesWaiting()
    });
}
function runCommand(req, res) {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const body = req.body;
        const processors = {
            'remove-dandling-resumable-uploads': () => remove_dangling_resumable_uploads_scheduler_1.RemoveDanglingResumableUploadsScheduler.Instance.execute(),
            'process-video-views-buffer': () => video_views_buffer_scheduler_1.VideoViewsBufferScheduler.Instance.execute(),
            'process-video-viewers': () => video_views_manager_1.VideoViewsManager.Instance.processViewerStats(),
            'process-update-videos-scheduler': () => update_videos_scheduler_1.UpdateVideosScheduler.Instance.execute(),
            'process-video-channel-sync-latest': () => video_channel_sync_latest_scheduler_1.VideoChannelSyncLatestScheduler.Instance.execute()
        };
        yield processors[body.command]();
        return res.status(204).end();
    });
}
//# sourceMappingURL=debug.js.map