diff --git a/packages/api/src/controllers/stream.ts b/packages/api/src/controllers/stream.ts index 96ad4e7457..21c6d02fd3 100644 --- a/packages/api/src/controllers/stream.ts +++ b/packages/api/src/controllers/stream.ts @@ -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) => { @@ -994,6 +1003,10 @@ app.post( doc.multistream ); + if (doc.userTags) { + await validateTags(doc.userTags); + } + await db.stream.create(doc); res.status(201); @@ -1443,6 +1456,7 @@ app.patch( suspended, multistream, playbackPolicy, + userTags, creatorId, profiles, } = payload; @@ -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) { diff --git a/packages/api/src/schema/api-schema.yaml b/packages/api/src/schema/api-schema.yaml index 1a43ef57d9..9244c86da0 100644 --- a/packages/api/src/schema/api-schema.yaml +++ b/packages/api/src/schema/api-schema.yaml @@ -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 @@ -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 @@ -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 diff --git a/packages/api/src/schema/db-schema.yaml b/packages/api/src/schema/db-schema.yaml index 9fae4ce3cd..c8d02b6e45 100644 --- a/packages/api/src/schema/db-schema.yaml +++ b/packages/api/src/schema/db-schema.yaml @@ -651,6 +651,8 @@ components: example: 66E2161C-7670-4D05-B71D-DA2D6979556F lastSeen: index: true + userTags: + type: object isActive: index: true createdAt: