Advertisement
Guest User

Untitled

a guest
May 7th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mega.fileuploader {
  2. import flash.net.*;
  3.  
  4. public class File {
  5.  
  6. private var _fileRef:FileReference;
  7. private var _id:string;
  8. private var _server:string;
  9. private var _description:string = "";
  10. private var _password:string = "";
  11. private var _trafficExchange:string = "";
  12. private var _recipientEmail:string = "";
  13. private var _uploaderEmail:string = "";
  14. private var _multiple:string = "";
  15. private var _hotlink:string = "0";
  16.  
  17. public function File(_arg1:FileReference, _arg2:string){
  18. this._fileRef = _arg1;
  19. this._server = _arg2;
  20. this._id = this.generateRandomID(32);
  21. }
  22. public function getFileReference():FileReference{
  23. return (this._fileRef);
  24. }
  25. public function getsize():number{
  26. return (this._fileRef.size);
  27. }
  28. public function getName():string{
  29. return (this._fileRef.name);
  30. }
  31. public function getID():string{
  32. return (this._id);
  33. }
  34. public function setDescription(_arg1:string):void{
  35. this._description = _arg1;
  36. }
  37. public function getDescription():string{
  38. return (this._description);
  39. }
  40. public function setPassword(_arg1:string):void{
  41. this._password = _arg1;
  42. }
  43. public function getPassword():string{
  44. return (this._password);
  45. }
  46. public function setTrafficExchange(_arg1:string):void{
  47. this._trafficExchange = _arg1;
  48. }
  49. public function getTrafficExchange():string{
  50. return (this._trafficExchange);
  51. }
  52. public function setRecipientEmail(_arg1:string):void{
  53. this._recipientEmail = _arg1;
  54. }
  55. public function getRecipientEmail():string{
  56. return (this._recipientEmail);
  57. }
  58. public function setUploaderEmail(_arg1:string):void{
  59. this._uploaderEmail = _arg1;
  60. }
  61. public function getUploaderEmail():string{
  62. return (this._uploaderEmail);
  63. }
  64. public function setMultipleRecipients(_arg1:string):void{
  65. this._multiple = _arg1;
  66. }
  67. public function getMultipleRecipients():string{
  68. return (this._multiple);
  69. }
  70. public function setHotlink(_arg1:string):void{
  71. this._hotlink = _arg1;
  72. }
  73. public function getHotlink():string{
  74. return (this._hotlink);
  75. }
  76. public function setServer(_arg1:string):void{
  77. this._server = _arg1;
  78. }
  79. public function getServer():string{
  80. return (this._server);
  81. }
  82. private function generateRandomID(_arg1:number):string{
  83. var _local7:string;
  84. var _local2:array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
  85. var _local3 = "0";
  86. var _local4:string = (_local3 + new date().gettime());
  87. var _local5:uint = (_arg1 - _local4.length);
  88. var _local6:uint = 1;
  89. while (_local6 <= _local5) {
  90. _local7 = _local2[math.floor((math.random() * 10))];
  91. _local4 = (_local4 + _local7);
  92. _local6++;
  93. };
  94. return (_local4);
  95. }
  96.  
  97. }
  98. }//package com.mega.fileuploader
  99. package com.mega.fileuploader {
  100. import __AS3__.vec.*;
  101. import flash.events.*;
  102. import flash.net.*;
  103. import flash.display.*;
  104. import flash.utils.*;
  105. import flash.external.*;
  106. import flash.errors.*;
  107.  
  108. public class FileUploader extends Sprite {
  109.  
  110. private static const TIME_OUT_TIME:number = 60000;
  111. private static const STATUS_FILE_SELECT:string = "fileSelect";
  112. private static const STATUS_UPLOADING:string = "uploading";
  113. private static const STATUS_FINISHED:string = "finished";
  114.  
  115. private var _fileRefList:FileReferenceList;
  116. private var _allFiles:Vector.<File>;
  117. private var _serverList:Vector.<String>;
  118. private var _processedFileIndex:number = 0;
  119. private var _timeOutTimer:Timer;
  120. private var _button:Sprite;
  121. private var _clickCount:uint = 0;
  122. private var _lastProgressTime:number;
  123. private var _status:string;
  124. private var _userID:string;
  125.  
  126. public function FileUploader(){
  127. stage.align = StageAlign.TOP_LEFT;
  128. stage.scalemode = StageScaleMode.NO_SCALE;
  129. stage.showDefaultContextMenu = false;
  130. this._status = STATUS_FILE_SELECT;
  131. this._timeOutTimer = new Timer(500);
  132. this._timeOutTimer.addEventListener(TimerEvent.TIMER, this.timeOutTick);
  133. this._allFiles = new Vector.<File>();
  134. var _local1:string = ((this.root.loaderInfo.parameters.servers)==undefined) ? "http%3A%2F%2Fwww173.megaupload.com%2F" : this.root.loaderInfo.parameters.servers;
  135. this._serverList = this.getServerList(_local1);
  136. this._userID = ((this.root.loaderInfo.parameters.user)==undefined) ? "" : this.root.loaderInfo.parameters.user;
  137. this._fileRefList = new FileReferenceList();
  138. this._fileRefList.addEventListener(Event.SELECT, this.filesSelectedHandler);
  139. this.registerCallbacks();
  140. stage.addEventListener(MouseEvent.CLICK, this.browseHandler);
  141. }
  142. private function getServerList(_arg1:string):Vector.<String>{
  143. var _local3:uint;
  144. var _local2:array = _arg1.split(";");
  145. while (_local3 < _local2.length) {
  146. _local2[_local3] = decodeURIComponent(_local2[_local3]);
  147. _local3++;
  148. };
  149. return (Vector.<String>(_local2));
  150. }
  151. private function createButton():void{
  152. this._button = new Sprite();
  153. this._button.graphics.beginfill(0, 0);
  154. this._button.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
  155. this._button.graphics.endfill();
  156. this._button.addEventListener(MouseEvent.CLICK, this.browseHandler);
  157. this._button.mouseChildren = false;
  158. this._button.buttonMode = true;
  159. addChild(this._button);
  160. }
  161. private function browseHandler(_arg1:MouseEvent):void{
  162. this._fileRefList.browse();
  163. }
  164. private function stageResizeHandler(_arg1:Event):void{
  165. this._button.width = stage.stageWidth;
  166. this._button.height = stage.stageHeight;
  167. }
  168. private function registerCallbacks():void{
  169. ExternalInterface.addCallback("startupload", this.startUpload);
  170. ExternalInterface.addCallback("removefile", this.removeFile);
  171. ExternalInterface.addCallback("updatefile", this.updateFileProperties);
  172. }
  173. private function filesSelectedHandler(_arg1:Event):void{
  174. this.addSelectedValidFiles(FileReferenceList(_arg1.target));
  175. }
  176. private function uploadFile():void{
  177. var _local1:URLRequest = new URLRequest();
  178. var _local2:File = this.getProcessedFile();
  179. var _local3:URLVariables = new URLVariables();
  180. var _local4:FileReference = _local2.getFileReference();
  181. _local3.message = _local2.getDescription();
  182. _local3.password = _local2.getPassword();
  183. _local3.trafficurl = _local2.getTrafficExchange();
  184. _local3.toemail = _local2.getRecipientEmail();
  185. _local3.fromemail = _local2.getUploaderEmail();
  186. _local3.multiemail = _local2.getMultipleRecipients();
  187. _local3.user = this._userID;
  188. _local3.hotlink = _local2.getHotlink();
  189. _local1.url = ((((((_local2.getServer() + "upload_done.php?UPLOAD_IDENTIFIER=") + _local2.getID()) + "&user=") + this._userID) + "&s=") + _local2.getsize());
  190. _local1.data = _local3;
  191. _local1.method = URLRequestMethod.POST;
  192. this.enableFileEvents(_local4, true);
  193. this.startTimeOutTracker();
  194. _local4.upload(_local1);
  195. }
  196. private function enableFileEvents(_arg1:FileReference, _arg2:boolean):void{
  197. var _local3:function;
  198. if (_arg2){
  199. _local3 = _arg1.addEventListener;
  200. } else {
  201. _local3 = _arg1.removeEventListener;
  202. };
  203. _local3(Event.OPEN, this.handleFileUploadEvent);
  204. _local3(IOErrorEvent.IO_ERROR, this.handleFileUploadEvent);
  205. _local3(SecurityErrorEvent.SECURITY_ERROR, this.handleFileUploadEvent);
  206. _local3(HTTPStatusEvent.HTTP_STATUS, this.handleFileUploadEvent);
  207. _local3(ProgressEvent.PROGRESS, this.handleFileUploadEvent);
  208. _local3(Event.COMPLETE, this.handleFileUploadEvent);
  209. _local3(DataEvent.UPLOAD_COMPLETE_DATA, this.handleFileUploadEvent);
  210. }
  211. private function handleFileUploadEvent(_arg1:object):void{
  212. var _local3:string;
  213. var _local2:FileReference = FileReference(_arg1.currentTarget);
  214. switch (_arg1.type){
  215. case Event.OPEN:
  216. JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_START, {fileID:this.getProcessedFile().getID()});
  217. break;
  218. case IOErrorEvent.IO_ERROR:
  219. this.stopTimeOutTracker();
  220. this.enableFileEvents(_local2, false);
  221. this.verifyEarlyCompletion();
  222. break;
  223. case SecurityErrorEvent.SECURITY_ERROR:
  224. this.stopTimeOutTracker();
  225. this.enableFileEvents(_local2, false);
  226. this.errorFile();
  227. break;
  228. case HTTPStatusEvent.HTTP_STATUS:
  229. this.stopTimeOutTracker();
  230. this.enableFileEvents(_local2, false);
  231. this.errorFile();
  232. break;
  233. case ProgressEvent.PROGRESS:
  234. this._lastProgressTime = new date().gettime();
  235. _local3 = this.getProcessedFile().getID();
  236. JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_PROGRESS, {
  237. fileID:_local3,
  238. bytesloaded:_arg1.bytesloaded,
  239. bytestotal:_arg1.bytestotal
  240. });
  241. break;
  242. case Event.COMPLETE:
  243. this.stopTimeOutTracker();
  244. break;
  245. case DataEvent.UPLOAD_COMPLETE_DATA:
  246. this.stopTimeOutTracker();
  247. this.enableFileEvents(_local2, false);
  248. this.successFile(_arg1.data);
  249. break;
  250. case Event.CANCEL:
  251. };
  252. }
  253. private function addSelectedValidFiles(_arg1:FileReferenceList):void{
  254. var big:* = false;
  255. var fileRef:* = null;
  256. var file:* = null;
  257. var fileProps:* = null;
  258. var j:* = 0;
  259. var fileRefList:* = _arg1;
  260. var files:* = fileRefList.fileList;
  261. var newFiles:* = [];
  262. var i:* = 0;
  263. while (i < files.length) {
  264. fileRef = files[i];
  265. try {
  266. if (fileRef.size > 4294967296){
  267. big = true;
  268. } else {
  269. big = false;
  270. };
  271. } catch(e:IOError) {
  272. big = true;
  273. };
  274. if (!big){
  275. if (!this.isDuplicatedFile(fileRef)){
  276. file = new File(fileRef, this.getRandomServer());
  277. newFiles.push(file);
  278. this._allFiles.push(file);
  279. };
  280. };
  281. i = (i + 1);
  282. };
  283. if (newFiles.length > 0){
  284. fileProps = "";
  285. j = 0;
  286. while (j < newFiles.length) {
  287. fileProps = (fileProps + ((((File(newFiles[j]).getID() + ";") + encodeURIComponent(File(newFiles[j]).getName())) + ";") + File(newFiles[j]).getsize()));
  288. if (j < (newFiles.length - 1)){
  289. fileProps = (fileProps + "||");
  290. };
  291. j = (j + 1);
  292. };
  293. JsEventDispatcher.dispatchEvent(JsEventDispatcher.FILES_ADDED, {fileProps:fileProps});
  294. };
  295. }
  296. private function verifyEarlyCompletion():void{
  297. var _local1:URLLoader = new URLLoader();
  298. var _local2:URLRequest = new URLRequest();
  299. var _local3:URLVariables = new URLVariables();
  300. var _local4:File = this.getProcessedFile();
  301. _local3.name = _local4.getName();
  302. _local3.user = this._userID;
  303. _local3.message = _local4.getDescription();
  304. _local3.password = _local4.getPassword();
  305. _local3.trafficurl = _local4.getTrafficExchange();
  306. _local3.toemail = _local4.getRecipientEmail();
  307. _local3.fromemail = _local4.getUploaderEmail();
  308. _local3.multiemail = _local4.getMultipleRecipients();
  309. _local2.url = ((((_local4.getServer() + "uploadquick.php?UPLOAD_IDENTIFIER=") + _local4.getID()) + "&user=") + this._userID);
  310. _local2.method = URLRequestMethod.POST;
  311. _local2.data = _local3;
  312. _local1.addEventListener(Event.COMPLETE, this.verificationXMLSuccess);
  313. _local1.addEventListener(IOErrorEvent.IO_ERROR, this.verificationXMLError);
  314. _local1.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.verificationXMLError);
  315. _local1.load(_local2);
  316. }
  317. private function verificationXMLSuccess(_arg1:Event):void{
  318. URLLoader(_arg1.currentTarget).removeEventListener(Event.COMPLETE, this.verificationXMLSuccess);
  319. URLLoader(_arg1.currentTarget).removeEventListener(IOErrorEvent.IO_ERROR, this.verificationXMLError);
  320. URLLoader(_arg1.currentTarget).removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.verificationXMLError);
  321. var _local2:xml = xml(_arg1.target.data);
  322. if (_local2.children().length() > 0){
  323. if (((_local2.children()[0].hasOwnProperty("@url")) && (!((_local2.children()[0].@url == ""))))){
  324. this.terminateFile(_local2.children()[0].@url);
  325. } else {
  326. this.errorFile();
  327. };
  328. } else {
  329. this.errorFile();
  330. };
  331. }
  332. private function verificationXMLError(_arg1:Event):void{
  333. URLLoader(_arg1.currentTarget).removeEventListener(Event.COMPLETE, this.verificationXMLSuccess);
  334. URLLoader(_arg1.currentTarget).removeEventListener(IOErrorEvent.IO_ERROR, this.verificationXMLError);
  335. URLLoader(_arg1.currentTarget).removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.verificationXMLError);
  336. this.errorFile();
  337. }
  338. private function isDuplicatedFile(_arg1:FileReference):boolean{
  339. var _local3:File;
  340. var _local2:uint;
  341. while (_local2 < this._allFiles.length) {
  342. _local3 = this._allFiles[_local2];
  343. if ((((_local3.getName() == _arg1.name)) && ((_local3.getsize() == _arg1.size)))){
  344. return (true);
  345. };
  346. _local2++;
  347. };
  348. return (false);
  349. }
  350. private function startTimeOutTracker():void{
  351. if (!this._timeOutTimer.running){
  352. this._timeOutTimer.start();
  353. };
  354. }
  355. private function stopTimeOutTracker():void{
  356. if (this._timeOutTimer.running){
  357. this._timeOutTimer.reset();
  358. };
  359. }
  360. private function timeOutTick(_arg1:TimerEvent):void{
  361. var _local2:number = new date().gettime();
  362. if ((_local2 - this._lastProgressTime) > TIME_OUT_TIME){
  363. this.getProcessedFile().getFileReference().cancel();
  364. this.stopTimeOutTracker();
  365. this.verifyEarlyCompletion();
  366. };
  367. }
  368. private function errorFile():void{
  369. JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_ERROR, {fileID:this.getProcessedFile().getID()});
  370. this.uploadNextFile();
  371. }
  372. private function terminateFile(_arg1:string):void{
  373. JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_SUCCESS, {
  374. fileID:this.getProcessedFile().getID(),
  375. url:_arg1
  376. });
  377. this.uploadNextFile();
  378. }
  379. private function successFile(_arg1:string):void{
  380. var arr:* = null;
  381. var fileURL:* = null;
  382. var data:* = _arg1;
  383. try {
  384. arr = data.split(";");
  385. arr = arr[2].split("'");
  386. fileURL = string(arr[1]);
  387. if ((((fileURL == "undefined")) || ((fileURL == "")))){
  388. this.errorFile();
  389. return;
  390. };
  391. JsEventDispatcher.dispatchEvent(JsEventDispatcher.UPLOAD_SUCCESS, {
  392. fileID:this.getProcessedFile().getID(),
  393. url:fileURL
  394. });
  395. this.uploadNextFile();
  396. } catch(e:error) {
  397. errorFile();
  398. uploadNextFile();
  399. };
  400. }
  401. private function getProcessedFile():File{
  402. return (this._allFiles[this._processedFileIndex]);
  403. }
  404. private function uploadNextFile():void{
  405. if (this._processedFileIndex < (this._allFiles.length - 1)){
  406. this._processedFileIndex++;
  407. this.uploadFile();
  408. } else {
  409. this._status = STATUS_FINISHED;
  410. };
  411. }
  412. private function getRandomServer():string{
  413. var _local1:number = math.round((math.random() * (this._serverList.length - 1)));
  414. return (this._serverList[_local1]);
  415. }
  416. public function startUpload():void{
  417. if (this._allFiles.length > 0){
  418. this._status = STATUS_UPLOADING;
  419. this._processedFileIndex = 0;
  420. this.uploadFile();
  421. };
  422. }
  423. public function removeFile(_arg1:string):void{
  424. var _local2:uint;
  425. var _local3:boolean;
  426. var _local4:uint;
  427. if (this._status == STATUS_FILE_SELECT){
  428. _local2 = 0;
  429. while (_local2 < this._allFiles.length) {
  430. if (this._allFiles[_local2].getID() == _arg1){
  431. this._allFiles.splice(_local2, 1);
  432. break;
  433. };
  434. _local2++;
  435. };
  436. } else {
  437. if (this._status == STATUS_UPLOADING){
  438. _local3 = false;
  439. if (this.getProcessedFile().getID() == _arg1){
  440. this.stopTimeOutTracker();
  441. this.enableFileEvents(this.getProcessedFile().getFileReference(), false);
  442. this.getProcessedFile().getFileReference().cancel();
  443. _local3 = true;
  444. };
  445. _local4 = 0;
  446. while (_local4 < this._allFiles.length) {
  447. if (this._allFiles[_local4].getID() == _arg1){
  448. this._allFiles.splice(_local4, 1);
  449. if (_local3){
  450. this._processedFileIndex--;
  451. };
  452. break;
  453. };
  454. _local4++;
  455. };
  456. if (_local3){
  457. this.uploadNextFile();
  458. };
  459. };
  460. };
  461. }
  462. public function updateFileProperties(_arg1:string, _arg2:string, _arg3:string, _arg4:string, _arg5:string, _arg6:string, _arg7:string):void{
  463. var _local8:File;
  464. var _local9:uint;
  465. if (this._status == STATUS_FILE_SELECT){
  466. _local9 = 0;
  467. while (_local9 < this._allFiles.length) {
  468. if (this._allFiles[_local9].getID() == _arg1){
  469. _local8 = this._allFiles[_local9];
  470. break;
  471. };
  472. _local9++;
  473. };
  474. _local8.setDescription(_arg2);
  475. _local8.setUploaderEmail(_arg3);
  476. _local8.setRecipientEmail(_arg4);
  477. _local8.setPassword(_arg5);
  478. _local8.setHotlink(_arg6);
  479. _local8.setMultipleRecipients(_arg7);
  480. };
  481. }
  482.  
  483. }
  484. }//package com.mega.fileuploader
  485. package com.mega.fileuploader {
  486. import flash.external.*;
  487.  
  488. public class JsEventDispatcher {
  489.  
  490. public static const FILES_ADDED:string = "filesAdded";
  491. public static const FILES_REMOVED:string = "filesRemoved";
  492. public static const UPLOAD_START:string = "uploadStart";
  493. public static const UPLOAD_PROGRESS:string = "uploadProgress";
  494. public static const UPLOAD_SUCCESS:string = "uploadSuccess";
  495. public static const UPLOAD_ERROR:string = "uploadError";
  496. public static const UPLOAD_CANCEL:string = "uploadCancel";
  497.  
  498. public static function dispatchEvent(_arg1:string, _arg2:object):void{
  499. switch (_arg1){
  500. case UPLOAD_START:
  501. ExternalInterface.call("onUploadStart", _arg2.fileID);
  502. break;
  503. case UPLOAD_PROGRESS:
  504. ExternalInterface.call("onUploadProgress", _arg2.fileID, _arg2.bytesloaded, _arg2.bytestotal);
  505. break;
  506. case UPLOAD_SUCCESS:
  507. ExternalInterface.call("onUploadSuccess", _arg2.fileID, _arg2.url);
  508. break;
  509. case UPLOAD_ERROR:
  510. ExternalInterface.call("onUploadError", _arg2.fileID);
  511. break;
  512. case UPLOAD_CANCEL:
  513. break;
  514. case FILES_ADDED:
  515. ExternalInterface.call("onFileSelect", _arg2.fileProps);
  516. break;
  517. };
  518. }
  519.  
  520. }
  521. }//package com.mega.fileuploader
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement