From 29d55db950015389be00c32bb95d79be343b43ca Mon Sep 17 00:00:00 2001 From: gioelecerati <50955448+gioelecerati@users.noreply.github.com> Date: Mon, 22 Apr 2024 20:24:20 +0200 Subject: [PATCH] api: ingest: direct base & playback (#2139) * api: ingest: direct base & playback * fix * fix * implement for a specific hardcoded id for tests * fix * fix --- packages/api/src/controllers/playback.ts | 11 +++++++++-- packages/api/src/controllers/user.ts | 14 +++++++++++++- packages/api/src/schema/db-schema.yaml | 3 +++ packages/api/src/test-server.ts | 2 ++ packages/api/src/types/common.d.ts | 2 ++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/api/src/controllers/playback.ts b/packages/api/src/controllers/playback.ts index 8366a57b98..26f8f86178 100644 --- a/packages/api/src/controllers/playback.ts +++ b/packages/api/src/controllers/playback.ts @@ -342,9 +342,16 @@ app.get("/:id", async (req, res) => { res.status(501); return res.json({ errors: ["Ingest not configured"] }); } - const ingest = ingests[0].base; - + let ingest = ingests[0].base; let { id } = req.params; + + if ( + (id === "1ba7nrr34rbjl4bb" || req.user?.directPlayback) && + ingests[0].baseDirect + ) { + ingest = ingests[0].baseDirect; + } + const withRecordings = req.query.recordings === "true"; const origin = req.headers["origin"] ?? ""; diff --git a/packages/api/src/controllers/user.ts b/packages/api/src/controllers/user.ts index 0081ac6381..c00f1bc511 100644 --- a/packages/api/src/controllers/user.ts +++ b/packages/api/src/controllers/user.ts @@ -480,7 +480,7 @@ app.post("/", validatePost("user"), async (req, res) => { res.json(user); }); -app.patch("/:id", authorizer({}), async (req, res) => { +app.patch("/:id/email", authorizer({}), async (req, res) => { const { email } = req.body; const userId = req.user.id; @@ -731,6 +731,18 @@ app.patch( } ); +app.patch("/:id", authorizer({ anyAdmin: true }), async (req, res) => { + const { id } = req.params; + const { directPlayback } = req.body; + + if (directPlayback) { + await db.user.update(id, { directPlayback }); + } + + res.status(204); + res.end(); +}); + app.post("/token", validatePost("user"), async (req, res) => { const user = await findUserByEmail(req.body.email); const [hashedPassword] = await hash(req.body.password, user.salt); diff --git a/packages/api/src/schema/db-schema.yaml b/packages/api/src/schema/db-schema.yaml index fb90633793..a3c13c67b2 100644 --- a/packages/api/src/schema/db-schema.yaml +++ b/packages/api/src/schema/db-schema.yaml @@ -1178,6 +1178,9 @@ components: newEmail: type: string description: temporary field for email change + directPlayback: + type: boolean + default: false kind: type: string readOnly: true diff --git a/packages/api/src/test-server.ts b/packages/api/src/test-server.ts index 453ab45978..8e2bc7ee93 100644 --- a/packages/api/src/test-server.ts +++ b/packages/api/src/test-server.ts @@ -48,7 +48,9 @@ params.ingest = [ { ingest: "rtmp://test/live", playback: "https://test/hls", + playbackDirect: "https://test/hls", base: "https://test", + baseDirect: "https://test", origin: "http://test", }, ]; diff --git a/packages/api/src/types/common.d.ts b/packages/api/src/types/common.d.ts index d21ddf4ebc..e316b718bb 100644 --- a/packages/api/src/types/common.d.ts +++ b/packages/api/src/types/common.d.ts @@ -18,8 +18,10 @@ export interface OrchestratorNodeAddress extends NodeAddress { export interface Ingest { origin?: string; base?: string; + baseDirect?: string; ingest: string; playback: string; + playbackDirect?: string; } export interface Price {