openvibers/openvibe.live Commits
menu card: build and serve it with openvibe-sdk/menu (#673)
Changes
@@@ -6,7 +6,7 @@"port": 3000,"domain": "openvibe.live (www, ingest, whip)","contracts": "openvibe-contracts v0.320.0",-- "sdk": "openvibe-sdk v0.94.0",++ "sdk": "openvibe-sdk v0.97.1","shared": "openvibe-shared v4.133.0","capabilities": ["live.chat_context.read",@@@ -24,7 +24,7 @@"node-media-server": "^2.7.1","onnxruntime-node": "^1.20.0","openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",-- "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",++ "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1","openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0","pg": "^8.23.1","sanitize-html": "^2.17.7",@@@ -2856,9 +2856,9 @@}},"node_modules/openvibe-sdk": {-- "version": "0.94.0",-- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",-- "integrity": "sha512-p3buZSOSFV81OdZgs5GoSIfMCQNJjW23eAIXIt0RVFIOvh3TByNNEMmuCanxRybFIbzh+9IDMbBwHJrBLl3JeA==",++ "version": "0.97.1",++ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",++ "integrity": "sha512-zCRmu7NoOi7kI0v04N8uypCgsuEcf9kCzkw88r0+dj9PG3AA/z+Pp4BZaX6Z1JUE3sdrtc17D5LcD05IbWsw8w==","license": "MIT","bin": {"openvibe-download": "bin/openvibe-download.js"@@@ -43,7 +43,7 @@"node-media-server": "^2.7.1","onnxruntime-node": "^1.20.0","openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",-- "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",++ "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1","openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0","pg": "^8.23.1","sanitize-html": "^2.17.7",@@@ -12,6 +12,7 @@// there is one (https on openvibe.live or an openvibe.* host); a stream without a picture gets no image.const db = require('./db/database');const contentLabels = require('./labels');++const { menuCard, menuRoute } = require('openvibe-sdk/menu');const SITE = 'live';const BASE = 'https://openvibe.live';@@@ -62,16 +63,17 @@ function cardFrom(rows, at = Date.now()) {if (image) item.image = image;return item;});-- return {++ return menuCard({id: 'live-now',site: SITE,title: 'Live now',kind: 'rail',++ origin: BASE,items,more: { label: 'See all', url: `${BASE}/` },-- updated_at: new Date(at).toISOString(),-- ttl_s: CARD_TTL_S,-- };++ ttlSeconds: CARD_TTL_S,++ updatedAt: at,++ });}/**@@@ -104,13 +106,8 @@ function createMenuCard({ load = () => db.getLiveStreams(), now = Date.now } = {return pending;}-- async function handler(_req, res) {-- const body = await card();-- res.set('Cache-Control', `public, max-age=${CARD_TTL_S}`)-- .set('Access-Control-Allow-Origin', '*')-- .set('Cross-Origin-Resource-Policy', 'cross-origin')-- .json([body]);-- }++ // openvibe-sdk/menu answers the file (CORS *, the public cache) and turns a build failure into [], never a 500.++ const handler = menuRoute(async () => [await card()], { maxAgeSeconds: CARD_TTL_S });return { card, handler, cardFrom, cacheMs: CACHE_MS };}
@@ -6,7 +6,7 @@
@@ -6,7 +6,7 @@
"port": 3000,
"port": 3000,
"domain": "openvibe.live (www, ingest, whip)",
"domain": "openvibe.live (www, ingest, whip)",
"contracts": "openvibe-contracts v0.320.0",
"contracts": "openvibe-contracts v0.320.0",
- "sdk": "openvibe-sdk v0.94.0",
+ "sdk": "openvibe-sdk v0.97.1",
"shared": "openvibe-shared v4.133.0",
"shared": "openvibe-shared v4.133.0",
"capabilities": [
"capabilities": [
"live.chat_context.read",
"live.chat_context.read",
@@ -24,7 +24,7 @@
@@ -24,7 +24,7 @@
"node-media-server": "^2.7.1",
"node-media-server": "^2.7.1",
"onnxruntime-node": "^1.20.0",
"onnxruntime-node": "^1.20.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",
- "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",
+ "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0",
"pg": "^8.23.1",
"pg": "^8.23.1",
"sanitize-html": "^2.17.7",
"sanitize-html": "^2.17.7",
@@ -2856,9 +2856,9 @@
@@ -2856,9 +2856,9 @@
}
}
},
},
"node_modules/openvibe-sdk": {
"node_modules/openvibe-sdk": {
- "version": "0.94.0",
- "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",
- "integrity": "sha512-p3buZSOSFV81OdZgs5GoSIfMCQNJjW23eAIXIt0RVFIOvh3TByNNEMmuCanxRybFIbzh+9IDMbBwHJrBLl3JeA==",
+ "version": "0.97.1",
+ "resolved": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",
+ "integrity": "sha512-zCRmu7NoOi7kI0v04N8uypCgsuEcf9kCzkw88r0+dj9PG3AA/z+Pp4BZaX6Z1JUE3sdrtc17D5LcD05IbWsw8w==",
"license": "MIT",
"license": "MIT",
"bin": {
"bin": {
"openvibe-download": "bin/openvibe-download.js"
"openvibe-download": "bin/openvibe-download.js"
@@ -43,7 +43,7 @@
@@ -43,7 +43,7 @@
"node-media-server": "^2.7.1",
"node-media-server": "^2.7.1",
"onnxruntime-node": "^1.20.0",
"onnxruntime-node": "^1.20.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",
"openvibe-contracts": "https://codeload.github.com/OpenVibers/OpenVibe.Contracts/tar.gz/refs/tags/v0.320.0",
- "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.94.0",
+ "openvibe-sdk": "https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.97.1",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0",
"openvibe-shared": "https://codeload.github.com/OpenVibers/OpenVibe.Shared/tar.gz/refs/tags/v4.133.0",
"pg": "^8.23.1",
"pg": "^8.23.1",
"sanitize-html": "^2.17.7",
"sanitize-html": "^2.17.7",
@@ -12,6 +12,7 @@
@@ -12,6 +12,7 @@
// there is one (https on openvibe.live or an openvibe.* host); a stream without a picture gets no image.
// there is one (https on openvibe.live or an openvibe.* host); a stream without a picture gets no image.
const db = require('./db/database');
const db = require('./db/database');
const contentLabels = require('./labels');
const contentLabels = require('./labels');
+const { menuCard, menuRoute } = require('openvibe-sdk/menu');
const SITE = 'live';
const SITE = 'live';
const BASE = 'https://openvibe.live';
const BASE = 'https://openvibe.live';
@@ -62,16 +63,17 @@ function cardFrom(rows, at = Date.now()) {
@@ -62,16 +63,17 @@ function cardFrom(rows, at = Date.now()) {
if (image) item.image = image;
if (image) item.image = image;
return item;
return item;
});
});
- return {
+ return menuCard({
id: 'live-now',
id: 'live-now',
site: SITE,
site: SITE,
title: 'Live now',
title: 'Live now',
kind: 'rail',
kind: 'rail',
+ origin: BASE,
items,
items,
more: { label: 'See all', url: `${BASE}/` },
more: { label: 'See all', url: `${BASE}/` },
- updated_at: new Date(at).toISOString(),
- ttl_s: CARD_TTL_S,
- };
+ ttlSeconds: CARD_TTL_S,
+ updatedAt: at,
+ });
}
}
/**
/**
@@ -104,13 +106,8 @@ function createMenuCard({ load = () => db.getLiveStreams(), now = Date.now } = {
@@ -104,13 +106,8 @@ function createMenuCard({ load = () => db.getLiveStreams(), now = Date.now } = {
return pending;
return pending;
}
}
- async function handler(_req, res) {
- const body = await card();
- res.set('Cache-Control', `public, max-age=${CARD_TTL_S}`)
- .set('Access-Control-Allow-Origin', '*')
- .set('Cross-Origin-Resource-Policy', 'cross-origin')
- .json([body]);
- }
+ // openvibe-sdk/menu answers the file (CORS *, the public cache) and turns a build failure into [], never a 500.
+ const handler = menuRoute(async () => [await card()], { maxAgeSeconds: CARD_TTL_S });
return { card, handler, cardFrom, cacheMs: CACHE_MS };
return { card, handler, cardFrom, cacheMs: CACHE_MS };
}
}