@eyevinn/iaf-plugin-aws
Version:
Eyevinn Ingest Application Framework (IAF) plugin for upload and transcode in AWS
92 lines • 5.14 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AwsUploadModule = void 0;
const path = __importStar(require("path"));
const mediaConvertDispatcher_1 = require("./mediaConvertDispatcher");
const s3Uploader_1 = require("./s3Uploader");
const nanoid_1 = require("nanoid");
class AwsUploadModule {
constructor(mediaConvertEndpoint, awsRegion, ingestBucket, outputBucket, roleArn, playlistName, encodeParams, outputFiles, logger, watcherTimeout) {
/**
* Method that runs when a FileWatcher detects a new file.
* Uploads the file to an S3 ingress bucket, and dispatches a transcoding job when
* the upload is completed.
* @param filePath the path to the file being added.
* @param readStream Readable stream of the file.
*/
this.onFileAdd = (filePath, readStream) => {
let file = path.basename(filePath);
this.fileName = `${path.parse(file).name}-${(0, nanoid_1.nanoid)(10)}${path.parse(file).ext}`;
try {
this.uploader.upload(readStream, this.fileName).then(() => {
this.dispatcher.dispatch(this.fileName).then((data) => {
this.uploader.watcher(this.fileName).then((result) => {
this.dispatcher.getJob(data.Job.Id).then((job) => {
if (job.Status === "SUBMITTED" || job.Status === "PROGRESSING") {
this.logger.warn("MediaConvert job did not complete before the watcher timed out, continue to watch for transcoded files!");
this.uploader.watcher(this.fileName).then((result) => {
if ('outputError' in result) {
this.fileUploadedDelegate(result['outputs'], result['outputError']);
}
else {
this.fileUploadedDelegate(result);
}
});
}
else if (job.Status === "ERROR") {
this.logger.error('MediaConvert job failed, retrying job!');
this.dispatcher.dispatch(this.fileName).then(() => {
this.uploader.watcher(this.fileName).then((output) => {
if ('outputError' in result) {
this.fileUploadedDelegate(result['outputs'], result['outputError']);
}
else {
this.fileUploadedDelegate(result);
}
});
});
}
else {
if ('outputError' in result) {
this.fileUploadedDelegate(result['outputs'], result['outputError']);
}
else {
this.fileUploadedDelegate(result);
}
}
});
});
});
});
}
catch (err) {
this.logger.error(`Error when attempting to process file: ${this.fileName}. Full error: ${err}`);
}
};
this.logger = logger;
this.playlistName = playlistName;
this.uploader = new s3Uploader_1.S3Uploader(ingestBucket, outputBucket, awsRegion, outputFiles, this.logger, watcherTimeout);
this.dispatcher = new mediaConvertDispatcher_1.MediaConvertDispatcher(mediaConvertEndpoint, awsRegion, ingestBucket, outputBucket, roleArn, this.playlistName, encodeParams, this.logger);
}
}
exports.AwsUploadModule = AwsUploadModule;
//# sourceMappingURL=awsModule.js.map