|
|
@ -23,6 +23,8 @@ class VenueService extends SiteService {
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: true });
|
|
|
|
res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: true });
|
|
|
|
|
|
|
|
res.locals.shingChannelStatus = await this.getChannelStatus(res.locals.site.shingChannelSlug, { allowCache: true });
|
|
|
|
|
|
|
|
this.log.debug('channel status', { status: res.locals.shingChannelStatus });
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to populate Shing.tv channel feed', { error });
|
|
|
|
this.log.error('failed to populate Shing.tv channel feed', { error });
|
|
|
@ -34,29 +36,50 @@ class VenueService extends SiteService {
|
|
|
|
async getChannelFeed (channelSlug, options) {
|
|
|
|
async getChannelFeed (channelSlug, options) {
|
|
|
|
const { cache: cacheService } = this.dtp.services;
|
|
|
|
const { cache: cacheService } = this.dtp.services;
|
|
|
|
const cacheKey = `venue:ch:${channelSlug}`;
|
|
|
|
const cacheKey = `venue:ch:${channelSlug}`;
|
|
|
|
|
|
|
|
options = Object.assign({ allowCache: true }, options);
|
|
|
|
options = Object.assign({
|
|
|
|
|
|
|
|
allowCache: true,
|
|
|
|
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let json;
|
|
|
|
let json;
|
|
|
|
if (options.allowCache) {
|
|
|
|
if (options.allowCache) {
|
|
|
|
json = await cacheService.getObject(cacheKey);
|
|
|
|
json = await cacheService.getObject(cacheKey);
|
|
|
|
if (json) {
|
|
|
|
if (json) { return json; }
|
|
|
|
return json;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.log.info('fetching Shing channel feed', { channelSlug });
|
|
|
|
const response = await fetch(`https://shing.tv/channel/${channelSlug}/feed/json`);
|
|
|
|
const response = await fetch(`https://shing.tv/channel/${channelSlug}/feed/json`);
|
|
|
|
if (!response.ok) {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new SiteError(500, 'Failed to fetch Shing channel feed');
|
|
|
|
throw new SiteError(500, 'Failed to fetch Shing channel feed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
json = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json = await response.json();
|
|
|
|
await cacheService.setObjectEx(cacheKey, CACHE_DURATION, json);
|
|
|
|
await cacheService.setObjectEx(cacheKey, CACHE_DURATION, json);
|
|
|
|
|
|
|
|
|
|
|
|
return json;
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getChannelStatus (channelSlug, options) {
|
|
|
|
|
|
|
|
const { cache: cacheService } = this.dtp.services;
|
|
|
|
|
|
|
|
const cacheKey = `venue:ch:${channelSlug}:status`;
|
|
|
|
|
|
|
|
options = Object.assign({ allowCache: true }, options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let json;
|
|
|
|
|
|
|
|
if (options.allowCache) {
|
|
|
|
|
|
|
|
json = await cacheService.getObject(cacheKey);
|
|
|
|
|
|
|
|
if (json) { return json; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.log.info('fetching Shing channel status', { channelSlug });
|
|
|
|
|
|
|
|
const response = await fetch(`https://shing.tv/channel/${channelSlug}/status`);
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
|
|
|
throw new SiteError(500, 'Failed to fetch Shing channel status');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { channel } = json;
|
|
|
|
|
|
|
|
await cacheService.setObjectEx(cacheKey, 10, channel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
module.exports = {
|
|
|
|