fix: /houxu/lives/realtime fail when link.media == null (#1957)

This commit is contained in:
ReZonafine 2019-04-21 17:45:41 +08:00 committed by DIYgod
parent d3704ce64c
commit 1fa670f132
1 changed files with 7 additions and 4 deletions

View File

@ -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 + '<br />' + 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 + '<br />' + 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(),
}));