From e897c3b4e82f10b246188123dc0681270f450bd3 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sat, 14 Jan 2023 20:20:43 +0100 Subject: [PATCH] Add null protection --- package.json | 2 +- src/OsmUserInfo.ts | 2 +- src/Postbuilder.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 28d1ea3..a7930ad 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "scripts": { "build": "tsc", "lint": "tslint --project ./tsconfig.json -t stylish", - "start": "nvm use && ts-node src/index.ts", + "start": "ts-node src/index.ts", "test": "doctest-ts-improved src/ && mocha --require ts-node/register \"./**/*.doctest.ts\" && (find . -type f -name \"*.doctest.ts\" | xargs rm)" }, "dependencies": { diff --git a/src/OsmUserInfo.ts b/src/OsmUserInfo.ts index 59275ea..dd6af49 100644 --- a/src/OsmUserInfo.ts +++ b/src/OsmUserInfo.ts @@ -45,7 +45,7 @@ export default class OsmUserInfo { const div = document.createElement("div") div.innerHTML = userdata.description const links = Array.from(div.getElementsByTagName("a")) - const meLinks = links.filter(link => link.getAttribute("rel").split(" ").indexOf("me") >= 0) + const meLinks = links.filter(link => link.getAttribute("rel")?.split(" ")?.indexOf("me") >= 0) return meLinks.map(link => link.href.toString()) //*/ } diff --git a/src/Postbuilder.ts b/src/Postbuilder.ts index 518afac..5fad541 100644 --- a/src/Postbuilder.ts +++ b/src/Postbuilder.ts @@ -174,7 +174,6 @@ export class Postbuilder { const props = image.changeset.properties const uid = ""+props.uid - if (result.indexOf(image) >= 0) { continue } @@ -200,6 +199,7 @@ export class Postbuilder { themeBonus[theme] = (themeBonus[theme] ?? 0) - 1 const uid = randomBestImage.changeset.properties.uid alreadyEncounteredUid.set(uid, (alreadyEncounteredUid.get(uid) ?? 0) + 1) + console.log("Selecting image",randomBestImage.image," by ", randomBestImage.changeset.properties.user+" with score "+bestImageScore) } return result