-
Notifications
You must be signed in to change notification settings - Fork 309
/
index.js
3524 lines (3034 loc) · 116 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* global MegaData instance
* @name M
*/
var M = null;
var dlid = false;
var dlkey = false;
var cn_url = false;
var init_l = true;
var pfkey = false;
var pfcol = false;
var pfid = false;
var pfhandle = false;
var n_h = false;
var u_n = false;
var n_k_aes = false;
var fmdirid = false;
var u_type, cur_page, u_checked;
var confirmcode = false;
var confirmok = false;
var hash = window.location.hash;
var chrome_msg = false;
var init_anoupload = false;
var pwchangecode = false;
var resetpwcode = false;
var resetpwemail = '';
var mobileparsed = false;
var mobilekeygen = false;
var subdirid = false;
var subsubdirid = false;
var unread;
var account = false;
var register_txt = false;
var login_next = false;
var loggedout = false;
var flhashchange = false;
var avatars = Object.create(null);
var mega_title = 'MEGA';
var pro_json = '[[["N02zLAiWqRU",1,500,1024,1,"9.99","EUR"],["zqdkqTtOtGc",1,500,1024,12,"99.99","EUR"],["j-r9sea9qW4",2,2048,4096,1,"19.99","EUR"],["990PKO93JQU",2,2048,4096,12,"199.99","EUR"],["bG-i_SoVUd0",3,4096,8182,1,"29.99","EUR"],["e4dkakbTRWQ",3,4096,8182,12,"299.99","EUR"]]]';
pages.placeholder = '<div class="bottom-page scroll-block placeholder selectable-txt">' +
'((TOP))' +
'<div class="main-pad-block">' +
'<div class="main-mid-pad new-bottom-pages"></div>' +
'</div>';
mBroadcaster.once('startMega', function() {
'use strict';
if (pages['dialogs-common']) {
$('body').safeAppend(translate(pages['dialogs-common'].replace(/{staticpath}/g, staticpath)));
delete pages['dialogs-common'];
}
// Set class if gbot
if (is_bot) {
document.documentElement.classList.add('gbot');
}
else {
document.documentElement.classList.remove('gbot');
}
// Add language class to body for CSS fixes for specific language strings
document.body.classList.add(lang);
if (({'fa': 1,'ar': 1,'he': 1})[lang]) {
document.body.classList.add('rtl');
}
if (is_mobile) {
const usingMobPages = ['placeholder', 'register', 'key', 'support', 'keybackup',
'disputenotice', 'download', 'reset', 'propay', 'login'];
for (let i = usingMobPages.length; i--;) {
delete pages[usingMobPages[i]];
jsl_loaded[usingMobPages[i]] = 1;
}
pages = new Proxy(pages, {
get(target, prop) {
if (target[prop] === undefined) {
if (d) {
console.info(`[proxy] providing 'mobile' page for '${prop}'`);
}
return target.mobile || '';
}
return target[prop] || '';
}
});
}
});
mBroadcaster.once('startMega:desktop', function() {
'use strict';
var $body = $('body');
var p = ['chat', 'onboarding', 'dialogs'];
for (var i = p.length; i--;) {
if (typeof pages[p[i]] === 'string') {
$body.safeAppend(translate(pages[p[i]].replace(/{staticpath}/g, staticpath)));
delete pages[p[i]];
}
}
$('#avatar-svg').safeAppend(pages.contact_avatar);
delete pages.contact_avatar;
});
function startMega() {
'use strict';
jsl = [];
mBroadcaster.sendMessage('startMega');
if (is_mobile) {
mBroadcaster.sendMessage('startMega:mobile');
mBroadcaster.removeListeners('startMega:desktop');
}
else {
mBroadcaster.sendMessage('startMega:desktop');
mBroadcaster.removeListeners('startMega:mobile');
}
if (silent_loading) {
loadingDialog.hide('jsl-loader');
onIdle(silent_loading);
silent_loading = false;
}
else {
init_page();
}
}
function topMenu(close) {
'use strict';
let $currentContainer;
const fmholder = document.getElementById('fmholder');
// If #startholder is visible, #fmholder is not
if (fmholder.classList.contains('hidden') || fmholder.style.display === 'none') {
$currentContainer = $('#startholder');
}
else {
$currentContainer = $(fmholder);
}
var $topMenuBtn = $('.js-more-menu', $currentContainer);
var $topMenu = $('.top-menu-popup', $currentContainer);
var $scrollBlock = $('.top-menu-scroll', $topMenu);
var $mobileOverlay = $('.mobile.dark-overlay', 'body');
if (close) {
$.topMenu = '';
$topMenuBtn.removeClass('menu-open');
$topMenu.addClass('o-hidden');
// If on mobile, hide the menu and also remove the close click/tap handler on the dark background overlay
if (is_mobile) {
$('html').removeClass('overlayed');
$mobileOverlay.addClass('hidden').removeClass('active').unbind('tap.topmenu');
}
$(window).off('resize.topmenu');
if (M.chat && megaChatIsReady) {
megaChat.plugins.chatOnboarding.checkAndShowStep();
}
}
else {
$.topMenu = 'topmenu';
$topMenuBtn.addClass('menu-open');
$topMenu.removeClass('o-hidden');
if (M.chat && $.dialog === 'onboardingDialog') {
closeDialog();
}
if (u_type) {
const $menuAvatar = $('.avatar-block', $topMenu);
if (!$menuAvatar.hasClass('rendered')) {
$menuAvatar.addClass('rendered');
$('.wrapper', $menuAvatar).safeHTML(useravatar.contact(u_handle));
}
$('.top-menu-logged .loader', $topMenu).addClass('loading');
Promise.resolve(M.storageQuotaCache || M.getStorageQuota())
.then((data) => {
topMenuDataUpdate(data);
if (fminitialized && !folderlink && M.currentTreeType === 'cloud-drive') {
return M.checkLeftStorageBlock(data);
}
})
.catch(dump);
}
if (!is_mobile) {
topMenuScroll($scrollBlock);
}
else {
// Show the dark backround overlay behind the menu and if it's clicked, close the menu
$('html').addClass('overlayed');
$mobileOverlay.removeClass('hidden').addClass('active').rebind('tap.topmenu', function() {
topMenu(true);
return false;
});
}
}
}
/* Update used storage info*/
function topMenuDataUpdate(data) {
'use strict';
var storageHtml;
var $storageBlock = $('.top-menu-logged', '.top-menu-popup').removeClass('going-out exceeded');
var space_used = bytesToSize(data.used);
var space = bytesToSize(data.max, 0);
var perc = data.percent;
if (perc >= 100) {
$storageBlock.addClass('exceeded');
}
else if (perc >= data.uslw / 100) {
$storageBlock.addClass('going-out');
}
// Show only space_used for Business and Pro Flexi accounts
if (u_attr && (u_attr.b || u_attr.pf)) {
storageHtml = '<span>' + space_used + '</span>';
}
else {
storageHtml = l[1607].replace('%1', '<span>' + space_used + '</span>')
.replace('%2', space);
}
$('.loader', $storageBlock).removeClass('loading');
$('.storage-txt', $storageBlock).safeHTML(storageHtml);
const $storageBar = $('.storage', $storageBlock);
if (u_attr && !u_attr.pf) {
$('span', $storageBar).outerWidth(perc + '%');
$storageBar.removeClass('hidden');
}
else {
$storageBar.addClass('hidden');
}
}
function topMenuScroll($scrollBlock) {
"use strict";
if (!$scrollBlock.length) {
return false;
}
if ($scrollBlock.is('.ps')) {
Ps.update($scrollBlock[0]);
}
else {
Ps.initialize($scrollBlock[0]);
}
}
function scrollMenu() {
"use strict";
$('.bottom-pages .fmholder').rebind('scroll.devmenu', function() {
if (page === 'doc' || page.substr(0, 9) === 'corporate' || page === 'sdk' || page === 'dev') {
var $menu = $('.new-left-menu-block');
var topPos = $(this).scrollTop();
if (topPos > 0) {
if (topPos + $menu.outerHeight() + 106 <= $('.main-mid-pad').outerHeight()) {
$menu.css('top', topPos + 50 + 'px').addClass('floating');
}
else {
$menu.removeClass('floating');
}
}
else {
$menu.removeAttr('style');
}
}
});
}
function topPopupAlign(button, popup, topPos) {
'use strict';
const popupAlign = () => {
var $button = $(button),
$popup = $(popup),
$popupArrow = $popup.children('.dropdown-white-arrow'),
pageWidth,
popupLeftPos,
arrowLeftPos,
buttonTopPos,
headerWidth;
if ($button.length && $popup.length) {
pageWidth = $('body').outerWidth();
headerWidth = $('.top-head').outerWidth();
$popup.removeAttr('style');
$popupArrow.removeAttr('style');
popupLeftPos = $button.offset().left
+ $button.outerWidth() / 2
- $popup.outerWidth() / 2;
if (topPos) {
$popup.css('top', topPos + 'px');
}
else {
buttonTopPos = $button.offset().top + $button.outerHeight();
$popup.css('top', buttonTopPos + 13 + 'px');
}
if (popupLeftPos > 10) {
if (popupLeftPos + $popup.outerWidth() + 10 > pageWidth) {
$popup.css({
left: 'auto',
right: '10px'
});
$popupArrow.css(
'left', $button.offset().left - $button.outerWidth() / 2
);
}
else {
$popup.css('left', popupLeftPos + 'px');
}
}
else {
$popup.css('left', '10px');
arrowLeftPos = $button.offset().left
- $button.outerWidth() / 2;
$popupArrow.css({
left: arrowLeftPos + 22
})
}
}
};
// If top menu is opened - set timeout to count correct positions
if (!$('.top-menu-popup').hasClass('o-hidden') || $('body').hasClass('hidden')) {
tSleep(0.2).then(() => requestAnimationFrame(popupAlign));
}
else {
requestAnimationFrame(popupAlign);
}
}
function init_page() {
page = String(page || (u_type ? 'fm' : 'start'));
if (!window.M || is_megadrop) {
return console.warn('Something went wrong, the initialization did not completed...');
}
if (mega.ensureAccessibility) {
if (mega.ensureAccessibility() !== 'accessible') {
console.error('Unable to ensure accessibility...');
return false;
}
delete mega.ensureAccessibility;
}
// If they are transferring from mega.co.nz
if (page.substr(0, 13) == 'sitetransfer!') {
// If false, then the page is changing hash URL so don't continue past here
if (M.transferFromMegaCoNz() === false) {
return false;
}
}
// Users that logged in and are suspended (requiring special SMS unlock) are not allowed to go anywhere else in the
// site until they validate their account. So if they clicked the browser back button, then they should get logged
// out or they will end up with with a partially logged in account stuck in an infinite loop. This logout is not
// triggered on the mobile web sms/ pages because a session is still required to talk with the API to get unlocked.
if (window.doUnloadLogOut) {
return false;
}
dlkey = false;
var pageBeginLetters = page.substr(0, 2);
if (page.length > 2 && (page[0] === '!' || pageBeginLetters === 'F!')) {
// Convering old links to new links format.
page = page[0] === 'F' ? page.replace('F!', 'folder/').replace('!', '#')
.replace('!', '/folder/').replace('?', '/file/')
: page.replace('!', 'file/').replace('!', '#');
history.replaceState({ subpage: page }, "", (hashLogic ? '#' : '/') + page);
return init_page();
}
if (page.substr(0, 5) === 'file/') {
dlid = page.substr(5, 8).replace(/[^\w-]+/g, '');
dlkey = page.substr(14).replace(/[^\w-].+$/, '');
if (M.hasPendingTransfers() && $.lastSeenFilelink !== getSitePath()) {
page = 'download';
M.abortTransfers().then(() => location.reload()).catch(() => loadSubPage($.lastSeenFilelink));
return;
}
$.lastSeenFilelink = getSitePath();
}
// Rmove business class to affect the top header
// Remove bottom-page class and old class
// Remove pro class when user come back from pro page
document.body.classList.remove('business', 'bottom-pages', 'old', 'pro', 'mega-lite-mode');
// Add mega-lite-mode class to hide/show various elements in MEGA Lite mode
if (mega.lite.inLiteMode) {
document.body.classList.add('mega-lite-mode');
}
// Redirect url to extensions when it tries to go plugin or chrome or firefox
if (page === 'plugin') {
mega.redirect('mega.io', 'extensions', false, false);
return false;
}
if (page === "fm/contacts") {
// force replace of page history, so that back won't cause the user to go back to an empty fm/contacts
loadSubPage("/fm/chat/contacts");
return false;
}
if (page === "fm/ipc") {
if (u_type) {
return loadSubPage("/fm/chat/contacts/received");
}
login_next = '/fm/chat/contacts/received';
return loadSubPage('/login');
}
if (page === "fm/opc") {
return loadSubPage("/fm/chat/contacts/sent");
}
$('#loading').hide();
if (window.loadingDialog) {
loadingDialog.hide('force');
}
if (is_chatlink || page.substr(0, 5) === 'chat/') {
if (fminitialized && megaChatIsReady) {
// tried to navigate internally to a chat link, do a force redirect.
// Can be triggered by the back button.
assert(
megaChat.initialChatId,
'missing .initialChatId, did this page initialized from a standalone chat/meeting link?'
);
loadSubPage(`fm/chat/c/${megaChat.initialChatId}`);
return false;
}
page = page.slice(0, 36);
const [publicChatHandle, publicChatKey] = page.replace('chat/', '').split('#');
if (!publicChatHandle || publicChatHandle.length !== 8 || !publicChatKey || publicChatKey.length !== 22) {
return u_type
? loadSubPage('fm/chat')
: mega.redirect('mega.io', 'chatandmeetings', false, false);
}
if (typeof is_chatlink !== 'object') {
is_chatlink = Object.create(null);
}
Object.defineProperties(is_chatlink, {
ph: { value: publicChatHandle },
key: { value: publicChatKey },
pnh: {
get: function() {
return this.url && this.ph;
}
}
});
M.chat = true;
if (!u_handle) {
assert(!u_type);
u_handle = "AAAAAAAAAAA";
}
parsepage(pages.chatlink);
const init = () => {
init_chat(0x104DF11E5)
.then(() => megaChat.renderListing(page, true))
.then(() => megaChat.renderMyStatus())
.then(() => {
document.querySelector('.chat-links-preview .chat-links-logo-header a.logo')
.addEventListener('click', () => {
is_chatlink = false;
delete megaChat.initialPubChatHandle;
delete M.currentdirid;
megaChat.destroy();
if (u_type) {
loadSubPage("fm");
}
else {
loadSubPage("start");
}
});
$(`.chat-links-preview${is_mobile ? '.mobile' : '.section'}`).removeClass('hidden');
})
.dump('init_chat');
};
// Authring (user's keys) are required to be loaded before the chat is, otherwise strongvelope would init
// with undefined pub keys
if (u_type) {
// show loading
for (const node of document.querySelectorAll(
'.section.chat-links-preview, .section.chat-links-preview .fm-chat-is-loading'
)) {
node.classList.remove('hidden');
}
// init authring -> init chat
authring.onAuthringReady()
.then(init, (ex) => {
console.error("Failed to initialize authring:", ex);
});
}
else {
init();
}
mega.ui.setTheme();
return;
}
is_chatlink = false;
var oldPFKey = pfkey;
// contact link handling...
if (pageBeginLetters === 'C!' && page.length > 2) {
var ctLink = page.substring(2, page.length);
if (!is_mobile) {
if (!u_type) {
parsepage(pages.placeholder);
openContactInfoLink(ctLink);
return;
}
else {
page = 'fm/chat/contacts';
mBroadcaster.once('fm:initialized', function() {
openContactInfoLink(ctLink);
});
}
}
else {
var processContactLink = function() {
if (!mega.ui.contactLinkCardDialog) {
var contactLinkCardHtml = pages['mobile-add-contact-card'];
if (contactLinkCardHtml) {
mega.ui.contactLinkCardDialog = contactLinkCardHtml;
}
}
var contactInfoCard = new MobileContactLink(ctLink);
contactInfoCard.showContactLinkInfo();
};
if (!u_type) {
parsepage(pages.placeholder);
processContactLink();
return;
}
else {
loadSubPage('fm');
M.onFileManagerReady(processContactLink);
return;
}
}
}
var newLinkSelector = '';
if (page.startsWith('folder/') || page.startsWith('collection/')) {
const pos = page.indexOf('/') + 1;
let phLen = page.indexOf('#');
let possibleS = -1;
if (phLen < 0) {
phLen = page.length;
possibleS = page.indexOf('/f', pos);
if (possibleS > -1) {
phLen = possibleS;
}
}
pfid = page.substr(pos, phLen - pos).replace(/[^\w-]+/g, "");
// check if we have key
pfkey = false;
pfhandle = false;
pfcol = page.startsWith('collection/');
if (page.length - phLen > 2) {
if (possibleS === -1) {
phLen++;
}
const [linkRemaining] = page.substr(phLen, page.length - phLen).split('?');
var fileSelectorPlace = linkRemaining.indexOf('/file/');
var folderSelectorPlace = linkRemaining.indexOf('/folder/');
var selectorIsValid = false;
if (fileSelectorPlace > -1 || folderSelectorPlace > -1) {
selectorIsValid = true;
}
if (selectorIsValid && fileSelectorPlace > -1 && folderSelectorPlace > -1) {
selectorIsValid = false;
}
var keyCutPlace;
if (selectorIsValid) {
if (fileSelectorPlace > -1) {
keyCutPlace = fileSelectorPlace;
if (linkRemaining.length - 6 - fileSelectorPlace > 2) {
$.autoSelectNode = linkRemaining.substring(fileSelectorPlace + 6, linkRemaining.length);
$.autoSelectNode = $.autoSelectNode.replace(/[^\w-]+/g, "");
}
}
else {
keyCutPlace = folderSelectorPlace;
if (linkRemaining.length - 8 - folderSelectorPlace > 2) {
pfhandle = linkRemaining.substring(folderSelectorPlace + 8, linkRemaining.length);
pfhandle = pfhandle.replace(/[^\w-]+/g, "");
newLinkSelector = '/folder/' + pfhandle;
}
}
}
else {
keyCutPlace = Math.min(fileSelectorPlace, folderSelectorPlace);
if (keyCutPlace === -1) {
keyCutPlace = linkRemaining.length;
}
}
pfkey = linkRemaining.substring(0, keyCutPlace).replace(/[^\w-]+/g, "").slice(0, 22) || false;
}
n_h = pfid;
if (!flhashchange || pfkey !== oldPFKey || pfkey.length !== 22 || pfid.length !== 8) {
closeDialog();
const data = JSON.stringify([
1,
!oldPFKey | 0, !!flhashchange | 0, (pfkey !== oldPFKey) | 0,
pfkey.length | 0, pfid.length | 0, window[`preflight-folder-link-error:${pfid}`] | 0
]);
eventlog(pfcol ? is_mobile ? 99911 : 99910 : is_mobile ? 99631 : 99632, data, true);
if (pfid.length !== 8 || window['preflight-folder-link-error:' + pfid]) {
folderreqerr(false, window['preflight-folder-link-error:' + pfid] || EARGS);
return false;
}
if (pfkey.length === 22) {
api_setfolder(n_h);
waitsc.poke();
u_n = pfid;
}
else {
// Insert placeholder background page while waiting for user input
parsepage(pages.placeholder);
// Let's apply theme for this dialog
mega.ui.setTheme();
onIdle(topmenuUI);
// Show the decryption key dialog on top
mKeyDialog(pfid, true, pfkey, newLinkSelector)
.catch(() => {
loadSubPage('start');
});
pfkey = false;
return false;
}
if (fminitialized && (!folderlink || pfkey !== oldPFKey)) {
// Clean up internal state in case we're navigating back to a folderlink
M.currentdirid = M.RootID = M.currentCustomView = undefined;
delete $.onImportCopyNodes;
delete $.mcImport;
delete $.albumImport;
}
}
if (pfhandle) {
page = 'fm/' + pfhandle;
}
else {
page = 'fm';
}
}
else if (!flhashchange || page !== 'fm/transfers') {
if (pfcol) {
pfcol = false;
mega.gallery.albums.disposeAll();
mega.gallery.removeDbActionCache();
mega.gallery.albumsRendered = false;
}
n_h = false;
u_n = false;
pfkey = false;
pfid = false;
pfhandle = false;
}
confirmcode = false;
pwchangecode = false;
if (pageBeginLetters.toLowerCase() === 'n!') {
return invalidLinkError();
}
if (page.substr(0, 7) === 'confirm') {
confirmcode = page.replace("confirm", "");
page = 'confirm';
}
if (page.substr(0, 7) == 'pwreset') {
resetpwcode = page.replace("pwreset", "");
page = 'resetpassword';
}
// If password revert link, use generic background page, show the dialog and pass in the code
if (page.substr(0, 8) === 'pwrevert') {
parsepage(pages.placeholder);
passwordRevert.init(page);
// Make sure placeholder background is shown
return false;
}
if ((pfkey && !flhashchange || dlkey) && !location.hash) {
return location.replace(getAppBaseUrl());
}
if (!$.mcImport && $.dialog !== 'cookies-dialog' && typeof closeDialog === 'function') {
closeDialog();
}
// Pages that can be viewed while being logged in and registered but not yet email confirmed
if ((page.substr(0, 1) !== '!')
&& (page.substr(0, 3) !== 'pro')
&& (page.substr(0, 5) !== 'start' || is_fm())
&& (page.substr(0, 13) !== 'discountpromo') // Discount Promo with regular discount code on the end
&& (page.substr(0, 2) !== 's/') // Discount Promo short URL e.g. /s/blackfriday
&& (page.substr(0, 8) !== 'payment-') // Payment URLs e.g. /payment-ecp-success, /payment-sabadell-failure etc
&& (page !== 'refer')
&& (page !== 'contact')
&& (page !== 'mobileapp')
&& (page !== 'nas')
&& (page !== 'extensions')
&& (page !== 'chrome')
&& (page !== 'firefox')
&& (page !== 'edge')
&& (page !== 'desktop')
&& (page !== 'sync')
&& (page !== 'cmd')
&& (page !== 'terms')
&& (page !== 'privacy')
&& (page !== 'gdpr')
&& (page !== 'takendown')
&& (page !== 'resellers')
&& (page !== 'security')
&& (page !== 'storage')
&& (page !== 'objectstorage')
&& (page !== 'megabackup')
&& (page !== 'collaboration')
&& (page !== 'securechat')
&& (page !== 'unsub')
&& (page !== 'cookie')
&& (page.indexOf('file/') === -1)
&& (page.indexOf('folder/') === -1)
&& !page.startsWith('collection/')
&& localStorage.awaitingConfirmationAccount) {
var acc = JSON.parse(localStorage.awaitingConfirmationAccount);
// if visiting a #confirm link, or they confirmed it elsewhere.
if (confirmcode || u_type > 1) {
delete localStorage.awaitingConfirmationAccount;
}
else {
parsepage(pages.placeholder);
// Show signup link dialog for mobile
if (is_mobile) {
mobile.register.showConfirmEmailScreen(acc);
return false;
}
else {
// Insert placeholder page while waiting for user input
return mega.ui.sendSignupLinkDialog(acc, function () {
// The user clicked 'close', abort and start over...
delete localStorage.awaitingConfirmationAccount;
init_page();
});
}
}
}
// If the account has just finished being cancelled
if (localStorage.beingAccountCancellation) {
// Insert placeholder page while waiting for user input
parsepage(pages.placeholder);
// Show message that the account has been cancelled successfully
msgDialog('warninga', l[6188], l[6189], '', loadSubPage.bind(null, 'start'));
delete localStorage.beingAccountCancellation;
return false;
}
if (page.substr(0, 2) === 'P!' && page.length > 2) {
// Password protected link decryption dialog
parsepage(pages.placeholder);
if (is_mobile) {
mobile.passwordDecryption.show(page);
}
else {
exportPassword.decrypt.init(page);
}
// lets set them for the dialog.
mega.ui.setTheme();
}
else if (page.substr(0, 4) === 'blog') {
window.location.replace('https://blog.mega.io');
}
else if (page.substr(0, 6) == 'verify') {
if (is_mobile) {
mobile.settings.account.verifyEmail.init();
}
else {
parsepage(pages.change_email);
emailchange.main();
}
}
else if (page === 'corporate/reviews') {
window.location.replace('/login'); // Page removed
}
else if (page.substr(0, 9) === 'corporate') {
mega.redirect('mega.io', 'media', false, false);
}
// If user has been invited to join MEGA and they are not already registered
else if (page.substr(0, 9) == 'newsignup') {
// Get the email and hash checksum from after the #newsignup tag
var emailAndHash = page.substr(9);
var emailAndHashDecoded = base64urldecode(emailAndHash);
// Separate the email and checksum portions
var endOfEmailPosition = emailAndHashDecoded.length - 8;
var email = emailAndHashDecoded.substring(0, endOfEmailPosition);
var hashChecksum = emailAndHashDecoded.substring(endOfEmailPosition);
// Hash the email address
var hashBytes = asmCrypto.SHA512.bytes(email);
// Convert the first 8 bytes of the email to a Latin1 string for comparison
var byteString = '';
for (var i = 0; i < 8; i++) {
byteString += String.fromCharCode(parseInt(hashBytes[i]));
}
// Unset registration email
localStorage.removeItem('registeremail');
// If the checksum matches, redirect to #register page
if (hashChecksum === byteString) {
// Store in the localstorage as this gets pre-populated into the register form
localStorage.registeremail = email;
// Redirect to the register page
loadSubPage('register');
}
else {
// Redirect to the register page
loadSubPage('register');
// Show message
alert('We can\'t decipher your invite link, please check you copied the link correctly, or sign up manually with the same email address.');
}
}
else if (page.length > 14 && page.substr(0, 14) === 'businesssignup') {
if (is_mobile) {
parsepage(pages.mobile);
mega.ui.setTheme();
mobile.passwordDecryption.show();
}
else {
var signupCodeEncrypted = page.substring(14, page.length);
M.require('businessAcc_js', 'businessAccUI_js').done(function () {
var business = new BusinessAccountUI();
business.showLinkPasswordDialog(signupCodeEncrypted);
});
}
}
else if (page.length > 14 && page.substr(0, 14) === 'businessinvite') {
if (is_mobile) {
parsepage(pages.mobile);
}
var signupCode = page.substring(14, page.length);
M.require('businessAcc_js', 'businessAccUI_js').done(function () {
var business = new BusinessAccountUI();
business.openInvitationLink(signupCode);
});
}
/**
* If S4 Auth Code from url e.g. #s4acAUTHCODE
*/
else if (page.substr(0, 4) === 's4ac') {
loadSubPage('fm');
}
/**
* Activate S4 Auth Code for Pro Flexi accounts
*/
else if (page === 'activate-s4') {
ActivateS4Page.load();
}
else if (page === 'confirm') {
loadingDialog.show();
security.register.verifyEmailConfirmCode(confirmcode)
.then(({email}) => {
page = 'login';
confirmok = true;
parsepage(pages.login);
onIdle(topmenuUI);
if (is_mobile) {
mobile.register.showConfirmAccountScreen(email);
}
else {
login_txt = l[378];
init_login();
if (email) {
$('#login-name2').val(email).blur();
$('.register-st2-button').addClass('active');
$('#login-name2').prop('readonly', true);
}
}
})
.catch((ex) => {
if (ex === EROLLEDBACK) {
return;
}
page = 'login';
parsepage(pages.login);
if (is_mobile) {
mobile.register.showConfirmAccountFailure(ex);
}
else {
login_txt = ex === ENOENT ? l[19788] : String(ex).includes(l[703]) && l[703] || `${l[705]} ${ex}`;
init_login();
topmenuUI();
}
})
.finally(() => {
loadingDialog.hide();
});
}
else if (page.startsWith('emailverify')) {
return security.showVerifyEmailDialog('login-to-account');
}
else if (u_type == 2) {
parsepage(pages.key);
if (is_mobile) {
mobile.register.showGeneratingKeysScreen();
}
init_key();
}
else if (page == 'login') {