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