1
0
mirror of https://git.sr.ht/~cadence/bibliogram synced 2024-11-22 16:17:29 +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
while (inTable && parser.hasRemaining()) {
console.log(parser.remaining())
while (parser.hasRemaining()) {
const line = parser.get({split: "\n"})
if (line.startsWith("|")) {
/** [empty, official, address, country, rss, cloudflare] */
/** [empty, address, country, rss, privacy policy, cloudflare] */
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({
address: parts[2].trim(),
country: parts[3].match(/[A-Z]{2,}|$/)[0] || null,
official: parts[1].trim() === ":white_check_mark:",
rss: parts[4].trim() === ":white_check_mark:",
cloudflare: parts[5].trim() === ":crying_cat_face:"
address,
country: parts[2].match(/[A-Z]{2,}|$/)[0] || null,
official: address === "https://bibliogram.art", // yeah we're just gonna hard code this
rss_enabled: parts[3].trim() === ":white_check_mark:",
has_privacy_policy: parts[4].trim() === ":white_check_mark:",
using_cloudflare: parts[5].trim() === ":crying_cat_face:"
})
}
} else {
@ -44,13 +47,13 @@ module.exports = [
}
return instances
})()
if (Array.isArray(result)) {
if (Array.isArray(result) && result.length) {
return {
statusCode: 200,
contentType: "application/json",
content: {
status: "ok",
version: "1.0",
version: "2.0",
generatedAt: Date.now(),
data: result
}