- const { baseUrlHttp, baseUrlWs } = this.getBaseUrls()
- if (!this.Tags) this.Tags = []
-
- const tag = this.Tags.map(t => ({
- type: 'Hashtag' as 'Hashtag',
- name: t.name
- }))
-
- let language
- if (this.language) {
- language = {
- identifier: this.language + '',
- name: VideoModel.getLanguageLabel(this.language)
- }
- }
-
- let category
- if (this.category) {
- category = {
- identifier: this.category + '',
- name: VideoModel.getCategoryLabel(this.category)
- }
- }
-
- let licence
- if (this.licence) {
- licence = {
- identifier: this.licence + '',
- name: VideoModel.getLicenceLabel(this.licence)
- }
- }
-
- let likesObject
- let dislikesObject
-
- if (Array.isArray(this.AccountVideoRates)) {
- const res = this.toRatesActivityPubObjects()
- likesObject = res.likesObject
- dislikesObject = res.dislikesObject
- }
-
- let sharesObject
- if (Array.isArray(this.VideoShares)) {
- sharesObject = this.toAnnouncesActivityPubObject()
- }
-
- let commentsObject
- if (Array.isArray(this.VideoComments)) {
- commentsObject = this.toCommentsActivityPubObject()
- }
-
- const url = []
- for (const file of this.VideoFiles) {
- url.push({
- type: 'Link',
- mimeType: 'video/' + file.extname.replace('.', ''),
- href: this.getVideoFileUrl(file, baseUrlHttp),
- width: file.resolution,
- size: file.size
- })
-
- url.push({
- type: 'Link',
- mimeType: 'application/x-bittorrent',
- href: this.getTorrentUrl(file, baseUrlHttp),
- width: file.resolution
- })
-
- url.push({
- type: 'Link',
- mimeType: 'application/x-bittorrent;x-scheme-handler/magnet',
- href: this.generateMagnetUri(file, baseUrlHttp, baseUrlWs),
- width: file.resolution
- })
- }
-
- // Add video url too
- url.push({
- type: 'Link',
- mimeType: 'text/html',
- href: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid
- })
-
- return {
- type: 'Video' as 'Video',
- id: this.url,
- name: this.name,
- duration: this.getActivityStreamDuration(),
- uuid: this.uuid,
- tag,
- category,
- licence,
- language,
- views: this.views,
- sensitive: this.nsfw,
- commentsEnabled: this.commentsEnabled,
- published: this.publishedAt.toISOString(),
- updated: this.updatedAt.toISOString(),
- mediaType: 'text/markdown',
- content: this.getTruncatedDescription(),
- support: this.support,
- icon: {
- type: 'Image',
- url: this.getThumbnailUrl(baseUrlHttp),
- mediaType: 'image/jpeg',
- width: THUMBNAILS_SIZE.width,
- height: THUMBNAILS_SIZE.height
- },
- url,
- likes: likesObject,
- dislikes: dislikesObject,
- shares: sharesObject,
- comments: commentsObject,
- attributedTo: [
- {
- type: 'Person',
- id: this.VideoChannel.Account.Actor.url
- },
- {
- type: 'Group',
- id: this.VideoChannel.Actor.url
- }
- ]
- }
- }
-
- toAnnouncesActivityPubObject () {
- const shares: string[] = []
-
- for (const videoShare of this.VideoShares) {
- shares.push(videoShare.url)
- }
-
- return activityPubCollection(getVideoSharesActivityPubUrl(this), shares)
- }
-
- toCommentsActivityPubObject () {
- const comments: string[] = []
-
- for (const videoComment of this.VideoComments) {
- comments.push(videoComment.url)
- }
-
- return activityPubCollection(getVideoCommentsActivityPubUrl(this), comments)
- }
-
- toRatesActivityPubObjects () {
- const likes: string[] = []
- const dislikes: string[] = []
-
- for (const rate of this.AccountVideoRates) {
- if (rate.type === 'like') {
- likes.push(rate.Account.Actor.url)
- } else if (rate.type === 'dislike') {
- dislikes.push(rate.Account.Actor.url)
- }
- }
-
- const likesObject = activityPubCollection(getVideoLikesActivityPubUrl(this), likes)
- const dislikesObject = activityPubCollection(getVideoDislikesActivityPubUrl(this), dislikes)
-
- return { likesObject, dislikesObject }