1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-23 00:27:30 +00:00

Fix instances wiki parser for new format

The endpoint version is now 2.0. Old versions of the parser will not
return value data.
This commit is contained in:
Cadence Ember 2020-05-09 03:18:02 +12:00
parent 6b3dc95926
commit be3324ffce
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412

View File

@ -24,18 +24,21 @@ module.exports = [
} }
} }
if (!parser.hasRemaining()) return null if (!parser.hasRemaining()) return null
while (inTable && parser.hasRemaining()) { console.log(parser.remaining())
while (parser.hasRemaining()) {
const line = parser.get({split: "\n"}) const line = parser.get({split: "\n"})
if (line.startsWith("|")) { if (line.startsWith("|")) {
/** [empty, official, address, country, rss, cloudflare] */ /** [empty, address, country, rss, privacy policy, cloudflare] */
const parts = line.split("|") const parts = line.split("|")
if (parts.length >= 4 && parts[2].includes("://")) { if (parts.length >= 6 && parts[1].includes("://")) {
const address = parts[1].trim().split(" ")[0]
instances.push({ instances.push({
address: parts[2].trim(), address,
country: parts[3].match(/[A-Z]{2,}|$/)[0] || null, country: parts[2].match(/[A-Z]{2,}|$/)[0] || null,
official: parts[1].trim() === ":white_check_mark:", official: address === "https://bibliogram.art", // yeah we're just gonna hard code this
rss: parts[4].trim() === ":white_check_mark:", rss_enabled: parts[3].trim() === ":white_check_mark:",
cloudflare: parts[5].trim() === ":crying_cat_face:" has_privacy_policy: parts[4].trim() === ":white_check_mark:",
using_cloudflare: parts[5].trim() === ":crying_cat_face:"
}) })
} }
} else { } else {
@ -44,13 +47,13 @@ module.exports = [
} }
return instances return instances
})() })()
if (Array.isArray(result)) { if (Array.isArray(result) && result.length) {
return { return {
statusCode: 200, statusCode: 200,
contentType: "application/json", contentType: "application/json",
content: { content: {
status: "ok", status: "ok",
version: "1.0", version: "2.0",
generatedAt: Date.now(), generatedAt: Date.now(),
data: result data: result
} }