Browse Source

add Gab TV channel data fetch and service

master
Rob Colbert 2 years ago
parent
commit
343f02a64d
  1. 2
      app/controllers/home.js
  2. 3
      app/models/article.js
  3. 48
      app/services/gab-tv.js
  4. 3
      app/views/index.pug
  5. 2
      package.json
  6. 4
      update-deps
  7. 52
      yarn.lock

2
app/controllers/home.js

@ -35,8 +35,10 @@ class HomeController extends SiteController {
}
async getHome (req, res, next) {
const { gabTV: gabTvService } = this.dtp.services;
try {
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.gabTvChannel = await gabTvService.getChannelEpisodes('mrjoeprich');
res.render('index');
} catch (error) {
return next(error);

3
app/models/article.js

@ -16,6 +16,9 @@ const ArticleSchema = new Schema({
title: { type: String, required: true },
summary: { type: String },
content: { type: String },
flags: {
isFeatured: { type: Boolean, default: false, index: true },
},
});
ArticleSchema.index({

48
app/services/gab-tv.js

@ -0,0 +1,48 @@
// gab-tv.js
// Copyright (C) 2021 Digital Telepresence, LLC
// License: Apache-2.0
'use strict';
const fetch = require('node-fetch'); // jshint ignore:line
const CACHE_DURATION = 1000 * 60 * 5;
const { SiteService } = require('../../lib/site-lib');
class GabTVService extends SiteService {
constructor (dtp) {
super(dtp, module.exports);
}
async getChannelEpisodes (channelSlug, options) {
const { cache: cacheService } = this.dtp.services;
const cacheKey = `gabtv:ch:${channelSlug}`;
options = Object.assign({
allowCache: true,
}, options);
let json;
if (options.allowCache) {
json = await cacheService.getObject(cacheKey);
if (json) {
return json;
}
}
const response = await fetch(`https://tv.gab.com/channel/${channelSlug}/feed/json`);
json = await response.json();
await cacheService.setObjectEx(cacheKey, CACHE_DURATION, json);
return json;
}
}
module.exports = {
slug: 'gab-tv',
name: 'gabTV',
create: (dtp) => { return new GabTVService(dtp); },
};

3
app/views/index.pug

@ -13,4 +13,5 @@ block content
section.uk-section.uk-section-secondary
.uk-container
.uk-text-lead.uk-text-center Welcome to the new online home of #{site.name}! We just getting started. Hang tight!
.uk-text-lead.uk-text-center Welcome to the new online home of #{site.name}! We just getting started. Hang tight!
pre= JSON.stringify(gabTvChannel, null, 2)

2
package.json

@ -49,7 +49,7 @@
"mongoose": "^6.0.14",
"morgan": "^1.10.0",
"multer": "^1.4.3",
"node-fetch": "^3.1.0",
"node-fetch": "2",
"numeral": "^2.0.6",
"otplib": "^12.0.1",
"passport": "^0.5.0",

4
update-deps

@ -37,7 +37,7 @@ yarn \
mongoose \
morgan \
multer \
node-fetch \
node-fetch@2 \
numeral \
otplib \
passport \
@ -73,4 +73,4 @@ yarn add -D \
terser-webpack-plugin \
webpack \
webpack-stream \
workbox-webpack-plugin
workbox-webpack-plugin

52
yarn.lock

@ -2579,11 +2579,6 @@ data-uri-to-buffer@1:
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-1.2.0.tgz#77163ea9c20d8641b4707e8f18abdf9a78f34835"
integrity sha512-vKQ9DTQPN1FLYiiEEOQ6IBGFqvjCa5rSK3cWMy/Nespm5d/x3dGFT9UBZnkLxCwua/IXBi2TYnwTEpsOvhC4UQ==
data-uri-to-buffer@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b"
integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==
data-urls@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-3.0.1.tgz#597fc2ae30f8bc4dbcf731fcd1b1954353afc6f8"
@ -3484,13 +3479,6 @@ feed@^4.2.2:
dependencies:
xml-js "^1.6.11"
fetch-blob@^3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.3.tgz#a7dca4855e39d3e3c5a1da62d4ee335c37d26012"
integrity sha512-ax1Y5I9w+9+JiM+wdHkhBoxew+zG4AJ2SvAD1v1szpddUIiPERVGBxrMcB2ZqW0Y3PP8bOWYv2zqQq1Jp2kqUQ==
dependencies:
web-streams-polyfill "^3.0.3"
file-uri-to-path@1, [email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
@ -3646,13 +3634,6 @@ form-data@^4.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"
formdata-polyfill@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"
[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
@ -5741,14 +5722,12 @@ node-addon-api@^4.2.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.2.0.tgz#117cbb5a959dff0992e1c586ae0393573e4d2a87"
integrity sha512-eazsqzwG2lskuzBqCGPi7Ac2UgOoMz8JVOXVhTvvPDYhthvNpefx8jWD8Np7Gv+2Sz0FlPWZk0nJV0z598Wn8Q==
node-fetch@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.1.0.tgz#714f4922dc270239487654eaeeab86b8206cb52e"
integrity sha512-QU0WbIfMUjd5+MUzQOYhenAazakV7Irh1SGkWCsRzBwvm4fAhzEUaHMJ6QLP7gWT6WO9/oH2zhKMMGMuIrDyKw==
node-fetch@2:
version "2.6.6"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89"
integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.2"
formdata-polyfill "^4.0.10"
whatwg-url "^5.0.0"
node-releases@^2.0.1:
version "2.0.1"
@ -8021,6 +8000,11 @@ tr46@^3.0.0:
dependencies:
punycode "^2.1.1"
tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
tslib@^2.0.1, tslib@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
@ -8416,10 +8400,10 @@ web-encoding@^1.1.5:
optionalDependencies:
"@zxing/text-encoding" "0.9.0"
web-streams-polyfill@^3.0.3:
version "3.2.0"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz#a6b74026b38e4885869fb5c589e90b95ccfc7965"
integrity sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==
webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
webidl-conversions@^4.0.2:
version "4.0.2"
@ -8516,6 +8500,14 @@ whatwg-url@^11.0.0:
tr46 "^3.0.0"
webidl-conversions "^7.0.0"
whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
whatwg-url@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.1.0.tgz#c2c492f1eca612988efd3d2266be1b9fc6170d06"

Loading…
Cancel
Save