]>
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' |
09700934 | 4 | import { VideoConstant } from '../../../../../shared/models/videos/video.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 |
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 |
2186386c | 43 | |
b64c950a | 44 | account: { |
03e12d7c C |
45 | id: number |
46 | uuid: string | |
b64c950a C |
47 | name: string |
48 | displayName: string | |
49 | url: string | |
0f320037 C |
50 | host: string |
51 | avatar: Avatar | |
52 | } | |
53 | ||
54 | channel: { | |
55 | id: number | |
56 | uuid: string | |
57 | name: string | |
58 | displayName: string | |
59 | url: string | |
b64c950a C |
60 | host: string |
61 | avatar: Avatar | |
62 | } | |
aff038cd | 63 | |
df98563e | 64 | private static createDurationString (duration: number) { |
f6aec1b0 | 65 | const hours = Math.floor(duration / 3600) |
2186386c | 66 | const minutes = Math.floor((duration % 3600) / 60) |
df98563e | 67 | const seconds = duration % 60 |
f6aec1b0 | 68 | |
df98563e C |
69 | const minutesPadding = minutes >= 10 ? '' : '0' |
70 | const secondsPadding = seconds >= 10 ? '' : '0' | |
f6aec1b0 | 71 | const displayedHours = hours > 0 ? hours.toString() + ':' : '' |
4fd8aa32 | 72 | |
2186386c | 73 | return displayedHours + minutesPadding + minutes.toString() + ':' + secondsPadding + seconds.toString() |
4fd8aa32 C |
74 | } |
75 | ||
7ce44a74 | 76 | constructor (hash: VideoServerModel, translations = {}) { |
c5911fd3 | 77 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 78 | |
d592e0a9 | 79 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 80 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 81 | this.category = hash.category |
df98563e | 82 | this.licence = hash.licence |
df98563e | 83 | this.language = hash.language |
2243730c | 84 | this.privacy = hash.privacy |
2186386c C |
85 | this.waitTranscoding = hash.waitTranscoding |
86 | this.state = hash.state | |
df98563e C |
87 | this.description = hash.description |
88 | this.duration = hash.duration | |
89 | this.durationLabel = Video.createDurationString(hash.duration) | |
90 | this.id = hash.id | |
0a6658fd | 91 | this.uuid = hash.uuid |
df98563e | 92 | this.isLocal = hash.isLocal |
df98563e | 93 | this.name = hash.name |
df98563e | 94 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 95 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 96 | this.previewPath = hash.previewPath |
c6e0bfbf | 97 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 98 | this.embedPath = hash.embedPath |
c6e0bfbf | 99 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
100 | this.views = hash.views |
101 | this.likes = hash.likes | |
102 | this.dislikes = hash.dislikes | |
103 | this.nsfw = hash.nsfw | |
b64c950a | 104 | this.account = hash.account |
4fd8aa32 | 105 | |
d3e91a5f C |
106 | this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
107 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) | |
7ce44a74 C |
108 | |
109 | this.category.label = peertubeTranslate(this.category.label, translations) | |
110 | this.licence.label = peertubeTranslate(this.licence.label, translations) | |
111 | this.language.label = peertubeTranslate(this.language.label, translations) | |
112 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
2186386c | 113 | |
bbe0f064 | 114 | this.scheduledUpdate = hash.scheduledUpdate |
2186386c | 115 | if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) |
501bc6c2 C |
116 | } |
117 | ||
0883b324 C |
118 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
119 | // Video is not NSFW, skip | |
120 | if (this.nsfw === false) return false | |
121 | ||
122 | // Return user setting if logged in | |
123 | if (user) return user.nsfwPolicy !== 'display' | |
124 | ||
125 | // Return default instance config | |
126 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 127 | } |
501bc6c2 | 128 | } |