From now on if JS is disabled you will still see radio's status.
This commit is contained in:
parent
efbb18cdea
commit
34884caef4
32
radio.js
32
radio.js
@ -9,12 +9,33 @@ const fetch = require("node-fetch");
|
|||||||
const config = require("./config");
|
const config = require("./config");
|
||||||
const util = require("./util");
|
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) {
|
function setRoutes(router) {
|
||||||
router.get('/', async ctx => {
|
router.get('/', async ctx => {
|
||||||
await ctx.render('index', {
|
await ctx.render('index', {
|
||||||
title: "/ Radio",
|
title: "/ Radio",
|
||||||
description: "Internet-radio broadcasting from under my desk.",
|
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 => {
|
.get('/filelist', async ctx => {
|
||||||
@ -28,14 +49,7 @@ function setRoutes(router) {
|
|||||||
path.join(__dirname, '/static/radio/assets/files/radio.arav.top.m3u'));
|
path.join(__dirname, '/static/radio/assets/files/radio.arav.top.m3u'));
|
||||||
})
|
})
|
||||||
.get('/stats', async ctx => {
|
.get('/stats', async ctx => {
|
||||||
let stats = await fetch('http://radio.home/status-json.xsl').then(r => r.json());
|
ctx.body = await getRadioStatus();
|
||||||
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,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,12 @@ block nav
|
|||||||
a(href=main_site) Back to main website
|
a(href=main_site) Back to main website
|
||||||
h1 Radio
|
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
|
block content
|
||||||
section
|
section
|
||||||
small.player-links
|
small.player-links
|
||||||
@ -21,9 +27,9 @@ block content
|
|||||||
audio(preload='none' controls)
|
audio(preload='none' controls)
|
||||||
source(src="/live/stream.ogg" type="audio/ogg")
|
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]!
|
| 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]
|
+radioStatus(radio_status.server_start_date, radio_status.server_start_iso8601)
|
||||||
p Now playing: #[span#radio-song n/a]
|
p Now playing: #[span#radio-song= radio_status.song]
|
||||||
p Current/peak listeners: #[span#radio-listeners n/a] / #[span#radio-listener-peak n/a]
|
p Current/peak listeners: #[span#radio-listeners= radio_status.listeners] / #[span#radio-listener-peak= radio_status.listener_peak]
|
||||||
p
|
p
|
||||||
small Notice: information updates every 45 seconds. But you can #[a(href="javascript:getRadioStats()") update] it forcibly.
|
small Notice: information updates every 45 seconds. But you can #[a(href="javascript:getRadioStats()") update] it forcibly.
|
||||||
section
|
section
|
||||||
|
Loading…
Reference in New Issue
Block a user