Velopark: first decent, working version

This commit is contained in:
Pieter Vander Vennet 2024-04-05 17:49:31 +02:00
parent 890816d2dd
commit 5b6cd1d2ae
18 changed files with 7054 additions and 21769 deletions

View file

@ -15,8 +15,12 @@ class ServerLdScrape extends Script {
{
mustMatch: "extractgraph",
mimetype: "application/ld+json",
addHeaders: {
"Cache-control":"max-age=3600, public"
},
async handle(content, searchParams: URLSearchParams) {
const url = searchParams.get("url")
console.log("URL", url)
if (cache[url] !== undefined) {
const { date, contents } = cache[url]
console.log(">>>", date, contents)
@ -37,6 +41,15 @@ class ServerLdScrape extends Script {
return "{\"#\":\"timout reached\"}"
}
} while (dloaded["redirect"])
if(dloaded["content"].startsWith("{")){
// This is probably a json
const snippet = JSON.parse(dloaded["content"])
console.log("Snippet is", snippet)
cache[url] = { contents: snippet, date: new Date() }
return JSON.stringify(snippet)
}
const parsed = parse(dloaded["content"])
const scripts = Array.from(parsed.getElementsByTagName("script"))
for (const script of scripts) {