Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/main/core/core_uploader/src/ |
Upload File : |
import {Loc,Event} from 'main.core'; import Stream from './stream'; import Package from './package'; import {EventEmitter} from 'main.core.events'; export default class Streams extends EventEmitter { static maxInstances = 3; static #instance = new Map(); static #packages = new Map(); static #hiddenTag = Symbol('streams descriptor'); static addPackage(pack: Package) { console.log('3. Add to a stream queue.'); if (this.maxInstances > 0 && this.#instance.size > this.maxInstances) { this.#packages.set(pack); } else { this.#packages.delete(pack); this.#runPackage(pack); } if (!window[this.#hiddenTag]) { window[this.#hiddenTag] = this.#catchWindow.bind(this); Event.bind(window, 'beforeunload', window[this.#hiddenTag]); } } static #catchWindow(event) { if (this.#packages.size > 0 || this.#instance.size > 0) { const confirmationMessage = Loc.getMessage('UPLOADER_UPLOADING_ONBEFOREUNLOAD'); (event || window.event).returnValue = confirmationMessage; return confirmationMessage; } } static #runPackage(pack: Package) { const stream = new Stream(); this.#instance.set(stream); console.log('3.1. Run package in a stream.'); pack.subscribeOnce('done', () => { console.log('6. Package is done so release the stream.'); this.#instance.delete(stream); stream.destroy(); if (this.#packages.size > 0) { const [newPack] = this.#packages.entries().next().value; this.addPackage(newPack); } else if (this.#instance.size <= 0) { Event.unbind(window, 'beforeunload', window[this.#hiddenTag]); delete window[this.#hiddenTag]; } }); pack.run(stream); } }