From 1fa670f132da288545588c609198c765af183f25 Mon Sep 17 00:00:00 2001
From: ReZonafine <46563025+ReZonafine@users.noreply.github.com>
Date: Sun, 21 Apr 2019 17:45:41 +0800
Subject: [PATCH] fix: /houxu/lives/realtime fail when link.media == null
(#1957)
---
lib/routes/houxu/lives.js | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/routes/houxu/lives.js b/lib/routes/houxu/lives.js
index b802ea138..b9de0097e 100644
--- a/lib/routes/houxu/lives.js
+++ b/lib/routes/houxu/lives.js
@@ -1,13 +1,16 @@
const axios = require('../../utils/axios');
-const liveUrlById = (liveId) => `https://houxu.app/lives/${liveId}`;
+const getLiveUrlById = (liveId) => `https://houxu.app/lives/${liveId}`;
+
+const getLinkDesc = (link) => (link.media === null ? link.description : link.media.name + ':
' + link.description);
const realtimeHandler = async () => {
const res = await axios.get('https://houxu.app/api/1/lives/updated/');
+
const out = res.data.results.map((el) => ({
title: el.last.link.title,
- description: el.last.link.media.name + ':
' + el.last.link.description,
- link: liveUrlById(el.id),
+ description: getLinkDesc(el.last.link),
+ link: getLiveUrlById(el.id),
guid: 'realtime-' + el.id + '-' + el.last.id,
pubDate: new Date(el.last.create_at).toUTCString(),
}));
@@ -27,7 +30,7 @@ const newHandler = async () => {
.map((el) => ({
title: el.object.title,
description: el.object.summary,
- link: liveUrlById(el.id),
+ link: getLiveUrlById(el.id),
guid: 'new-' + el.id + '-' + el.object.id,
pubDate: new Date(el.object.create_at).toUTCString(),
}));