PageSourceSearch

https://akademia-excel.ru/nassets/3e6171b4/js/frames/folder.js?v=1765633899

js akademia-excel.ru collected 2026-09-30 11:25:38 UTC 7,365 bytes, 236 lines download raw bytes

1jQuery.widget('gc.gcVideoFramesFolder', $.gc.gcFileSelectorFolder, {
2	options: {
3		mainHash: null,
4		previewList: []
5	},
6	mapFrameHashToSrc: null,
7	currentPreview: null,
8	_create: function() {
9		var self = this;
10
11		this.element.addClass("folder");
12
13		this.element.append(self.generateBeforeFolderPart());
14
15		this.filesEl = $('<div class="files-list"></div>');
16		this.filesEl.appendTo( this.element );
17	},
18	init: function() {
19	},
20	generateMapHashToSrc: function (previewList) {
21		var self = this;
22		var prefix = Math.floor(Math.random() * 1000) + 1;
23		self.mapFrameHashToSrc = {};
24		for (var i = 0; i < previewList.length; i++) {
25			var frameHash = prefix + 'frame' + i;
26			self.mapFrameHashToSrc[frameHash] = previewList[i];
27		}
28	},
29	createFileEl: function(hash, inFavorites) {
30		var $el = $('<div class="file-item"></div>');
31		var self = this;
32		self.hash = hash;
33
34		var fileKey = self.getFileKey(hash);
35		var fileClass = self.getFileClass(hash);
36		$el.data('key', fileKey);
37		$el.addClass(fileClass);
38		$el.addClass('video-frame');
39
40		var $img = $('<img>');
41		var frameUrl = self.getSrcByHash(hash);
42		$img.attr("src", frameUrl);
43		$img.data('hash', hash);
44		$img.appendTo($el);
45
46		$img.click(function() {
47			var service = window.vhs.createPreviewService(window.vhsRegion);
48			service.changeVideoPreview(self.options.mainHash, frameUrl)
49				.then(function(result){
50					if (result) {
51						self.selectFile(self.options.mainHash);
52					} else {
53						$.toast(window.tt('common', 'Ошибка загрузки файла'), {type: 'danger'});
54					}
55				})
56				.catch(function(){
57					$.toast(window.tt('common', 'Ошибка загрузки файла'), {type: 'danger'});
58				});
59		});
60
61		return $el;
62	},
63	loadFiles: function(folderName, $toElement, selectedHash) {
64		var key = folderName;
65		if (this.loading && this.loading === key) {
66			return;
67		}
68		var self = this;
69		$toElement.empty();
70
71		this.loading = key;
72
73		for (var frameHash in self.mapFrameHashToSrc) {
74			if (!self.mapFrameHashToSrc.hasOwnProperty(frameHash)) {
75				continue;
76			}
77			var $frameEl = self.createFileEl(frameHash, false);
78			$frameEl.appendTo($toElement);
79		}
80		self.loading = null;
81	},
82	selectFile: function(hash) {
83		var self = this;
84
85		$.toast(window.tt('common', 'Превью изменено'), {type: 'success'});
86		updateThumbnailVersion(self.options.mainHash, Date.now());
87		this.options.owner.fileSelected(hash);
88	},
89	getSrcByHash: function(hash) {
90		return hash in this.mapFrameHashToSrc
91			? this.mapFrameHashToSrc[hash]
92			: '';
93	},
94	checkNeedToRefresh: function() {
95		var self = this;
96		if (this.currentPreview) {
97			this.currentPreview.attr("src", getVideoThumbnailUrl(self.options.mainHash, 550, ''));
98		}
99	},
100	generateBeforeFolderPart: function() {
101		var self = this;
102		var hash = self.options.mainHash;
103
104		var $currentPreview = self.currentPreview = $('<img style="margin-bottom: 10px">');
105		$currentPreview.attr("src", getVideoThumbnailUrl(hash, 550, ''));
106		$currentPreview.css('width', 'auto').css('height', '360px').css('object-fit', 'contain');
107		var $content = $('<div>');
108		$content.css('padding-left', '19px');
109		var $messageEl = $('<div></div>');
110		var $loading = $('<img src="/public/img/loading.gif">');
111
112		$content.append($currentPreview);
113		$content.append($loading);
114		$content.append($messageEl);
115
116		// get video info
117
118		if (self.options.skipGetInfo) {
119			$loading.remove();
120			self.generateMapHashToSrc(self.options.previewList);
121			self.fillModalForReadyPreview($content, hash);
122			self.loadFiles(self.options.folder, self.filesEl);
123		} else {
124			ajaxCall('/pl/fileservice/video/info', {
125				'file-hash': hash,
126				'result-format': 'json'
127			}, {crossDomain: true}, function (response) {
128				$loading.remove();
129				if (response.status === 'done') {
130					self.generateMapHashToSrc(response.previewList);
131					self.fillModalForReadyPreview($content, hash);
132					self.loadFiles(self.options.folder, self.filesEl);
133				} else {
134					$messageEl.text('Это видео еще не обработано');
135				}
136			});
137		}
138
139		return $content;
140	},
141	fillModalForReadyPreview: function($content, fileHash) {
142		var self = this;
143
144		// make elements
145
146		var $uploader = $('<div class="uploader"></div>');
147		var queueId = "queueVideoPreviewUpload";
148		var $queue = $("<div id='" + queueId + "'></div>");
149
150		// build content
151
152		$uploader.appendTo($content);
153		$queue.appendTo($content);
154
155		// define action handlers
156
157		var uploadUrl = '/fileservice/widget/upload?deprecated=13'
158			+ '&secure=' + window.isEnabledSecureUpload
159			+ '&host=' + window.fileserviceUploadHost;
160
161		var uploadifiveParams = {
162			auto: true,
163			buttonText: window.tt('common', 'Загрузить превью'),
164			width: 140,
165			id: "videoPreviewUpload" + fileHash,
166			queueID: queueId,
167			dnd: false,
168			removeCompleted: true,
169			multi: false,
170			fileSizeLimit: self.options.fileSizeLimit,
171			uploadScript: uploadUrl,
172			formData: {fullAnswer: true},
173			onUploadError: function(file, errorCode, errorMsg) {
174				$.toast(window.tt('common', 'Ошибка загрузки файла'), {type: 'danger'});
175			},
176			onUploadComplete: function(e, res) {
177				res = JSON.parse(res);
178				var service = window.vhs.createPreviewService(window.vhsRegion);
179				service.changeVideoPreviewForHash(fileHash, res.hash)
180					.then(function(result){
181						if (result) {
182							self.selectFile(fileHash);
183						} else {
184							$.toast(window.tt('common', 'Ошибка загрузки файла'), {type: 'danger'});
185						}
186					})
187					.catch(function(){
188						$.toast(window.tt('common', 'Ошибка загрузки файла'), {type: 'danger'});
189					});
190			}
191		};
192
193		// Потому что fileType параметр uploadifive как-то не так работает.
194		// При указании video/* кучу видео форматов не позволяет выбрать
195		// Если перечислить конкретные расширения файлов (или mime-type'ы), то тоже не все их воспринимает
196		uploadifiveParams.onInit = function(filesToUpload, settings) {
197			if (window.isEnabledSecureUpload && window.fileserviceUploadHost) {
198				if (!settings) {
199					settings = {}
200				}
201				getUploadifySecretLink(filesToUpload, settings);
202			}
203
204			var $fileInput = $('input[type=file]', $content);
205			$fileInput.attr('accept', '.png, .jpg, .jpeg');
206		};
207		// При добавлении очередного файла создаются еще input'ы и по этому событию их можно обработать
208		uploadifiveParams.onUpload = uploadifiveParams.onInit;
209
210		setTimeout(function() {
211			$uploader.uploadifive(uploadifiveParams);
212		}, 100);
213	},
214	// one of previewHash and previewUrl is null
215	//VG: remove todo?
216	changeVideoPreview: function(fileHash, previewHash, previewUrl) {
217		var self = this;
218		var params = {
219			'file-hash': fileHash
220		};
221		var previewParamProvided = true;
222		if (previewHash) {
223			params = Object.assign({}, params, {'preview-hash': previewHash});
224		} else if (previewUrl) {
225			params = Object.assign({}, params, {'preview-url': previewUrl});
226		} else {
227			previewParamProvided = false;
228			console.log('Preview param is not provided');
229		}
230		if (previewParamProvided) {
231			ajaxCall('/pl/fileservice/video/change-preview', params, {}, function() {
232				self.selectFile(fileHash);
233			});
234		}
235	}
236} );

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.