Add dinosaur wet metrics
This commit is contained in:
@@ -2,6 +2,9 @@ import { Controller, Get, Res } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { identity, prop } from 'ramda';
|
||||
import * as xml from 'xml';
|
||||
import { InjectMetric } from '@willsoto/nestjs-prometheus';
|
||||
import { Gauge } from 'prom-client';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
const episodeFiles: [number, string][] = [
|
||||
[27544345, '01-Into-the-Big-Wet.mp3'],
|
||||
@@ -60,6 +63,34 @@ const buildFeeds = (
|
||||
episodes: Episode[],
|
||||
pubDateFn: (index: number) => Date = () => startDate,
|
||||
) => {
|
||||
const episodeItems = episodes
|
||||
.filter((episode: Episode, index: number) => pubDateFn(index) <= new Date())
|
||||
.map(({ title, url, length, fakeReleaseDate }, index) => ({
|
||||
item: [
|
||||
{ title },
|
||||
{ guid: url },
|
||||
{ pubDate: pubDateFn(index).toUTCString() },
|
||||
{
|
||||
'itunes:image': {
|
||||
_attr: {
|
||||
href: dinosaurImage,
|
||||
},
|
||||
},
|
||||
},
|
||||
{ 'itunes:episode': index + 1 },
|
||||
{
|
||||
enclosure: [
|
||||
{
|
||||
_attr: {
|
||||
url,
|
||||
type: 'audio/mpeg',
|
||||
length,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}));
|
||||
const feedObject = {
|
||||
rss: [
|
||||
{
|
||||
@@ -100,48 +131,24 @@ const buildFeeds = (
|
||||
'A recreation of Dinosaur Wet as an RSS feed for listeners-with-licenses enjoyment.',
|
||||
},
|
||||
{ language: 'en-US' },
|
||||
...episodes
|
||||
.filter(
|
||||
(episode: Episode, index: number) =>
|
||||
pubDateFn(index) <= new Date(),
|
||||
)
|
||||
.map(({ title, url, length, fakeReleaseDate }, index) => ({
|
||||
item: [
|
||||
{ title },
|
||||
{ guid: url },
|
||||
{ pubDate: pubDateFn(index).toUTCString() },
|
||||
{
|
||||
'itunes:image': {
|
||||
_attr: {
|
||||
href: dinosaurImage,
|
||||
},
|
||||
},
|
||||
},
|
||||
{ 'itunes:episode': index + 1 },
|
||||
{
|
||||
enclosure: [
|
||||
{
|
||||
_attr: {
|
||||
url,
|
||||
type: 'audio/mpeg',
|
||||
length,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})),
|
||||
...episodeItems,
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const feed = '<?xml version="1.0" encoding="UTF-8"?>' + xml(feedObject);
|
||||
return feed;
|
||||
return { feed, episodeItems };
|
||||
};
|
||||
|
||||
@ApiTags('dinosaurwet')
|
||||
@Controller('dinosaurwet')
|
||||
export class DinosaurwetController {
|
||||
constructor(
|
||||
@InjectMetric('weekly_count') public weeklyCount: Gauge<string>,
|
||||
@InjectMetric('daily_count') public dailyCount: Gauge<string>,
|
||||
) {}
|
||||
|
||||
@Get('')
|
||||
getAllAtOnce(@Res() response: Response) {
|
||||
response.header('Content-Type', 'application/xml');
|
||||
@@ -158,7 +165,8 @@ export class DinosaurwetController {
|
||||
(index: number) =>
|
||||
new Date(new Date(startDate).setDate(startDate.getDate() + index)),
|
||||
);
|
||||
return response.send(feed);
|
||||
this.dailyCount.set(feed.episodeItems.length);
|
||||
return response.send(feed.feed);
|
||||
}
|
||||
|
||||
@Get('weekly')
|
||||
@@ -170,6 +178,7 @@ export class DinosaurwetController {
|
||||
(index: number) =>
|
||||
new Date(new Date(startDate).setDate(startDate.getDate() + index * 7)),
|
||||
);
|
||||
return response.send(feed);
|
||||
this.weeklyCount.set(feed.episodeItems.length);
|
||||
return response.send(feed.feed);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user