From c15f83f899ae4de54fe418c5fe55c58ec964347d Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 1 Jan 2021 17:30:47 +1300 Subject: [PATCH] Normalise display data on search across APIs --- api/search.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/search.js b/api/search.js index f16d825..1c44155 100644 --- a/api/search.js +++ b/api/search.js @@ -1,6 +1,7 @@ const fetch = require("node-fetch") const {render} = require("pinski/plugins") const {getUser} = require("../utils/getuser") +const converters = require("../utils/converters") module.exports = [ { @@ -10,6 +11,20 @@ module.exports = [ const fetchURL = new URL(`${instanceOrigin}/api/v1/search`) fetchURL.searchParams.set("q", query) const results = await fetch(fetchURL.toString()).then(res => res.json()) + + for (const video of results) { + if (!video.second__lengthText && video.lengthSeconds > 0) { + video.second__lengthText = converters.lengthSecondsToLengthText(video.lengthSeconds) + } + if (!video.second__lengthText && video.lengthSeconds === 0) { + video.second__lengthText = "LIVE" + video.liveNow = true + } + if (video.publishedText === "0 seconds ago") { + video.publishedText = "Live now" + } + } + return render(200, "pug/search.pug", {query, results, instanceOrigin}) } }