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