Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CON-163] Expose tracks on CN (subtask) #3122

Merged
merged 7 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const models = require('../../models')

const types = models.ContentBlacklist.Types

const getTracks = async () => {
vicky-g marked this conversation as resolved.
Show resolved Hide resolved
return BlacklistManager.getAllTrackIds()
}

const getAllContentBlacklist = async () => {
// Segments stored in the ContentBlacklist may not be associated with a track
const segmentsFromCBL = await models.ContentBlacklist.findAll({
Expand Down Expand Up @@ -38,5 +42,6 @@ const removeFromContentBlacklist = async ({ type, values }) => {
module.exports = {
getAllContentBlacklist,
addToContentBlacklist,
removeFromContentBlacklist
removeFromContentBlacklist,
getTracks
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const express = require('express')
const {
getAllContentBlacklist,
addToContentBlacklist,
removeFromContentBlacklist
removeFromContentBlacklist,
getTracks
} = require('./contentBlacklistComponentService')
const {
handleResponse,
Expand All @@ -24,6 +25,21 @@ const TYPES_SET = new Set([types.cid, types.user, types.track])

// Controllers

const getTracksController = async (req) => {
let trackIds
try {
trackIds = await getTracks()
} catch (e) {
req.logger.error(
`ContentBlackListController - Could not fetch tracks: ${e.message}`
)

return errorResponseServerError(`Could not fetch tracks`)
}

return successResponse({ values: trackIds })
}

const contentBlacklistGetAllController = async (req) => {
const blacklistedContent = await getAllContentBlacklist()
return successResponse(blacklistedContent)
Expand Down Expand Up @@ -264,7 +280,7 @@ const filterNonexistantIds = async (libs, type, ids) => {
}

// Routes

router.get('/blacklist/tracks', handleResponse(getTracksController))
router.get('/blacklist', handleResponse(contentBlacklistGetAllController))
router.post('/blacklist/add', handleResponse(contentBlacklistAddController))
router.post(
Expand Down
4 changes: 4 additions & 0 deletions creator-node/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Utils {
return new Promise((resolve) => setTimeout(resolve, ms))
}

/**
* Generates a random number from [0, max)
* @param {number} max the max random number. exclusive
*/
static getRandomInt(max) {
return Math.floor(Math.random() * max)
}
Expand Down
Loading