1var addCastifyChannel = angular.module('AddCastifyChannelModule', ['uiCropper']); 2 3addCastifyChannel.controller('addCastifyChannelCtrl', ['$scope', '$rootScope', '$compile', '$timeout', '$location', '$mdDialog', '$mdMedia', '$sce', 'AJAX', "$document", "$window", function ($scope, $rootScope, $compile, $timeout, $location, $mdDialog, $mdMedia, $sce, AJAX, $document, $window) { 4 5 $scope.buildForm = function (urlHash) { 6 // const hash = urlHash 7 // $scope.data = {} 8 // $scope.data['channel_url'] = ''; 9 // $scope.getPlatforms(hash); 10 } 11 12 $scope.getMetaData = function () { 13 if ($scope.data.channel_url == '') { 14 $scope.channel_data = {}; 15 return; 16 } 17 $scope.channel_data = {}; 18 19 var url = $scope.data.channel_url 20 21 var params = { act: 'get_meta_data', url: url, page: $scope.page_title }; 22 23 AJAX.post(params, { 'scope': $scope, 'loaders': 'add_castify_channel_loader' }, function (response) { 24 if (response.status == "success") { 25 $scope.channel_data = response.data; 26 // $scope.channel_data.image = response.data['twitter:image']; 27 } else { 28 $scope.response = response.toString(); 29 $rootScope.displayToaster('error', 'Error', 'Failed to change details.\nPlease try again in a few seconds'); 30 } 31 }); 32 } 33 34 $scope.cancel = function () { 35 $location.path('main/castify_channels'); 36 } 37 38 $scope.getPlatforms = function (hash) { 39 $scope.data = {} 40 $scope.data['channel_url'] = ''; 41 42 const params = { act: 'get_castify_channel_data', page: $scope.page_title }; 43 44 AJAX.post(params, { 'scope': $scope, 'loaders': 'platforms_loader' }, function (response) { 45 if (response.status == "success") { 46 47 $scope.data['platforms'] = response.data.map(item => ({...item, selected:false}) ); 48 49 if ($scope.pageState === "new") { 50 if ($scope.channel_parent != 0 && $scope.channel_parent) 51 $scope.getChannelByHash($scope.channel_parent) 52 } 53 else 54 $scope.getChannelByHash(hash) 55 56 } else { 57 $scope.response = response.toString(); 58 $rootScope.displayToaster('error', 'Error', 'Failed to change details.\nPlease try again in a few seconds'); 59 } 60 }); 61 } 62 63 $scope.getBlob = function (image) { 64 return new Promise((resolve, reject) => { 65 fetch(image) 66 .then(res => res.blob()) 67 .then(blob => { 68 resolve(new File([blob], "file.jpg", { type: "image/jpeg" })) 69 }) 70 .catch(err => reject(err)) 71 }) 72 } 73 74 $scope.uploadImageToCdn = function (image) { 75 return new Promise((resolve, reject) => { 76 77 if (image === undefined) { 78 reject("error") 79 return 80 } 81 82 $scope.getBlob(image) 83 .then(res => { 84 const fd = new FormData(); 85 fd.append('act', "upload_CTV_content"); 86 fd.append('page', $scope.page_title); 87 fd.append('file', res); 88 fd.append('adv_id', $rootScope.user.active_medias.id_in_media); 89 fd.append('type', "thumbnail"); 90 fd.append('external_video_id', "castify_channel"); 91 92 AJAX.imagePost(fd, { 'scope': $scope, 'loaders': 'add_castify_channel_loader' }, function (response) { 93 if (response.status == "success") { 94 resolve(`https://${response.full_path}`) 95 } 96 else { 97 $rootScope.displayToaster('error', 'Error', 'Failed to upload your image.\nPlease try again in a few seconds'); 98 reject("error") 99 } 100 }) 101 }) 102 .catch(err => console.log(err)) 103 }); 104 } 105 106 $scope.getData = async function () { 107 108 $scope.res = angular.element('form').serialize(); 109 $scope.res += `&feed_id=${JSON.parse($rootScope.user.active_medias.additional_settings).default_feed_id}`; 110 111 const images = {}; 112 for (const i in $scope.uploadedImages) { 113 const image = $scope.uploadedImages[i] 114 if (image.isChanged && image.img) { 115 const uploadedImageUrl = await $scope.uploadImageToCdn(image.img); 116 images[i] = uploadedImageUrl; 117 $scope.res += `&${i}=${uploadedImageUrl}` 118 } else 119 images[i] = image.img 120 } 121 122 if (($scope.pageState === "new" && $scope.parent_channel != 0 && $scope.parent_channel) || $scope.pageState === "duplicate") { 123 $scope.res = ""; 124 const responseObj = Object.assign({}, $scope.response); 125 const newObj = { 126 title: $scope.title, 127 description: $scope.description, 128 text_color: $scope.textColor, 129 main_color: $scope.mainColor, 130 background_color: $scope.backgroundColor, 131 hash: $scope.hash, 132 platform: $scope.selectedPlatform, 133 app_logo: images["app_logo"], 134 background_image: images["background_image"], 135 splash_screen: images["splash_screen"] 136 } 137 138 const newObj1 = Object.assign(responseObj, newObj) 139 for (const i in newObj1) { 140 $scope.res += `&${i}=${newObj1[i]}`; 141 } 142 143 $scope.res = $scope.res.replace("&", ""); 144 145 // $scope.res = JSON.stringify(responseObj) 146 // $scope.res = JSON.stringify(Object.assign(responseObj, newObj)) 147 } 148 } 149
150 $scope.saveChannel = async function () { 151 152 if (!$scope.cooldownOver) { 153 $rootScope.displayToaster('error', 'Too many requests', 'Please wait a few seconds'); 154 return 155 } 156 157 if ($scope.selectedPlatform.length == 0) { 158 $rootScope.displayToaster('error', 'Error', 'You must select \nat least one platform'); 159 return; 160 } 161 $scope.madeChanges = false; 162 $scope.cooldownOver = false; 163 164 $rootScope.startCooldown(20, $scope.finishCooldown) 165 await $scope.getData(); 166 const params = { 167 act: 'save_dynamic_request', 168 template_id: 24, 169 immediately: 1, 170 module: 'add_castify_channel', 171 page: $scope.page_title, 172 platforms: $scope.selectedPlatform, 173 entity_id: $rootScope.user.active_medias.entity_id, 174 channel: $rootScope.user.active_medias.id, 175 data: $scope.res, 176 action: 'insert', 177 }; 178 179 if ($scope.pageState === 'edit') { 180 params["action"] = "update"; 181 params["where"] = JSON.stringify({ id: $scope.response.id }) 182 } else if ($scope.pageState === "new") { 183 if ($scope.channel_parent == 0 || !$scope.channel_parent) { 184 if ($rootScope.user.active_medias.type_in_media == "81") 185 params["publisher_group_id"] = $rootScope.user.active_medias.id_in_media 186 else if ($rootScope.user.active_medias.type_in_media == "80") 187 params["publisher_id"] = $rootScope.user.active_medias.id_in_media 188 } 189 } 190 191 AJAX.post(params, { 'scope': $scope, 'loaders': 'add_castify_channel_loader' }, function (response) { 192 if (response.status == "success") { 193 $rootScope.displayToaster('success', 'Success', 'The request was sent to approval.\n'); 194 $scope.channel_data = response.data; 195 if ($scope.pageState === "new") 196 $location.path('main/castify_channels') 197 } else { 198 $scope.response = response.toString(); 199 $rootScope.displayToaster('error', 'Error', 'Failed to change details.\nPlease try again in a few seconds'); 200 } 201 }); 202 } 203 204 $scope.refresh = function () { 205 $scope.allowNewPage = JSON.parse($rootScope.user.active_medias.additional_settings).allow_new_page 206 $scope.pageState = $scope.findPageState(); 207 $scope.onPageStateInit(); 208 } 209 210 $scope.generateHash = function () { 211 const bank = "abcdefghijklmnopqrstuvwxyz0123456789"; 212 let hash = "" 213 for (let i = 0; i < 10; i++) 214 hash += bank[Math.floor(Math.random() * bank.length)]; 215 216 return hash 217 } 218 219 $scope.getChannelByHash = function (hash) { 220 221 if ((!hash && $scope.pageState !== "new") || (!$scope.allowNewPage && $scope.pageState === "new")) { 222 $location.url("main/castify_channels"); 223 return 224 } 225 226 const params = { 227 "act": 'get_castify_channel_by_hash', 228 "hash": hash, 229 "page": $scope.page_title, 230 "mode": $scope.pageState 231 }; 232 233 AJAX.post(params, { 'scope': $scope, 'loaders': '' }, function (response) { 234 if (response.status == "success") { 235 //if no data arrived redirect to prev page 236 if (!response.data && $scope.pageState !== "new") { 237 $location.url("main/castify_channels"); 238 return 239 } 240 241 $scope.response = { ...response.data }; 242 243 if ($scope.pageState === "new") 244 return 245 246 $scope.title = response.data.app_name; 247 $scope.description = response.data.description; 248 $scope.textColor = response.data.text_color; 249 $scope.mainColor = response.data.main_color; 250 $scope.backgroundColor = response.data.background_color; 251 252 const index = $scope.data.platforms.findIndex(obj => obj.id == response.data.platform) 253 $scope.selectedPlatform = $scope.data.platforms[index].id; 254 $scope.prevPlatform = response.data.platform 255 $scope.addEvents(); 256 const imagesData = { 257 "app_logo": { url: response.data.app_logo }, 258 "background_image": { url: response.data.background_img }, 259 "splash_screen": { url: response.data.splash_screen }, 260 } 261 262 $scope.updateImages(imagesData) 263 264 } else { 265 $scope.response = response.toString(); 266 $rootScope.displayToaster('error', 'Error', 'Failed to retreive your channel.\nPlease try again in a few seconds'); 267 } 268 }); 269 } 270 271 $scope.updateImages = function (data) { 272 for (let i in $scope.uploadedImages) { 273 if (data[i].url) { 274 $scope.uploadedImages[i].img = data[i].url; 275 angular.element(`#P${i}`).attr("src", $scope.uploadedImages[i].img); 276 } 277 } 278 } 279 280 $scope.findPageState = function () { 281 const path = $location.path() 282 if (path.includes('edit')) 283 return 'edit'; 284 else if (path.includes('duplicate')) 285 return 'duplicate'; 286 else { 287 $scope.addEvents(); 288 return 'new'; 289 } 290 }; 291 292 $scope.onPageStateInit = function () { 293 switch ($scope.pageState) { 294 case "edit": 295 $scope.button_title = "Update"; 296 $rootScope.page_title = 'Update Channel'; 297 $scope.hash = $location.search().hash; 298 $scope.getPlatforms($location.search().hash); 299 break; 300 case 'new': 301 $scope.button_title = "Save"; 302 $rootScope.page_title = 'Add Castify Channel'; 303 $scope.hash = $scope.generateHash(); 304 $scope.getPlatforms(); 305 break 306 case 'duplicate': 307 $scope.button_title = "Duplicate"; 308 $rootScope.page_title = 'Duplicate Channel'; 309 $scope.hash = $scope.generateHash(); 310 $scope.getPlatforms($location.search().hash); 311 break; 312 } 313 } 314 315 $scope.addEvents = function () { 316 $scope.$watchGroup(['title', 'description', 'textColor', 'mainColor', 'backgroundColor', 'selectedPlatform'], function (new1, old) { 317 if (new1 !== old) 318 $scope.madeChanges = true 319 }); 320 } 321 322 $scope.finishCooldown = function () {
323 $scope.cooldownOver = true 324 } 325 326 $scope.init = function () { 327 $scope.page_title = 'add_castify_channel' 328 $scope.pageState = $scope.findPageState(); 329 $scope.onPageStateInit(); 330 $scope.allowNewPage = JSON.parse($rootScope.user.active_medias.additional_settings).allow_new_page 331 $scope.channel_parent = JSON.parse($rootScope.user.active_medias.additional_settings).parent_channel.trim(); 332 // images 333 $scope.uploadedImages = { 334 "app_logo": { 335 img: "app/assets/style/CR293AA2/images/addImagePopUp/placeholder.png", 336 isChanged: false 337 }, 338 "background_image": { 339 img: "app/assets/style/CR293AA2/images/addImagePopUp/placeholder.png", 340 isChanged: false 341 }, 342 "splash_screen": { 343 img: "app/assets/style/CR293AA2/images/addImagePopUp/placeholder.png", 344 isChanged: false 345 } 346 } 347 348 //form properties 349 $scope.title = ""; 350 $scope.description = ""; 351 $scope.textColor = "#000000"; 352 $scope.mainColor = "#000000"; 353 $scope.backgroundColor = "#000000"; 354 $scope.platforms = "" 355 356 $scope.channel_data = {}; 357 $scope.selectedPlatform = ""; 358 $scope.prevPlatform = ""; 359 360 $scope.filter_actions = false; 361 $scope.filter_settings = { 362 search: true, 363 search_type: 'drp', 364 select_all: false 365 }; 366 367 $scope.madeChanges = false 368 $scope.cooldownOver = true 369 $scope.add_castify_channel_loader = false;
370 371 $timeout(() => { 372 $scope.$on('$destroy', function () { 373 window.onbeforeunload = undefined; 374 }); 375 $scope.$on('$locationChangeStart', function (event, next, current) { 376 if ($scope.madeChanges) 377 if (!confirm("Are you sure you want to leave this page?")) 378 event.preventDefault(); 379 }); 380 }, 100) 381 382 $scope.video_path = 'https://cdn.videofy.ai/rukofy/Roku-add-authorization-to-Castify-acc.mp4'; 383 384 $rootScope.refreshPointer = $scope.refresh; 385 $location.url($location.path()); 386 387 $rootScope.skip_overide_title = true; 388 } 389 390 $rootScope.setPageHeight(); 391 392 if (typeof $rootScope.global_data == 'undefined') 393 $rootScope.getUserInfo($scope); 394 else 395 $scope.init(); 396}]); 397 398
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.