From 65e9c5c8701a1e5e60b59c5e3d8a92d210c73013 Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Mon, 7 Dec 2020 17:07:36 +0100 Subject: [PATCH] Added @luxon for date validation --- app/scripts/scraper.js | 5 +++-- package-lock.json | 7 ++++++- package.json | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/scripts/scraper.js b/app/scripts/scraper.js index b35fef3..35481dc 100644 --- a/app/scripts/scraper.js +++ b/app/scripts/scraper.js @@ -2,6 +2,7 @@ // Public modules from npm const cheerio = require("cheerio"); +const {DateTime} = require("luxon"); // Modules from file const { fetchHTML, getUrlRedirect } = require("./network-helper.js"); @@ -256,11 +257,11 @@ function parseMainPostText(text) { } // Last update of the main post - if (data.UPDATED) { + if (data.UPDATED && DateTime.fromISO(data.UPDATED).isValid) { parsedDict["LastUpdate"] = new Date(data.UPDATED); delete data.UPDATED; } - else if (data.THREAD_UPDATED) { + else if (data.THREAD_UPDATED && DateTime.fromISO(data.THREAD_UPDATED).isValid) { parsedDict["LastUpdate"] = new Date(data.THREAD_UPDATED); delete data.THREAD_UPDATED; } diff --git a/package-lock.json b/package-lock.json index 84dea4e..2f44242 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "f95api", - "version": "1.7.0", + "version": "1.9.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1643,6 +1643,11 @@ "streamroller": "^2.2.4" } }, + "luxon": { + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-1.25.0.tgz", + "integrity": "sha512-hEgLurSH8kQRjY6i4YLey+mcKVAWXbDNlZRmM6AgWDJ1cY3atl8Ztf5wEY7VBReFbmGnwQPz7KYJblL8B2k0jQ==" + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", diff --git a/package.json b/package.json index ecaae42..f3ef362 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "ky": "^0.25.0", "ky-universal": "^0.8.2", "log4js": "^6.3.0", + "luxon": "^1.25.0", "tough-cookie": "^4.0.0" }, "devDependencies": {