mirror of https://github.com/dirtbags/moth.git
Hacky update to fetchAll
This commit is contained in:
parent
5fbc4753de
commit
7e8dbb95b2
|
@ -103,6 +103,9 @@ function renderState(obj) {
|
||||||
}
|
}
|
||||||
if (Object.keys(obj.Puzzles).length > 0) {
|
if (Object.keys(obj.Puzzles).length > 0) {
|
||||||
renderPuzzles(obj.Puzzles)
|
renderPuzzles(obj.Puzzles)
|
||||||
|
if (obj.Config.Detachable) {
|
||||||
|
fetchAll(obj.Puzzles)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
renderNotices(obj.Messages)
|
renderNotices(obj.Messages)
|
||||||
}
|
}
|
||||||
|
@ -143,62 +146,27 @@ function showPuzzles() {
|
||||||
heartbeat()
|
heartbeat()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAll() {
|
async function fetchAll(puzzles) {
|
||||||
let teamId = sessionStorage.id
|
let teamId = sessionStorage.id
|
||||||
let headers = new Headers()
|
|
||||||
headers.append("pragma", "no-cache")
|
|
||||||
headers.append("cache-control", "no-cache")
|
|
||||||
requests = []
|
|
||||||
let url = new URL("current_manifest.json", window.location)
|
|
||||||
url.searchParams.set("id", teamId)
|
|
||||||
|
|
||||||
toast("Caching all currently-open content")
|
console.log("Caching all currently-open content")
|
||||||
requests.push( fetch(url, {headers: headers})
|
|
||||||
.then( resp => {
|
|
||||||
if (resp.ok) {
|
|
||||||
resp.json()
|
|
||||||
.then(contents => {
|
|
||||||
console.log("Processing manifest")
|
|
||||||
for (let resource of contents) {
|
|
||||||
if (resource == "puzzles.json") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fetch(resource)
|
|
||||||
.then(e => {
|
|
||||||
console.log("Fetched " + resource)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
let resp = await fetch("puzzles.json?id=" + teamId, {headers: headers})
|
for (let cat in puzzles) {
|
||||||
|
for (let points of puzzles[cat]) {
|
||||||
if (resp.ok) {
|
let resp = await fetch(cat + "/" + points + "/")
|
||||||
let categories = await resp.json()
|
if (! resp.ok) {
|
||||||
let cat_names = Object.keys(categories)
|
|
||||||
cat_names.sort()
|
|
||||||
for (let cat_name of cat_names) {
|
|
||||||
if (cat_name.startsWith("__")) {
|
|
||||||
// Skip metadata
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let puzzles = categories[cat_name]
|
let obj = await resp.json()
|
||||||
for (let puzzle of puzzles) {
|
for (let file of obj.files) {
|
||||||
let url = new URL("puzzle.html", window.location)
|
fetch(cat + "/" + points + "/" + file.name)
|
||||||
url.searchParams.set("cat", cat_name)
|
}
|
||||||
url.searchParams.set("points", puzzle[0])
|
for (let file of obj.scripts) {
|
||||||
url.searchParams.set("pid", puzzle[1])
|
fetch(cat + "/" + points + "/" + file.name)
|
||||||
requests.push(
|
|
||||||
fetch(url)
|
|
||||||
.then(e => {
|
|
||||||
console.log("Fetched " + url)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Promise.all(requests)
|
|
||||||
toast("Done caching content")
|
toast("Done caching content")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue