Get Data For When Manifests Were Last Reached From Cache

This commit is contained in:
Stripes
2023-04-08 13:14:56 +03:00
committed by GitHub
parent 5bd67f9183
commit 54cd09bcca
+17 -1
View File
@@ -2,6 +2,12 @@
const needle = require('needle')
const config = require('../config')
function isObject(obj) {
return typeof obj === 'object' &&
!Array.isArray(obj) &&
obj !== null
}
const getCached = () => {
return new Promise((resolve, reject) => {
const cached = { catalog: [] }
@@ -21,7 +27,17 @@ const getCached = () => {
} else {
console.log('warning: could not load old addon catalog')
}
resolve(cached)
needle.get(`https://${config['netlify-domain']}/lastReached.json`, config.needle, (err, resp, body) => {
if (body && isObject(body) && Object.keys(body).length) {
console.log('loaded last reached data')
cached.lastReached = body
} else {
cached.lastReached = {}
console.log('warning: could not last reached data')
}
resolve(cached)
})
})
})
})