Don't use webpack on boot.js

This commit is contained in:
djmaze 2020-09-03 16:34:23 +02:00
parent b837013cfb
commit fcaa2fd6de
11 changed files with 167 additions and 388 deletions

View file

@ -98,8 +98,8 @@ class AbstractApp extends AbstractBoot {
}
clearClientSideToken() {
if (window.__rlah_clear) {
__rlah_clear();
if (RainLoop.hash.clear) {
RainLoop.hash.clear();
}
}
@ -107,8 +107,8 @@ class AbstractApp extends AbstractBoot {
* @param {string} token
*/
setClientSideToken(token) {
if (window.__rlah_set) {
__rlah_set(token);
if (RainLoop.hash.set) {
RainLoop.hash.set(token);
Settings.settingsSet('AuthAccountHash', token);
populateAuthSuffix();

View file

@ -57,7 +57,6 @@ import QuotaStore from 'Stores/User/Quota';
import * as Local from 'Storage/Client';
import * as Settings from 'Storage/Settings';
import { checkTimestamp } from 'Storage/RainLoop';
import Remote from 'Remote/User/Ajax';
import Promises from 'Promises/User/Ajax';
@ -95,7 +94,7 @@ class AppUser extends AbstractApp {
setInterval(() => {
const currentTime = (new Date()).getTime();
if (currentTime > (lastTime + interval + 1000)) {
if (checkTimestamp()) {
if (RainLoop.hash.check()) {
this.reload();
}
Remote.jsVersion((sResult, oData) => {
@ -107,7 +106,7 @@ class AppUser extends AbstractApp {
lastTime = currentTime;
}, interval);
if (checkTimestamp()) {
if (RainLoop.hash.check()) {
this.reload();
}
@ -919,7 +918,7 @@ class AppUser extends AbstractApp {
bootend() {
if (window.progressJs) {
progressJs.set(100).end();
progressJs.end();
}
hideLoading();
}

View file

@ -1,187 +0,0 @@
import { getHash, setHash, clearHash } from 'Storage/RainLoop';
let RL_APP_DATA_STORAGE = null;
const doc = document;
/* eslint-disable camelcase,spaced-comment */
window.__rlah_set = () => setHash();
window.__rlah_clear = () => clearHash();
window.__rlah_data = () => RL_APP_DATA_STORAGE;
/**
* @returns {void}
*/
function showError() {
const oR = doc.getElementById('rl-loading'),
oL = doc.getElementById('rl-loading-error');
if (oR) {
oR.style.display = 'none';
}
if (oL) {
oL.style.display = 'block';
}
if (window.progressJs) {
progressJs.set(100).end();
}
}
/**
* @param {boolean} withError
* @returns {void}
*/
function runMainBoot(withError) {
if (window.__APP_BOOT && !withError) {
window.__APP_BOOT(() => showError());
} else {
showError();
}
}
function writeCSS(css) {
const style = doc.createElement('style');
style.type = 'text/css';
style.textContent = css;
// style.append(doc.createTextNode(styles));
doc.head.append(style);
}
function loadScript(src) {
if (!src) {
throw new Error('src should not be empty.');
}
return new Promise((resolve, reject) => {
const script = doc.createElement('script');
script.onload = () => resolve();
script.onerror = () => reject(new Error(src));
script.src = src;
// script.type = 'text/javascript';
doc.head.append(script);
// doc.body.append(element);
});
}
/**
* @param {mixed} data
* @returns {void}
*/
window.__initAppData = data => {
RL_APP_DATA_STORAGE = data;
window.__rlah_set();
if (RL_APP_DATA_STORAGE) {
const css = RL_APP_DATA_STORAGE.IncludeCss,
theme = RL_APP_DATA_STORAGE.NewThemeLink,
description= RL_APP_DATA_STORAGE.LoadingDescriptionEsc || '',
oE = doc.getElementById('rl-loading'),
oElDesc = doc.getElementById('rl-loading-desc');
if (theme) {
(doc.getElementById('app-theme-link') || {}).href = theme;
}
css && writeCSS(css);
if (oElDesc && description) {
oElDesc.innerHTML = description;
}
if (oE && oE.style) {
oE.style.opacity = 0;
setTimeout(() => oE.style.opacity = 1, 300);
}
}
const appData = window.__rlah_data(), p = progressJs;
if (
p &&
appData &&
appData.TemplatesLink &&
appData.LangLink &&
appData.StaticLibJsLink &&
appData.StaticAppJsLink &&
appData.StaticEditorJsLink
) {
p.set(5);
const libs = () =>
loadScript(appData.StaticLibJsLink).then(() => {
doc.getElementById('rl-check').remove();
if (appData.IncludeBackground) {
const img = appData.IncludeBackground.replace('{{USER}}', getHash() || '0');
if (img) {
doc.documentElement.classList.add('UserBackground');
doc.body.style.backgroundImage = "url("+img+")";
}
}
});
libs()
.then(() => {
p.set(20);
return Promise.all([loadScript(appData.TemplatesLink), loadScript(appData.LangLink)]);
})
.then(() => {
p.set(30);
return loadScript(appData.StaticAppJsLink);
})
.then(() => {
p.set(50);
return appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve();
})
.then(() => {
p.set(70);
runMainBoot(false);
})
.catch((e) => {
runMainBoot(true);
throw e;
})
.then(() => loadScript(appData.StaticEditorJsLink))
.then(() => {
if (window.CKEDITOR && window.__initEditor) {
window.__initEditor();
window.__initEditor = null;
}
});
} else {
runMainBoot(true);
}
};
/**
* @returns {void}
*/
window.__runBoot = () => {
const app = doc.getElementById('rl-app');
if (!navigator || !navigator.cookieEnabled) {
doc.location.replace('./?/NoCookie');
}
// require('Styles/@Boot.css');
writeCSS('#rl-content{display:none;}.internal-hiddden{display:none !important;}');
if (app) {
const layout = require('Html/Layout.html'),
meta = doc.getElementById('app-boot-data'),
options = meta ? JSON.parse(meta.getAttribute('content')) || {} : {};
app.innerHTML = ((layout && layout.default ? layout.default : layout) || '').replace(/[\r\n\t]+/g, '');
loadScript('./?/'
+ (options.admin ? 'Admin' : '')
+ 'AppData@'
+ (options.mobile ? 'mobile' : 'no-mobile')
+ (options.mobileDevice ? '-1' : '-0')
+ '/'
+ (getHash() || '0')
+ '/'
+ Math.random().toString().substr(2)
+ '/').then(() => {});
}
};

View file

@ -1,49 +0,0 @@
const STORAGE_KEY = '__rlA';
const TIME_KEY = '__rlT';
const storage = ()=>window.sessionStorage;
const timestamp = () => Math.round(Date.now() / 1000);
const setTimestamp = () => storage().setItem(TIME_KEY, timestamp());
/**
* @returns {string}
*/
export function getHash() {
return storage().getItem(STORAGE_KEY) || null;
}
/**
* @returns {void}
*/
export function setHash() {
const key = 'AuthAccountHash',
appData = window.__rlah_data();
storage().setItem(STORAGE_KEY, appData && appData[key] ? appData[key] : '');
setTimestamp();
}
/**
* @returns {void}
*/
export function clearHash() {
storage().setItem(STORAGE_KEY, '');
setTimestamp();
}
/**
* @returns {boolean}
*/
export function checkTimestamp() {
if (timestamp() > (parseInt(storage().getItem(TIME_KEY) || 0, 10) || 0) + 3600000) {
// 60m
clearHash();
return true;
}
return false;
}
// init section
setInterval(setTimestamp, 60000); // 1m

View file

@ -1,9 +1,6 @@
let SETTINGS = window.__rlah_data() || null;
let SETTINGS = RainLoop.data() || null;
SETTINGS = null != SETTINGS ? SETTINGS : {};
let APP_SETTINGS = SETTINGS.System || null;
APP_SETTINGS = null != APP_SETTINGS ? APP_SETTINGS : {};
/**
* @param {string} name
* @returns {*}
@ -25,6 +22,7 @@ export function settingsSet(name, value) {
* @returns {*}
*/
export function appSettingsGet(name) {
const APP_SETTINGS = SETTINGS.System || {};
return null == APP_SETTINGS[name] ? null : APP_SETTINGS[name];
}
@ -33,6 +31,6 @@ export function appSettingsGet(name) {
* @returns {boolean}
*/
export function capa(name) {
const values = settingsGet('Capa');
const values = SETTINGS.Capa;
return Array.isArray(values) && null != name && values.includes(name);
}

View file

@ -1,15 +1,108 @@
import { getHash, setHash, clearHash } from 'Storage/RainLoop';
(win => {
const
doc = win.document,
setPercentWidth = (percent) => {
setTimeout(() => progress.style.width = parseInt(Math.min(percent, 100)) + '%', 50);
app = doc.getElementById('rl-app'),
setPercentWidth = percent => setTimeout(() => progress.style.width = parseInt(Math.min(percent, 100)) + '%', 50),
Storage = type => {
let name = type+'Storage';
try {
win[name].setItem('storage', '');
win[name].getItem('storage');
win[name].removeItem('storage');
} catch (e) {
console.error(e);
const cookieName = encodeURIComponent(name+('session' === type ? win.name || (win.name = Date.now()) : ''));
// initialise if there's already data
let data = document.cookie.match('(^|;) ?'+cookieName+'=([^;]*)(;|$)');
data = data ? decodeURIComponent(data[2]) : null;
data = data ? JSON.parse(data) : {};
win[name] = {
getItem: key => data[key] === undefined ? null : data[key],
setItem: function (key, value) {
data[key] = ''+value; // forces the value to a string
document.cookie = cookieName+'='+encodeURIComponent(JSON.stringify(data))
+"; expires="+('local' === type ? (new Date(Date.now()+(365*24*60*60*1000))).toGMTString() : '')
+"; path=/; samesite=strict";
}
};
}
},
STORAGE_KEY = '__rlA',
TIME_KEY = '__rlT',
AUTH_KEY = 'AuthAccountHash',
storage = () => window.sessionStorage,
timestamp = () => Math.round(Date.now() / 1000),
setTimestamp = () => storage().setItem(TIME_KEY, timestamp()),
showError = () => {
const oR = doc.getElementById('rl-loading'),
oL = doc.getElementById('rl-loading-error');
if (oR) {
oR.style.display = 'none';
}
if (oL) {
oL.style.display = 'block';
}
p.end();
},
runMainBoot = withError => {
if (win.__APP_BOOT && !withError) {
win.__APP_BOOT(() => showError());
} else {
showError();
}
},
writeCSS = css => {
const style = doc.createElement('style');
style.type = 'text/css';
style.textContent = css;
doc.head.append(style);
},
loadScript = src => {
if (!src) {
throw new Error('src should not be empty.');
}
return new Promise((resolve, reject) => {
const script = doc.createElement('script');
script.onload = () => resolve();
script.onerror = () => reject(new Error(src));
script.src = src;
// script.type = 'text/javascript';
doc.head.append(script);
// doc.body.append(element);
});
},
p = win.progressJs = {
set: percent => setPercentWidth(percent),
end: () => {
if (container) {
progress.addEventListener('transitionend', () => {
if (container) {
container.hidden = true;
setTimeout(() => {container.remove();container=null;}, 200);
}
}, false);
setPercentWidth(100);
}
}
};
let container = doc.createElement('div'),
progress = container.appendChild(doc.createElement("div"));
progress = container.appendChild(doc.createElement("div")),
RL_APP_DATA_STORAGE = null;
container.className = 'progressjs-progress progressjs-theme-rainloop';
progress.className = "progressjs-inner";
@ -18,99 +111,53 @@ progress.appendChild(doc.createElement('div')).className = "progressjs-percent";
setPercentWidth(1);
doc.body.append(container);
win.progressJs = new class {
set(percent) {
setPercentWidth(percent);
return this;
}
Storage('local');
Storage('session');
end() {
if (progress) {
progress.addEventListener('transitionend', () => {
if (container) {
container.hidden = true;
setTimeout(() => {container.remove();container=null;}, 200);
}
}, false);
setPercentWidth(100);
win.RainLoop = {
hash: {
// getHash
get: () => storage().getItem(STORAGE_KEY) || null,
// setHash
set: () => {
storage().setItem(STORAGE_KEY, RL_APP_DATA_STORAGE && RL_APP_DATA_STORAGE[AUTH_KEY]
? RL_APP_DATA_STORAGE[AUTH_KEY] : '');
setTimestamp();
},
// clearHash
clear: () => {
storage().setItem(STORAGE_KEY, '');
setTimestamp();
},
// checkTimestamp
check: () => {
if (timestamp() > (parseInt(storage().getItem(TIME_KEY) || 0, 10) || 0) + 3600000) {
// 60m
RainLoop.hash.clear();
return true;
}
return false;
}
return this;
}
},
data: () => RL_APP_DATA_STORAGE
};
let RL_APP_DATA_STORAGE = null;
win.__rlah_set = () => setHash();
win.__rlah_clear = () => clearHash();
win.__rlah_data = () => RL_APP_DATA_STORAGE;
// init section
setInterval(setTimestamp, 60000); // 1m
/**
* @param {mixed} appData
* @returns {void}
*/
function showError() {
const oR = doc.getElementById('rl-loading'),
oL = doc.getElementById('rl-loading-error');
win.__initAppData = appData => {
RL_APP_DATA_STORAGE = appData;
if (oR) {
oR.style.display = 'none';
}
RainLoop.hash.set();
if (oL) {
oL.style.display = 'block';
}
if (win.progressJs) {
progressJs.set(100).end();
}
}
/**
* @param {boolean} withError
* @returns {void}
*/
function runMainBoot(withError) {
if (win.__APP_BOOT && !withError) {
win.__APP_BOOT(() => showError());
} else {
showError();
}
}
function writeCSS(css) {
const style = doc.createElement('style');
style.type = 'text/css';
style.textContent = css;
doc.head.append(style);
}
function loadScript(src) {
if (!src) {
throw new Error('src should not be empty.');
}
return new Promise((resolve, reject) => {
const script = doc.createElement('script');
script.onload = () => resolve();
script.onerror = () => reject(new Error(src));
script.src = src;
// script.type = 'text/javascript';
doc.head.append(script);
// doc.body.append(element);
});
}
/**
* @param {mixed} data
* @returns {void}
*/
win.__initAppData = data => {
RL_APP_DATA_STORAGE = data;
win.__rlah_set();
if (RL_APP_DATA_STORAGE) {
const css = RL_APP_DATA_STORAGE.IncludeCss,
theme = RL_APP_DATA_STORAGE.NewThemeLink,
description= RL_APP_DATA_STORAGE.LoadingDescriptionEsc || '',
if (appData) {
const css = appData.IncludeCss,
theme = appData.NewThemeLink,
description= appData.LoadingDescriptionEsc || '',
oE = doc.getElementById('rl-loading'),
oElDesc = doc.getElementById('rl-loading-desc');
@ -129,10 +176,7 @@ win.__initAppData = data => {
}
}
const appData = win.__rlah_data(), p = progressJs;
if (
p &&
appData &&
appData.TemplatesLink &&
appData.LangLink &&
@ -146,7 +190,7 @@ win.__initAppData = data => {
loadScript(appData.StaticLibJsLink).then(() => {
doc.getElementById('rl-check').remove();
if (appData.IncludeBackground) {
const img = appData.IncludeBackground.replace('{{USER}}', getHash() || '0');
const img = appData.IncludeBackground.replace('{{USER}}', RainLoop.hash.get() || '0');
if (img) {
doc.documentElement.classList.add('UserBackground');
doc.body.style.backgroundImage = "url("+img+")";
@ -187,8 +231,6 @@ win.__initAppData = data => {
}
};
const app = doc.getElementById('rl-app');
if (!navigator || !navigator.cookieEnabled) {
doc.location.replace('./?/NoCookie');
}
@ -230,7 +272,7 @@ if (app) {
+ (options.mobile ? 'mobile' : 'no-mobile')
+ (options.mobileDevice ? '-1' : '-0')
+ '/'
+ (getHash() || '0')
+ (RainLoop.hash.get() || '0')
+ '/'
+ Math.random().toString().substr(2)
+ '/').then(() => {});

View file

@ -30,33 +30,4 @@ w.ResizeObserver || (w.ResizeObserver = class {
}
});
const Storage = type => {
let name = type+'Storage';
try {
w[name].setItem('storage', '');
w[name].getItem('storage');
w[name].removeItem('storage');
} catch (e) {
console.error(e);
const cookieName = encodeURIComponent(name+('session' === type ? w.name || (w.name = Date.now()) : ''));
// initialise if there's already data
let data = document.cookie.match('(^|;) ?'+cookieName+'=([^;]*)(;|$)');
data = data ? decodeURIComponent(data[2]) : null;
data = data ? JSON.parse(data) : {};
w[name] = {
getItem: key => data[key] === undefined ? null : data[key],
setItem: function (key, value) {
data[key] = ''+value; // forces the value to a string
document.cookie = cookieName+'='+encodeURIComponent(JSON.stringify(data))
+"; expires="+('local' === type ? (new Date(Date.now()+(365*24*60*60*1000))).toGMTString() : '')
+"; path=/; samesite=strict";
}
};
}
};
Storage('local');
Storage('session');
})(window);