Fixes related to offline startup.
Fixed incorrect function name for local distro index loading. Fixed mojang tooltip not showing statuses when offline. Added timeout of 2500ms to news loading, remote distro index retrieval, and mojang status loading. Updates async to fix lodash vulnerability.
This commit is contained in:
@@ -149,6 +149,7 @@ const refreshMojangStatuses = async function(){
|
||||
try {
|
||||
const statuses = await Mojang.status()
|
||||
greenCount = 0
|
||||
greyCount = 0
|
||||
|
||||
for(let i=0; i<statuses.length; i++){
|
||||
const service = statuses[i]
|
||||
@@ -167,17 +168,23 @@ const refreshMojangStatuses = async function(){
|
||||
|
||||
if(service.status === 'yellow' && status !== 'red'){
|
||||
status = 'yellow'
|
||||
continue
|
||||
} else if(service.status === 'red'){
|
||||
status = 'red'
|
||||
break
|
||||
} else {
|
||||
if(service.status === 'grey'){
|
||||
++greyCount
|
||||
}
|
||||
++greenCount
|
||||
}
|
||||
|
||||
++greenCount
|
||||
}
|
||||
|
||||
if(greenCount == statuses.length){
|
||||
status = 'green'
|
||||
if(greenCount === statuses.length){
|
||||
if(greyCount === statuses.length){
|
||||
status = 'grey'
|
||||
} else {
|
||||
status = 'green'
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
@@ -915,51 +922,58 @@ function loadNews(){
|
||||
const distroData = AssetGuard.getDistributionData()
|
||||
const newsFeed = distroData['news_feed']
|
||||
const newsHost = new URL(newsFeed).origin + '/'
|
||||
$.get(newsFeed, (data) => {
|
||||
const items = $(data).find('item')
|
||||
const articles = []
|
||||
$.ajax(
|
||||
{
|
||||
url: newsFeed,
|
||||
success: (data) => {
|
||||
const items = $(data).find('item')
|
||||
const articles = []
|
||||
|
||||
for(let i=0; i<items.length; i++){
|
||||
// JQuery Element
|
||||
const el = $(items[i])
|
||||
for(let i=0; i<items.length; i++){
|
||||
// JQuery Element
|
||||
const el = $(items[i])
|
||||
|
||||
// Resolve date.
|
||||
const date = new Date(el.find('pubDate').text()).toLocaleDateString('en-US', {month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric'})
|
||||
// Resolve date.
|
||||
const date = new Date(el.find('pubDate').text()).toLocaleDateString('en-US', {month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric'})
|
||||
|
||||
// Resolve comments.
|
||||
let comments = el.find('slash\\:comments').text() || '0'
|
||||
comments = comments + ' Comment' + (comments === '1' ? '' : 's')
|
||||
// Resolve comments.
|
||||
let comments = el.find('slash\\:comments').text() || '0'
|
||||
comments = comments + ' Comment' + (comments === '1' ? '' : 's')
|
||||
|
||||
// Fix relative links in content.
|
||||
let content = el.find('content\\:encoded').text()
|
||||
let regex = /src="(?!http:\/\/|https:\/\/)(.+)"/g
|
||||
let matches
|
||||
while(matches = regex.exec(content)){
|
||||
content = content.replace(matches[1], newsHost + matches[1])
|
||||
}
|
||||
|
||||
let link = el.find('link').text()
|
||||
let title = el.find('title').text()
|
||||
let author = el.find('dc\\:creator').text()
|
||||
|
||||
// Generate article.
|
||||
articles.push(
|
||||
{
|
||||
link,
|
||||
title,
|
||||
date,
|
||||
author,
|
||||
content,
|
||||
comments,
|
||||
commentsLink: link + '#comments'
|
||||
// Fix relative links in content.
|
||||
let content = el.find('content\\:encoded').text()
|
||||
let regex = /src="(?!http:\/\/|https:\/\/)(.+)"/g
|
||||
let matches
|
||||
while(matches = regex.exec(content)){
|
||||
content = content.replace(matches[1], newsHost + matches[1])
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve({
|
||||
articles
|
||||
})
|
||||
|
||||
let link = el.find('link').text()
|
||||
let title = el.find('title').text()
|
||||
let author = el.find('dc\\:creator').text()
|
||||
|
||||
// Generate article.
|
||||
articles.push(
|
||||
{
|
||||
link,
|
||||
title,
|
||||
date,
|
||||
author,
|
||||
content,
|
||||
comments,
|
||||
commentsLink: link + '#comments'
|
||||
}
|
||||
)
|
||||
}
|
||||
resolve({
|
||||
articles
|
||||
})
|
||||
},
|
||||
timeout: 2500
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
resolve({
|
||||
articles: null
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user