Skip to content

Commit

Permalink
feat(web): disabled caching for developers
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Feb 19, 2022
1 parent 24f9d7e commit 9593aeb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/components/webServer/ctxUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ const chalk = require('chalk');
const helpers = require('../../extras/helpers');
const { dir, log, logOk, logWarn, logError } = require('../../extras/console')(modulename);

/**
* Preload essential templates to prevent multiple file reads
*/
let _templateCache = {}

//Helper functions
const now = () => { return Math.round(Date.now() / 1000); };
Expand Down Expand Up @@ -39,6 +35,7 @@ const getJavascriptConsts = (allConsts = []) => {
};

//Consts
const templateCache = new Map();
const WEBPIPE_PATH = 'https://monitor/WebPipe/';
const RESOURCE_PATH = 'nui://monitor/web/public/';
const THEME_DARK = 'theme--dark';
Expand All @@ -65,10 +62,11 @@ function getEjsOptions(filePath) {
* @returns {Promise<void>}
*/
async function loadWebTemplate(name) {
if (!_templateCache[name]) {
if (GlobalData.isDeveloperMode || !templateCache.has(name)) {
try {
const rawTemplate = await fs.readFile(getWebViewPath(name), 'utf-8');
_templateCache[name] = ejs.compile(rawTemplate, getEjsOptions(name + '.html'));
const compiled = ejs.compile(rawTemplate, getEjsOptions(name + '.html'));
templateCache.set(name, compiled);
} catch (e) {
if (e.code == 'ENOENT') {
e = new Error(`The '${name}' template was not found:\n` +
Expand All @@ -78,7 +76,7 @@ async function loadWebTemplate(name) {
}
}

return _templateCache[name];
return templateCache.get(name);
}


Expand All @@ -96,7 +94,7 @@ async function renderMasterView(view, reqSess, data, txVars) {
data.profilePicture = (reqSess && reqSess.auth && reqSess.auth.picture) ? reqSess.auth.picture : DEFAULT_AVATAR;
data.isTempPassword = (reqSess && reqSess.auth && reqSess.auth.isTempPassword);
data.isLinux = (GlobalData.osType == 'linux');
data.showAdvanced = (GlobalData.isAdvancedUser || GlobalData.verbose);
data.showAdvanced = (GlobalData.isDeveloperMode || GlobalData.verbose);
data.dynamicAd = txVars.isWebInterface && globals.dynamicAds.pick('main');

let out;
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (process.env.APP_ENV !== 'webpack' && txAdmin1337Convar !== 'IKnowWhatImDoing
logError('Looks like you don\'t know what you are doing.');
logDie('Please use the compiled release from GitHub or the version that comes with the latest FXServer.');
}
const isAdvancedUser = (process.env.APP_ENV !== 'webpack' && txAdmin1337Convar == 'IKnowWhatImDoing');
const isDeveloperMode = (process.env.APP_ENV !== 'webpack' && txAdmin1337Convar == 'IKnowWhatImDoing');

//Get OSType
const osTypeVar = os.type();
Expand Down Expand Up @@ -173,7 +173,7 @@ if (fs.existsSync(zapCfgFile)) {

loopbackInterfaces.push(forceInterface);

if (!isAdvancedUser) fs.unlinkSync(zapCfgFile);
if (!isDeveloperMode) fs.unlinkSync(zapCfgFile);
} catch (error) {
logDie(`Failed to load with ZAP-Hosting configuration error: ${error.message}`);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ if (!serverProfile.length) {
const noLookAlikesAlphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
GlobalData = {
//Env
isAdvancedUser,
isDeveloperMode,
osType,
resourceName,
fxServerVersion,
Expand Down

0 comments on commit 9593aeb

Please sign in to comment.