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