Add videosCount to channels
This commit is contained in:
parent
c19de268fd
commit
4f8f324438
|
@ -155,6 +155,7 @@ function formatChannelForDB (c: IndexableChannel): DBChannel {
|
|||
|
||||
description: c.description,
|
||||
support: c.support,
|
||||
videosCount: c.videosCount,
|
||||
|
||||
handle: `${c.name}@${c.host}`,
|
||||
|
||||
|
@ -182,6 +183,10 @@ function buildChannelsMapping () {
|
|||
const base = buildChannelOrAccountCommonMapping()
|
||||
|
||||
Object.assign(base, {
|
||||
videosCount: {
|
||||
type: 'long'
|
||||
},
|
||||
|
||||
support: {
|
||||
type: 'keyword'
|
||||
},
|
||||
|
|
|
@ -25,7 +25,27 @@ async function getChannel (host: string, name: string): Promise<IndexableChannel
|
|||
json: true
|
||||
}, REQUESTS.MAX_RETRIES, REQUESTS.WAIT)
|
||||
|
||||
return prepareChannelForDB(res.body, host)
|
||||
const videosCount = await getChannelVideosCount(host, name)
|
||||
|
||||
return prepareChannelForDB(res.body, host, videosCount)
|
||||
}
|
||||
|
||||
async function getChannelVideosCount (host: string, name: string): Promise<number> {
|
||||
const url = 'https://' + host + '/api/v1/video-channels/' + name + '/videos'
|
||||
|
||||
const res = await doRequestWithRetries<ResultList<Video>>({
|
||||
uri: url,
|
||||
qs: {
|
||||
start: 0,
|
||||
count: 0
|
||||
},
|
||||
json: true
|
||||
}, REQUESTS.MAX_RETRIES, REQUESTS.WAIT)
|
||||
|
||||
const total = res.body?.total
|
||||
if (!total || typeof total !== 'number') return 0
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
async function getVideos (host: string, start: number): Promise<IndexableVideo[]> {
|
||||
|
@ -78,10 +98,11 @@ function prepareVideoForDB <T extends Video> (video: T, host: string): T & Index
|
|||
})
|
||||
}
|
||||
|
||||
function prepareChannelForDB (channel: VideoChannel, host: string): IndexableChannel {
|
||||
function prepareChannelForDB (channel: VideoChannel, host: string, videosCount: number): IndexableChannel {
|
||||
return Object.assign(channel, {
|
||||
elasticSearchId: host + channel.id,
|
||||
host,
|
||||
videosCount,
|
||||
url: 'https://' + host + '/video-channels/' + channel.name
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue