From 523feb329b61d67df0b3109f9c6b64c6d3ea6867 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Tue, 14 Nov 2023 17:16:46 +0800 Subject: [PATCH] Code optimization: change non change var to const from let --- src/main/webui/src/app/TimeUtils.js | 18 +++++----- .../webui/src/app/components/CompUtils.js | 36 +++++++++---------- .../src/app/components/content/Hints.jsx | 4 +-- .../src/app/components/content/RemoteList.jsx | 6 ++-- .../src/app/components/content/RemoteView.jsx | 8 ++--- .../src/app/components/nav/NavFooter.jsx | 2 +- .../src/content-browse/DirectoryListing.jsx | 16 ++++----- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/main/webui/src/app/TimeUtils.js b/src/main/webui/src/app/TimeUtils.js index ad38f3d..201014e 100644 --- a/src/main/webui/src/app/TimeUtils.js +++ b/src/main/webui/src/app/TimeUtils.js @@ -28,13 +28,13 @@ export const TimeUtils = { return 'never'; } - let hours = Math.floor(secs / (60 * 60)); + const hours = Math.floor(secs / (60 * 60)); - let mdiv = secs % (60 * 60); - let minutes = Math.floor(mdiv / 60); + const mdiv = secs % (60 * 60); + const minutes = Math.floor(mdiv / 60); - let sdiv = mdiv % 60; - let seconds = Math.ceil(sdiv); + const sdiv = mdiv % 60; + const seconds = Math.ceil(sdiv); let out = ''; if (hours > 0){ @@ -66,7 +66,7 @@ export const TimeUtils = { return 'never'; } - let date = new Date(); + const date = new Date(); date.setTime(milliseconds); return date.toLocaleString(); }, @@ -78,9 +78,9 @@ export const TimeUtils = { if (secs < 1){ return 'never'; } - let nextDate = new Date(secs); - let toDay = new Date(); - let total = nextDate.getTime() - toDay.getTime(); + const nextDate = new Date(secs); + const toDay = new Date(); + const total = nextDate.getTime() - toDay.getTime(); return TimeUtils.secondsToDuration(total / 1000); } }; diff --git a/src/main/webui/src/app/components/CompUtils.js b/src/main/webui/src/app/components/CompUtils.js index c07f654..d6de168 100644 --- a/src/main/webui/src/app/components/CompUtils.js +++ b/src/main/webui/src/app/components/CompUtils.js @@ -16,7 +16,7 @@ export const Utils = { remoteOptions: store => { - let options = []; + const options = []; if (store.allow_snapshots){ options.push({icon: 'S', title: 'Snapshots allowed'}); @@ -28,7 +28,7 @@ export const Utils = { return options; }, hostedOptions: store => { - let options = []; + const options = []; if (store.allow_snapshots){ options.push({icon: 'S', title: 'Snapshots allowed'}); @@ -45,23 +45,23 @@ export const Utils = { return options; }, detailHref: key => { - let parts = key.split(':'); + const parts = key.split(':'); return `/${parts[1]}/${parts[0]}/view/${parts[2]}`; }, typeFromKey: key=>{ - let parts = key.split(':'); + const parts = key.split(':'); return parts[1]; }, packageTypeFromKey: key => { - let parts = key.split(':'); + const parts = key.split(':'); return parts[0]; }, nameFromKey: key => { - let parts = key.split(':'); + const parts = key.split(':'); return parts[parts.length-1]; }, storeHref: key => { - let parts = key.split(':'); + const parts = key.split(':'); let hostAndPort = window.location.hostname; if (window.location.port !== '' && window.location.port !== 80 && window.location.port !== 443){ @@ -69,25 +69,25 @@ export const Utils = { hostAndPort += window.location.port; } // - // let basepath = window.location.pathname; + // const basepath = window.location.pathname; // basepath = basepath.replace('/app', ''); // basepath = basepath.replace(/index.html.*/, ''); - let proto = window.location.protocol; + const proto = window.location.protocol; // TODO: In-UI browser that allows simple searching return `${proto}//${hostAndPort}/api/content/${parts[0]}/${parts[1]}/${parts[2]}`; }, setDisableMap: listing => { - let disabledMap = {}; + const disabledMap = {}; - let items = listing.items; + const items = listing.items; if (items) { for(let i = 0; i { if(disabledMap && disabledMap.size > 0){ - let result = key in disabledMap; + const result = key in disabledMap; return result; } return false; @@ -119,13 +119,13 @@ export const Utils = { return constituents; }, searchByKeyForNewStores: (searchString, rawStoresList)=>{ - let newListing=[]; + const newListing=[]; rawStoresList.forEach(item=>item.key.toLowerCase().includes(searchString.toLowerCase()) && newListing.push(item)); return newListing; }, isEmptyObj: obj => Object.keys(obj).length === 0 && obj.constructor === Object, cloneObj: src => { - let target = {}; + const target = {}; for (const prop in src) { if (prop in src) { target[prop] = src[prop]; @@ -134,7 +134,7 @@ export const Utils = { return target; }, logMessage: (message, ...params) => { - let allParams = [message]; + const allParams = [message]; params.forEach(p => allParams.push(p)); Reflect.apply(console.log, undefined, allParams); } diff --git a/src/main/webui/src/app/components/content/Hints.jsx b/src/main/webui/src/app/components/content/Hints.jsx index f479fef..aef8476 100644 --- a/src/main/webui/src/app/components/content/Hints.jsx +++ b/src/main/webui/src/app/components/content/Hints.jsx @@ -61,7 +61,7 @@ DisableTimeoutHint.propTypes = { }; const PrefetchHint = ({children}) => { - let suggestion = children ? children: + const suggestion = children ? children: 'Integer to indicate the pre-fetching priority of the remote, higher means more eager to do the ' + 'pre-fetching of the content in the repo, 0 or below means disable the pre-fecthing.'; @@ -73,7 +73,7 @@ PrefetchHint.propTypes = { }; const DurationHint = ({children}) => { - let suggestion = children ? children : "24h 36m 00s"; + const suggestion = children ? children : "24h 36m 00s"; return ({`eg. ${suggestion}`}); }; diff --git a/src/main/webui/src/app/components/content/RemoteList.jsx b/src/main/webui/src/app/components/content/RemoteList.jsx index 5f14b1e..f1bb9e8 100644 --- a/src/main/webui/src/app/components/content/RemoteList.jsx +++ b/src/main/webui/src/app/components/content/RemoteList.jsx @@ -82,9 +82,9 @@ export default function RemoteList() { init(state, setState); // Utils.logMessage(state); - let listing = state.listing; - let disMap = state.disabledMap; - let orderBys = [ + const listing = state.listing; + const disMap = state.disabledMap; + const orderBys = [ {value: 'key', text: 'Name'}, {value: 'url', text: 'Remote URL'} ]; diff --git a/src/main/webui/src/app/components/content/RemoteView.jsx b/src/main/webui/src/app/components/content/RemoteView.jsx index a39272b..68f6139 100644 --- a/src/main/webui/src/app/components/content/RemoteView.jsx +++ b/src/main/webui/src/app/components/content/RemoteView.jsx @@ -31,8 +31,8 @@ const init = (pkgType, storeName, setState) => { const fetchStore = async () => { const response = await jsonRest.get(storeUrl); if (response.ok){ - let raw = await response.json(); - let store = Utils.cloneObj(raw); + const raw = await response.json(); + const store = Utils.cloneObj(raw); store.disabled = raw.disabled === undefined ? false : raw.disabled; store.useX509 = raw.server_certificate_pem || raw.key_certificate_pem; store.useProxy = raw.proxy_host && true; @@ -42,7 +42,7 @@ const init = (pkgType, storeName, setState) => { // get Store disablement data const timeoutUrl = `/api/admin/schedule/store/${store.packageType}/${store.type}/${store.name}/disable-timeout`; const timeoutResponse = await jsonRest.get(timeoutUrl); - let newStore = Utils.cloneObj(store); + const newStore = Utils.cloneObj(store); if(timeoutResponse.ok){ const timeoutData = await timeoutResponse.json(); newStore.disableExpiration = timeoutData.expiration; @@ -87,7 +87,7 @@ export default function RemoteView() { }); const {packageType, name} = useParams(); init(packageType, name, setState); - let store = state.store; + const store = state.store; if(!Utils.isEmptyObj(store)) { return (
diff --git a/src/main/webui/src/app/components/nav/NavFooter.jsx b/src/main/webui/src/app/components/nav/NavFooter.jsx index 381c976..672b6a5 100644 --- a/src/main/webui/src/app/components/nav/NavFooter.jsx +++ b/src/main/webui/src/app/components/nav/NavFooter.jsx @@ -18,7 +18,7 @@ import React from 'react'; export default function NavFooter() { // TODO: stats will be render based on the backend addons response, this is a mock; - let stats = { + const stats = { version: "1.6.0", commitId: "f472176", builder: "ligangty", diff --git a/src/main/webui/src/content-browse/DirectoryListing.jsx b/src/main/webui/src/content-browse/DirectoryListing.jsx index 7aa03df..0114b5e 100644 --- a/src/main/webui/src/content-browse/DirectoryListing.jsx +++ b/src/main/webui/src/content-browse/DirectoryListing.jsx @@ -35,17 +35,17 @@ const getFullHost = () => { }; const URLList = props => { - let elems = []; + const elems = []; if(props.parentUrl){ - let parentUrl = props.parentUrl.replace("/api/browse", "/browse"); + const parentUrl = props.parentUrl.replace("/api/browse", "/browse"); elems.push(
  • ..
  • ); } if(props.urls){ props.urls.forEach((urlResult, index)=>{ - let source = `sources:\n${urlResult.sources.join("\n")}`; - let url = replaceUrl(urlResult.listingUrl); - let paths = urlResult.path.split('/'); - let path = urlResult.path.endsWith("/")? paths[paths.length-2] + "/" : paths[paths.length-1]; + const source = `sources:\n${urlResult.sources.join("\n")}`; + const url = replaceUrl(urlResult.listingUrl); + const paths = urlResult.path.split('/'); + const path = urlResult.path.endsWith("/")? paths[paths.length-2] + "/" : paths[paths.length-1]; elems.push(
  • {path}
  • ); }); } @@ -63,7 +63,7 @@ URLList.propTypes = { const Footer = props => { const elems = props.sources && props.sources.map((src, index)=>{ - let url = src.replace(/http(s{0,1}):\/\/.*?\//u, getFullHost()+"/"); + const url = src.replace(/http(s{0,1}):\/\/.*?\//u, getFullHost()+"/"); return
  • {url}
  • ; }); return( @@ -81,7 +81,7 @@ Footer.propTypes = { }; const getStoreKey = storeKey => { - let storeElems = storeKey.split(":"); + const storeElems = storeKey.split(":"); return { "packageType": storeElems[0], "type": storeElems[1],