Skip to content

Commit

Permalink
api: added user custom tags to stream object (#2017)
Browse files Browse the repository at this point in the history
* api: added user custom tags to stream object

* tags -> userTags
  • Loading branch information
gioelecerati authored Jan 29, 2024
1 parent 937f47d commit ee02db1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/api/src/controllers/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ async function validateStreamPlaybackPolicy(
}
}

async function validateTags(userTags: object) {
let stringifiedTags = JSON.stringify(userTags);
if (stringifiedTags.length > 2048) {
throw new BadRequestError(
`userTags object is too large. Max size is 2048 characters`
);
}
}

async function triggerManyIdleStreamsWebhook(ids: string[], queue: Queue) {
return Promise.all(
ids.map(async (id) => {
Expand Down Expand Up @@ -994,6 +1003,10 @@ app.post(
doc.multistream
);

if (doc.userTags) {
await validateTags(doc.userTags);
}

await db.stream.create(doc);

res.status(201);
Expand Down Expand Up @@ -1443,6 +1456,7 @@ app.patch(
suspended,
multistream,
playbackPolicy,
userTags,
creatorId,
profiles,
} = payload;
Expand Down Expand Up @@ -1481,6 +1495,11 @@ app.patch(
patch = { ...patch, playbackPolicy };
}

if (userTags) {
await validateTags(userTags);
patch = { ...patch, userTags };
}

// remove undefined fields to check below
patch = JSON.parse(JSON.stringify(patch));
if (Object.keys(patch).length === 0) {
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/schema/api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ components:
example: test_stream
creatorId:
$ref: "#/components/schemas/creator-id"
userTags:
type: object
description: User input tags associated with the stream
additionalProperties:
type: string
lastSeen:
type: number
example: 1587667174725
Expand Down Expand Up @@ -474,6 +479,8 @@ components:
$ref: "#/components/schemas/stream/properties/record"
multistream:
$ref: "#/components/schemas/stream/properties/multistream"
userTags:
$ref: "#/components/schemas/stream/properties/userTags"
deactivate-many-payload:
type: object
additionalProperties: false
Expand Down Expand Up @@ -525,6 +532,8 @@ components:
$ref: "#/components/schemas/playback-policy"
profiles:
$ref: "#/components/schemas/stream/properties/profiles"
userTags:
$ref: "#/components/schemas/stream/properties/userTags"
target-add-payload:
type: object
additionalProperties: false
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/schema/db-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ components:
example: 66E2161C-7670-4D05-B71D-DA2D6979556F
lastSeen:
index: true
userTags:
type: object
isActive:
index: true
createdAt:
Expand Down

0 comments on commit ee02db1

Please sign in to comment.