|
|
@ -4,6 +4,7 @@ |
|
|
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
const https = require('https'); |
|
|
|
const fetch = require('node-fetch'); // jshint ignore:line
|
|
|
|
|
|
|
|
const CACHE_DURATION = 60 * 5; |
|
|
@ -14,6 +15,14 @@ class VenueService extends SiteService { |
|
|
|
|
|
|
|
constructor (dtp) { |
|
|
|
super(dtp, module.exports); |
|
|
|
this.soapboxDomain = process.env.DTP_SOAPBOX_HOST || 'shing.tv'; |
|
|
|
} |
|
|
|
|
|
|
|
async start ( ) { |
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; |
|
|
|
this.httpsAgent = new https.Agent({ |
|
|
|
rejectUnauthorized: false, |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
channelMiddleware ( ) { |
|
|
@ -22,12 +31,12 @@ class VenueService extends SiteService { |
|
|
|
if (!res.locals.site || !res.locals.site.shingChannelSlug) { |
|
|
|
return next(); |
|
|
|
} |
|
|
|
res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: true }); |
|
|
|
res.locals.shingChannelStatus = await this.getChannelStatus(res.locals.site.shingChannelSlug, { allowCache: true }); |
|
|
|
res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: false }); |
|
|
|
res.locals.shingChannelStatus = await this.getChannelStatus(res.locals.site.shingChannelSlug, { allowCache: false }); |
|
|
|
this.log.debug('channel status', { status: res.locals.shingChannelStatus }); |
|
|
|
return next(); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to populate Shing.tv channel feed', { error }); |
|
|
|
this.log.error('failed to populate Soapbox channel feed', { error }); |
|
|
|
return next(); |
|
|
|
} |
|
|
|
}; |
|
|
@ -44,8 +53,11 @@ class VenueService extends SiteService { |
|
|
|
if (json) { return json; } |
|
|
|
} |
|
|
|
|
|
|
|
this.log.info('fetching Shing channel feed', { channelSlug }); |
|
|
|
const response = await fetch(`https://shing.tv/channel/${channelSlug}/feed/json`); |
|
|
|
const requestUrl = `https://${this.soapboxDomain}/channel/${channelSlug}/feed/json`; |
|
|
|
this.log.info('fetching Shing channel feed', { channelSlug, requestUrl }); |
|
|
|
const response = await fetch(requestUrl, { |
|
|
|
agent: this.httpsAgent, |
|
|
|
}); |
|
|
|
if (!response.ok) { |
|
|
|
throw new SiteError(500, 'Failed to fetch Shing channel feed'); |
|
|
|
} |
|
|
@ -67,8 +79,11 @@ class VenueService extends SiteService { |
|
|
|
if (json) { return json; } |
|
|
|
} |
|
|
|
|
|
|
|
this.log.info('fetching Shing channel status', { channelSlug }); |
|
|
|
const response = await fetch(`https://shing.tv/channel/${channelSlug}/status`); |
|
|
|
const requestUrl = `https://${this.soapboxDomain}/channel/${channelSlug}/status`; |
|
|
|
this.log.info('fetching Shing channel status', { channelSlug, requestUrl }); |
|
|
|
const response = await fetch(requestUrl, { |
|
|
|
agent: this.httpsAgent, |
|
|
|
}); |
|
|
|
if (!response.ok) { |
|
|
|
throw new SiteError(500, 'Failed to fetch Shing channel status'); |
|
|
|
} |
|
|
|