]>
Commit | Line | Data |
---|---|---|
202f6b6c | 1 | import { User } from '../' |
2186386c | 2 | import { Video as VideoServerModel, VideoPrivacy, VideoState } from '../../../../../shared' |
b64c950a | 3 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
40e87e9e | 4 | import { VideoConstant } from '../../../../../shared/models/videos/video-constant.model' |
c5911fd3 | 5 | import { getAbsoluteAPIUrl } from '../misc/utils' |
0883b324 | 6 | import { ServerConfig } from '../../../../../shared/models' |
d3e91a5f | 7 | import { Actor } from '@app/shared/actor/actor.model' |
7ce44a74 | 8 | import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' |
bbe0f064 | 9 | import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' |
92fb909c | 10 | |
69f616ab | 11 | export class Video implements VideoServerModel { |
df98563e | 12 | by: string |
d3e91a5f | 13 | accountAvatarUrl: string |
52d9f792 | 14 | videoChannelAvatarUrl: string |
df98563e | 15 | createdAt: Date |
6d33593a | 16 | updatedAt: Date |
2922e048 | 17 | publishedAt: Date |
09700934 C |
18 | category: VideoConstant<number> |
19 | licence: VideoConstant<number> | |
9d3ef9fe | 20 | language: VideoConstant<string> |
2243730c | 21 | privacy: VideoConstant<VideoPrivacy> |
df98563e C |
22 | description: string |
23 | duration: number | |
24 | durationLabel: string | |
0a6658fd C |
25 | id: number |
26 | uuid: string | |
df98563e | 27 | isLocal: boolean |
df98563e | 28 | name: string |
60862425 | 29 | serverHost: string |
df98563e C |
30 | thumbnailPath: string |
31 | thumbnailUrl: string | |
43f61d26 C |
32 | previewPath: string |
33 | previewUrl: string | |
d8755eed C |
34 | embedPath: string |
35 | embedUrl: string | |
df98563e C |
36 | views: number |
37 | likes: number | |
38 | dislikes: number | |
39 | nsfw: boolean | |
b64c950a | 40 | |
2186386c C |
41 | waitTranscoding?: boolean |
42 | state?: VideoConstant<VideoState> | |
bbe0f064 | 43 | scheduledUpdate?: VideoScheduleUpdate |
191764f3 C |
44 | blacklisted?: boolean |
45 | blacklistedReason?: string | |
2186386c | 46 | |
b64c950a | 47 | account: { |
03e12d7c C |
48 | id: number |
49 | uuid: string | |
b64c950a C |
50 | name: string |
51 | displayName: string | |
52 | url: string | |
0f320037 C |
53 | host: string |
54 | avatar: Avatar | |
55 | } | |
56 | ||
57 | channel: { | |
58 | id: number | |
59 | uuid: string | |
60 | name: string | |
61 | displayName: string | |
62 | url: string | |
b64c950a C |
63 | host: string |
64 | avatar: Avatar | |
65 | } | |
aff038cd | 66 | |
191764f3 C |
67 | static buildClientUrl (videoUUID: string) { |
68 | return '/videos/watch/' + videoUUID | |
69 | } | |
70 | ||
df98563e | 71 | private static createDurationString (duration: number) { |
f6aec1b0 | 72 | const hours = Math.floor(duration / 3600) |
2186386c | 73 | const minutes = Math.floor((duration % 3600) / 60) |
df98563e | 74 | const seconds = duration % 60 |
f6aec1b0 | 75 | |
df98563e C |
76 | const minutesPadding = minutes >= 10 ? '' : '0' |
77 | const secondsPadding = seconds >= 10 ? '' : '0' | |
f6aec1b0 | 78 | const displayedHours = hours > 0 ? hours.toString() + ':' : '' |
4fd8aa32 | 79 | |
2186386c | 80 | return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() |
4fd8aa32 C |
81 | } |
82 | ||
7ce44a74 | 83 | constructor (hash: VideoServerModel, translations = {}) { |
c5911fd3 | 84 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 85 | |
d592e0a9 | 86 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 87 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 88 | this.category = hash.category |
df98563e | 89 | this.licence = hash.licence |
df98563e | 90 | this.language = hash.language |
2243730c | 91 | this.privacy = hash.privacy |
2186386c C |
92 | this.waitTranscoding = hash.waitTranscoding |
93 | this.state = hash.state | |
df98563e C |
94 | this.description = hash.description |
95 | this.duration = hash.duration | |
96 | this.durationLabel = Video.createDurationString(hash.duration) | |
97 | this.id = hash.id | |
0a6658fd | 98 | this.uuid = hash.uuid |
df98563e | 99 | this.isLocal = hash.isLocal |
df98563e | 100 | this.name = hash.name |
df98563e | 101 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 102 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 103 | this.previewPath = hash.previewPath |
c6e0bfbf | 104 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 105 | this.embedPath = hash.embedPath |
c6e0bfbf | 106 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
107 | this.views = hash.views |
108 | this.likes = hash.likes | |
109 | this.dislikes = hash.dislikes | |
110 | this.nsfw = hash.nsfw | |
b64c950a | 111 | this.account = hash.account |
52d9f792 | 112 | this.channel = hash.channel |
4fd8aa32 | 113 | |
d3e91a5f C |
114 | this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
115 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) | |
52d9f792 | 116 | this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) |
7ce44a74 C |
117 | |
118 | this.category.label = peertubeTranslate(this.category.label, translations) | |
119 | this.licence.label = peertubeTranslate(this.licence.label, translations) | |
120 | this.language.label = peertubeTranslate(this.language.label, translations) | |
121 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
2186386c | 122 | |
bbe0f064 | 123 | this.scheduledUpdate = hash.scheduledUpdate |
2186386c | 124 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) |
191764f3 C |
125 | |
126 | this.blacklisted = hash.blacklisted | |
127 | this.blacklistedReason = hash.blacklistedReason | |
501bc6c2 C |
128 | } |
129 | ||
0883b324 C |
130 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
131 | // Video is not NSFW, skip | |
132 | if (this.nsfw === false) return false | |
133 | ||
134 | // Return user setting if logged in | |
135 | if (user) return user.nsfwPolicy !== 'display' | |
136 | ||
137 | // Return default instance config | |
138 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 139 | } |
501bc6c2 | 140 | } |