From 61d6864eaca1dcb58892b796faa1bd7750be9511 Mon Sep 17 00:00:00 2001 From: gioelecerati <50955448+gioelecerati@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:41:02 +0100 Subject: [PATCH] api: flag streams as pull created for auth header in webhook (#2064) * api: flag streams as pull created for auth header in webhook * update naming * rename rate limit back as well --- packages/api/src/controllers/access-control.ts | 10 +++++----- packages/api/src/controllers/stream.ts | 1 + packages/api/src/schema/api-schema.yaml | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/api/src/controllers/access-control.ts b/packages/api/src/controllers/access-control.ts index 38b7aa1f79..03cd114691 100644 --- a/packages/api/src/controllers/access-control.ts +++ b/packages/api/src/controllers/access-control.ts @@ -33,14 +33,14 @@ const app = Router(); type GateConfig = { refresh_interval: number; - rateLimit: number; + rate_limit: number; }; async function fireGateWebhook( webhook: DBWebhook, plabackPolicy: PlaybackPolicy, payload: AccessControlGatePayload, - isTrovoAuth: boolean + isPullStream: boolean ) { let timestamp = Date.now(); let jsonPayload = { @@ -63,7 +63,7 @@ async function fireGateWebhook( body: JSON.stringify(jsonPayload), }; - if (isTrovoAuth) { + if (isPullStream) { params.headers["Trovo-Auth-Version"] = "1.1"; } @@ -152,7 +152,7 @@ app.post( if (user.createdAt > HACKER_DISABLE_CUTOFF_DATE) { if (isFreeTierUser(user)) { - config.rateLimit = MAX_ALLOWED_VIEWERS_FOR_HACKER_TIER_PER_NODE; + config.rate_limit = MAX_ALLOWED_VIEWERS_FOR_HACKER_TIER_PER_NODE; } } @@ -257,7 +257,7 @@ app.post( webhook, content.playbackPolicy, gatePayload, - content.isTrovoAuth + content.isPullStream ); if (statusCode >= 200 && statusCode < 300) { diff --git a/packages/api/src/controllers/stream.ts b/packages/api/src/controllers/stream.ts index 8e5ca93872..b850c91771 100644 --- a/packages/api/src/controllers/stream.ts +++ b/packages/api/src/controllers/stream.ts @@ -1038,6 +1038,7 @@ app.put( profiles: req.config.defaultStreamProfiles, ...rawPayload, creatorId: mapInputCreatorId(rawPayload.creatorId), + isPullStream: true, }; const keyValue = _.get(payload, pullStreamKeyAccessors[key]); diff --git a/packages/api/src/schema/api-schema.yaml b/packages/api/src/schema/api-schema.yaml index 94cf6f12b3..c5868b7e9d 100644 --- a/packages/api/src/schema/api-schema.yaml +++ b/packages/api/src/schema/api-schema.yaml @@ -472,12 +472,12 @@ components: description: Used to form playback URL playbackPolicy: $ref: "#/components/schemas/playback-policy" - isTrovoAuth: + isPullStream: type: boolean readOnly: true description: >- - Wether the stream is authenticated by Trovo. If true, any webhook - policy will include the Trovo Auth header + Wether the stream is a pull stream. If true, any webhook policy will + include the Trovo Auth header profiles: type: array default: @@ -873,12 +873,12 @@ components: description: URL to manually download the asset if desired playbackPolicy: $ref: "#/components/schemas/playback-policy" - isTrovoAuth: + isPullStream: type: boolean readOnly: true description: >- - Wether the stream is authenticated by Trovo. If true, any webhook - policy will include the Trovo Auth header + Wether the stream is a pull stream. If true, any webhook policy will + include the Trovo Auth header source: oneOf: - additionalProperties: false