"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.videoSourceGetValidator = void 0;
const tslib_1 = require("tslib");
const video_1 = require("../../../helpers/video");
const video_source_1 = require("../../../models/video/video-source");
const shared_1 = require("../shared");
const videoSourceGetValidator = [
    (0, shared_1.isValidVideoIdParam)('id'),
    (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        if ((0, shared_1.areValidationErrors)(req, res))
            return;
        if (!(yield (0, shared_1.doesVideoExist)(req.params.id, res, 'for-api')))
            return;
        const video = (0, video_1.getVideoWithAttributes)(res);
        res.locals.videoSource = yield video_source_1.VideoSourceModel.loadByVideoId(video.id);
        if (!res.locals.videoSource) {
            return res.fail({
                status: 404,
                message: 'Video source not found'
            });
        }
        const user = res.locals.oauth.token.User;
        if (!(0, shared_1.checkUserCanManageVideo)(user, video, 17, res))
            return;
        return next();
    })
];
exports.videoSourceGetValidator = videoSourceGetValidator;
//# sourceMappingURL=video-source.js.map