From now on if JS is disabled you will still see radio's status.

This commit is contained in:
Alexander Andreev 2021-02-17 03:44:34 +04:00
parent efbb18cdea
commit 34884caef4
Signed by: Arav
GPG Key ID: 610DF2574456329F
2 changed files with 32 additions and 12 deletions

View File

@ -9,12 +9,33 @@ const fetch = require("node-fetch");
const config = require("./config");
const util = require("./util");
async function getRadioStatus() {
let status = await fetch('http://radio.home/status-json.xsl').then(r => r.json())
.catch(() => {
return {
server_start_iso8601: "n/a",
server_start_date: "n/a",
song: "n/a",
listener_peak: "n/a",
listeners: "n/a"
}
});
return {
server_start_iso8601: status.icestats.server_start_iso8601,
server_start_date: util.datetime(status.icestats.server_start_iso8601, util.post_date_format),
song: `${status.icestats.source.artist} - ${status.icestats.source.title}`,
listener_peak: status.icestats.source.listener_peak,
listeners: status.icestats.source.listeners
}
}
function setRoutes(router) {
router.get('/', async ctx => {
await ctx.render('index', {
title: "/ Radio",
description: "Internet-radio broadcasting from under my desk.",
main_site: util.getServiceByHost(ctx.header.host)
main_site: util.getServiceByHost(ctx.header.host),
radio_status: await getRadioStatus()
});
})
.get('/filelist', async ctx => {
@ -28,14 +49,7 @@ function setRoutes(router) {
path.join(__dirname, '/static/radio/assets/files/radio.arav.top.m3u'));
})
.get('/stats', async ctx => {
let stats = await fetch('http://radio.home/status-json.xsl').then(r => r.json());
ctx.body = {
server_start_iso8601: stats.icestats.server_start_iso8601,
server_start_date: util.datetime(stats.icestats.server_start_iso8601, util.post_date_format),
song: `${stats.icestats.source.artist} - ${stats.icestats.source.title}`,
listener_peak: stats.icestats.source.listener_peak,
listeners: stats.icestats.source.listeners,
};
ctx.body = await getRadioStatus();
});
}

View File

@ -8,6 +8,12 @@ block nav
a(href=main_site) Back to main website
h1 Radio
mixin radioStatus(date, iso)
if (date != "n/a")
p #[span#radio-status On-air since #[time(datetime=iso)= date]]
else
p #[span#radio-status Radio is offline.]
block content
section
small.player-links
@ -21,9 +27,9 @@ block content
audio(preload='none' controls)
source(src="/live/stream.ogg" type="audio/ogg")
| Your browser doesn't support an audio element, it's sad... But you always can take the #[a(href="/playlist") playlist]!
p #[span#radio-status n/a]
p Now playing: #[span#radio-song n/a]
p Current/peak listeners: #[span#radio-listeners n/a] / #[span#radio-listener-peak n/a]
+radioStatus(radio_status.server_start_date, radio_status.server_start_iso8601)
p Now playing: #[span#radio-song= radio_status.song]
p Current/peak listeners: #[span#radio-listeners= radio_status.listeners] / #[span#radio-listener-peak= radio_status.listener_peak]
p
small Notice: information updates every 45 seconds. But you can #[a(href="javascript:getRadioStats()") update] it forcibly.
section