export default class MediaAttachment {
/**
* Creates a new MediaAttachment
*
* @constructor MediaAttachment
* @param {object} params - Object with parms
* @param {string} [params.imageUrl] - Image URL
* @param {string} [params.videoUrl] - Video URL
* @param {string} [params.base64Image] - Base64 Image
* @param {string} [params.base64Video] - Base64 Video
* @param {File} [params.imageFile] - Image File
* @param {File} [params.videoFile] - Video File
*/
constructor(params) {
this.imageUrl = params.imageUrl || null;
this.videoUrl = params.videoUrl || null;
this.base64Image = params.base64Image || null;
this.base64Video = params.base64Video || null;
this.imageFile = params.imageFile || null;
this.videoFile = params.videoFile || null;
}
/**
* Creates media attachment instance with image url.
*
* @memberof MediaAttachment
* @param {string} imageUrl - Url of the image.
* @return {MediaAttachment} Created media attachment instance.
*/
static withImageUrl(imageUrl) {
const mA = new MediaAttachment({});
mA.imageUrl = imageUrl;
return mA;
}
/**
* Creates media attachment instance with video url.
*
* @memberof MediaAttachment
* @param {string} videoUrl - Url of the video.
* @return {MediaAttachment} Created media attachment instance.
*/
static withVideoUrl(videoUrl) {
const mA = new MediaAttachment({});
mA.videoUrl = videoUrl;
return mA;
}
/**
* Creates media attachment instance with Base64 image.
*
* @memberof MediaAttachment
* @param {string} image - Uri of the image.
* @return {MediaAttachment} Created media attachment instance.
*/
static withBase64Image(image) {
const mA = new MediaAttachment({});
mA.base64Image = image.replace(/\r\n/g, '');
return mA;
}
/**
* Creates media attachment instance with Base64 video.
*
* @memberof MediaAttachment
* @param {string} video - Uri of the video.
* @return {MediaAttachment} Created media attachment instance.
*/
static withBase64Video(video) {
const mA = new MediaAttachment({});
mA.base64Video = video.replace(/\r\n/g, '');
return mA;
}
/**
* Creates media attachment instance with File image.
*
* @memberof MediaAttachment
* @param {File} file - Image file.
* @return {MediaAttachment} Created media attachment instance.
*/
static withImageFile(file) {
const mA = new MediaAttachment({});
mA.imageFile = file;
return mA;
}
/**
* Creates media attachment instance with File video.
*
* @memberof MediaAttachment
* @param {File} file - Video file.
* @return {MediaAttachment} Created media attachment instance.
*/
static withVideoFile(file) {
const mA = new MediaAttachment({});
mA.videoFile = file;
return mA;
}
/**
* Returns image url.
*
* @memberof MediaAttachment
* @instance
* @return {string} Image url.
*/
getImageUrl() {
return this.imageUrl;
}
/**
* Returns video url.
*
* @memberof MediaAttachment
* @instance
* @return {string} Video url.
*/
getVideoUrl() {
return this.videoUrl;
}
}