"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkLiveCleanupAfterSave = void 0;
const tslib_1 = require("tslib");
const chai_1 = require("chai");
const fs_extra_1 = require("fs-extra");
const path_1 = require("path");
function checkLiveCleanupAfterSave(server, videoUUID, resolutions = []) {
    return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
        const basePath = server.servers.buildDirectory('streaming-playlists');
        const hlsPath = (0, path_1.join)(basePath, 'hls', videoUUID);
        if (resolutions.length === 0) {
            const result = yield (0, fs_extra_1.pathExists)(hlsPath);
            (0, chai_1.expect)(result).to.be.false;
            return;
        }
        const files = yield (0, fs_extra_1.readdir)(hlsPath);
        (0, chai_1.expect)(files).to.have.lengthOf(resolutions.length * 2 + 2);
        for (const resolution of resolutions) {
            const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`));
            (0, chai_1.expect)(fragmentedFile).to.exist;
            const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`));
            (0, chai_1.expect)(playlistFile).to.exist;
        }
        const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8'));
        (0, chai_1.expect)(masterPlaylistFile).to.exist;
        const shaFile = files.find(f => f.endsWith('-segments-sha256.json'));
        (0, chai_1.expect)(shaFile).to.exist;
    });
}
exports.checkLiveCleanupAfterSave = checkLiveCleanupAfterSave;
//# sourceMappingURL=live.js.map