2021-06-24 15:18:54 +02:00
|
|
|
import { AccountSummary, VideoChannelSummary } from '../../../../PeerTube/shared/models'
|
|
|
|
import { AdditionalActorAttributes } from '../../../types/actor.model'
|
2022-02-26 12:52:51 +01:00
|
|
|
import { formatActorImageForDB } from './'
|
|
|
|
import { buildActorImageMapping, formatActorImageForAPI, formatActorImagesForAPI, formatActorImagesForDB } from './elastic-search-avatar'
|
2021-06-24 15:18:54 +02:00
|
|
|
|
|
|
|
function buildChannelOrAccountSummaryMapping () {
|
|
|
|
return {
|
|
|
|
id: {
|
|
|
|
type: 'long'
|
|
|
|
},
|
|
|
|
|
|
|
|
name: {
|
|
|
|
type: 'text',
|
|
|
|
fields: {
|
|
|
|
raw: {
|
|
|
|
type: 'keyword'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
displayName: {
|
|
|
|
type: 'text'
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
type: 'keyword'
|
|
|
|
},
|
|
|
|
host: {
|
|
|
|
type: 'keyword'
|
|
|
|
},
|
|
|
|
handle: {
|
|
|
|
type: 'keyword'
|
|
|
|
},
|
|
|
|
|
|
|
|
avatar: {
|
2022-02-26 12:52:51 +01:00
|
|
|
properties: buildActorImageMapping()
|
|
|
|
},
|
|
|
|
|
|
|
|
// Introduced in 4.2
|
|
|
|
avatars: {
|
|
|
|
properties: buildActorImageMapping()
|
2021-06-24 15:18:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildChannelOrAccountCommonMapping () {
|
|
|
|
return {
|
|
|
|
...buildChannelOrAccountSummaryMapping(),
|
|
|
|
|
|
|
|
followingCount: {
|
|
|
|
type: 'long'
|
|
|
|
},
|
|
|
|
followersCount: {
|
|
|
|
type: 'long'
|
|
|
|
},
|
|
|
|
|
|
|
|
createdAt: {
|
|
|
|
type: 'date',
|
|
|
|
format: 'date_optional_time'
|
|
|
|
},
|
|
|
|
updatedAt: {
|
|
|
|
type: 'date',
|
|
|
|
format: 'date_optional_time'
|
|
|
|
},
|
|
|
|
|
|
|
|
description: {
|
|
|
|
type: 'text'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatActorSummaryForAPI (actor: (AccountSummary | VideoChannelSummary) & AdditionalActorAttributes) {
|
|
|
|
return {
|
|
|
|
id: actor.id,
|
|
|
|
name: actor.name,
|
|
|
|
displayName: actor.displayName,
|
|
|
|
url: actor.url,
|
|
|
|
host: actor.host,
|
|
|
|
|
2022-02-26 12:52:51 +01:00
|
|
|
avatar: formatActorImageForAPI(actor.avatar),
|
|
|
|
avatars: formatActorImagesForAPI(actor.avatars, actor.avatar)
|
2021-06-24 15:18:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatActorForDB (actor: AccountSummary | VideoChannelSummary) {
|
|
|
|
return {
|
|
|
|
id: actor.id,
|
|
|
|
name: actor.name,
|
|
|
|
displayName: actor.displayName,
|
|
|
|
url: actor.url,
|
|
|
|
host: actor.host,
|
|
|
|
|
|
|
|
handle: `${actor.name}@${actor.host}`,
|
|
|
|
|
2022-02-26 12:52:51 +01:00
|
|
|
avatar: formatActorImageForDB(actor.avatar, actor.host),
|
|
|
|
avatars: formatActorImagesForDB(actor.avatars, actor.host)
|
2021-06-24 15:18:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
buildChannelOrAccountCommonMapping,
|
|
|
|
buildChannelOrAccountSummaryMapping,
|
|
|
|
formatActorSummaryForAPI,
|
|
|
|
formatActorForDB
|
|
|
|
}
|