"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.videoFilesDeleteHLSValidator = exports.videoFilesDeleteWebTorrentValidator = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("../../../helpers/logger");
const shared_1 = require("../shared");
const videoFilesDeleteWebTorrentValidator = [
    (0, shared_1.isValidVideoIdParam)('id'),
    (req, res, next) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
        logger_1.logger.debug('Checking videoFilesDeleteWebTorrent parameters', { parameters: req.params });
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        if (!(yield (0, shared_1.doesVideoExist)(req.params.id, res)))
            return;
        const video = res.locals.videoAll;
        if (!checkLocalVideo(video, res))
            return;
        if (!video.hasWebTorrentFiles()) {
            return res.fail({
                status: 400,
                message: 'This video does not have WebTorrent files'
            });
        }
        if (!video.getHLSPlaylist()) {
            return res.fail({
                status: 400,
                message: 'Cannot delete WebTorrent files since this video does not have HLS playlist'
            });
        }
        return next();
    })
];
exports.videoFilesDeleteWebTorrentValidator = videoFilesDeleteWebTorrentValidator;
const videoFilesDeleteHLSValidator = [
    (0, shared_1.isValidVideoIdParam)('id'),
    (req, res, next) => (0, tslib_1.__awaiter)(void 0, void 0, void 0, function* () {
        logger_1.logger.debug('Checking videoFilesDeleteHLS parameters', { parameters: req.params });
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        if (!(yield (0, shared_1.doesVideoExist)(req.params.id, res)))
            return;
        const video = res.locals.videoAll;
        if (!checkLocalVideo(video, res))
            return;
        if (!video.getHLSPlaylist()) {
            return res.fail({
                status: 400,
                message: 'This video does not have HLS files'
            });
        }
        if (!video.hasWebTorrentFiles()) {
            return res.fail({
                status: 400,
                message: 'Cannot delete HLS playlist since this video does not have WebTorrent files'
            });
        }
        return next();
    })
];
exports.videoFilesDeleteHLSValidator = videoFilesDeleteHLSValidator;
function checkLocalVideo(video, res) {
    if (video.remote) {
        res.fail({
            status: 400,
            message: 'Cannot delete files of remote video'
        });
        return false;
    }
    return true;
}
//# sourceMappingURL=video-files.js.map