Skip to content

Commit

Permalink
api: acl: remove redundant isPullStream (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelecerati authored Feb 21, 2024
1 parent 995d727 commit a91a2b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
22 changes: 8 additions & 14 deletions packages/api/src/controllers/access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import fetch from "node-fetch";
import { HACKER_DISABLE_CUTOFF_DATE } from "./utils/notification";
import { isFreeTierUser } from "./helpers";
import { cache } from "../store/cache";
import { DBStream } from "../store/stream-table";
import { WithID } from "../store/types";

const WEBHOOK_TIMEOUT = 30 * 1000;
const MAX_ALLOWED_VIEWERS_FOR_HACKER_TIER_PER_NODE = 5;
Expand All @@ -38,21 +40,19 @@ type GateConfig = {

async function fireGateWebhook(
webhook: DBWebhook,
plabackPolicy: PlaybackPolicy,
payload: AccessControlGatePayload,
isPullStream: boolean,
contentName: string
content: DBStream | WithID<Asset>,
payload: AccessControlGatePayload
) {
let timestamp = Date.now();
let jsonPayload = {
context: plabackPolicy.webhookContext,
context: content.playbackPolicy.webhookContext,
accessKey: payload.accessKey,
timestamp: timestamp,
};

if (payload.webhookPayload) {
if (payload.webhookPayload.headers) {
payload.webhookPayload.headers["Tx-Stream-Id"] = contentName;
payload.webhookPayload.headers["Tx-Stream-Id"] = content.name;
}
jsonPayload = { ...jsonPayload, ...payload.webhookPayload };
}
Expand All @@ -67,7 +67,7 @@ async function fireGateWebhook(
body: JSON.stringify(jsonPayload),
};

if (isPullStream) {
if ("pull" in content && content.pull) {
params.headers["Trovo-Auth-Version"] = "1.1";
}

Expand Down Expand Up @@ -266,13 +266,7 @@ app.post(

const gatePayload: AccessControlGatePayload = req.body;

const statusCode = await fireGateWebhook(
webhook,
content.playbackPolicy,
gatePayload,
content.isPullStream,
content.name
);
const statusCode = await fireGateWebhook(webhook, content, gatePayload);

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

const keyValue = _.get(payload, pullStreamKeyAccessors[key]);
Expand Down
12 changes: 0 additions & 12 deletions packages/api/src/schema/api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,6 @@ components:
description: Used to form playback URL
playbackPolicy:
$ref: "#/components/schemas/playback-policy"
isPullStream:
type: boolean
readOnly: true
description: >-
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 +867,6 @@ components:
description: URL to manually download the asset if desired
playbackPolicy:
$ref: "#/components/schemas/playback-policy"
isPullStream:
type: boolean
readOnly: true
description: >-
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 a91a2b1

Please sign in to comment.