Skip to content

Commit

Permalink
api: flag streams as pull created for auth header in webhook (#2064)
Browse files Browse the repository at this point in the history
* api: flag streams as pull created for auth header in webhook

* update naming

* rename rate limit back as well
  • Loading branch information
gioelecerati authored Feb 19, 2024
1 parent 76b3a9c commit 61d6864
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/api/src/controllers/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -63,7 +63,7 @@ async function fireGateWebhook(
body: JSON.stringify(jsonPayload),
};

if (isTrovoAuth) {
if (isPullStream) {
params.headers["Trovo-Auth-Version"] = "1.1";
}

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -257,7 +257,7 @@ app.post(
webhook,
content.playbackPolicy,
gatePayload,
content.isTrovoAuth
content.isPullStream
);

if (statusCode >= 200 && statusCode < 300) {
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/controllers/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ app.put(
profiles: req.config.defaultStreamProfiles,
...rawPayload,
creatorId: mapInputCreatorId(rawPayload.creatorId),
isPullStream: true,
};

const keyValue = _.get(payload, pullStreamKeyAccessors[key]);
Expand Down
12 changes: 6 additions & 6 deletions packages/api/src/schema/api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 61d6864

Please sign in to comment.