]>
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' |
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 | |
b64c950a | 50 | account: { |
03e12d7c C |
51 | id: number |
52 | uuid: string | |
b64c950a C |
53 | name: string |
54 | displayName: string | |
55 | url: string | |
0f320037 | 56 | host: string |
457bb213 | 57 | avatar?: Avatar |
0f320037 C |
58 | } |
59 | ||
60 | channel: { | |
61 | id: number | |
62 | uuid: string | |
63 | name: string | |
64 | displayName: string | |
65 | url: string | |
b64c950a | 66 | host: string |
457bb213 | 67 | avatar?: Avatar |
b64c950a | 68 | } |
aff038cd | 69 | |
6e46de09 C |
70 | userHistory?: { |
71 | currentTime: number | |
72 | } | |
73 | ||
191764f3 C |
74 | static buildClientUrl (videoUUID: string) { |
75 | return '/videos/watch/' + videoUUID | |
76 | } | |
77 | ||
7ce44a74 | 78 | constructor (hash: VideoServerModel, translations = {}) { |
c5911fd3 | 79 | const absoluteAPIUrl = getAbsoluteAPIUrl() |
c6e0bfbf | 80 | |
d592e0a9 | 81 | this.createdAt = new Date(hash.createdAt.toString()) |
2922e048 | 82 | this.publishedAt = new Date(hash.publishedAt.toString()) |
df98563e | 83 | this.category = hash.category |
df98563e | 84 | this.licence = hash.licence |
df98563e | 85 | this.language = hash.language |
2243730c | 86 | this.privacy = hash.privacy |
2186386c C |
87 | this.waitTranscoding = hash.waitTranscoding |
88 | this.state = hash.state | |
df98563e C |
89 | this.description = hash.description |
90 | this.duration = hash.duration | |
11b8762f | 91 | this.durationLabel = durationToString(hash.duration) |
df98563e | 92 | this.id = hash.id |
0a6658fd | 93 | this.uuid = hash.uuid |
df98563e | 94 | this.isLocal = hash.isLocal |
df98563e | 95 | this.name = hash.name |
df98563e | 96 | this.thumbnailPath = hash.thumbnailPath |
c6e0bfbf | 97 | this.thumbnailUrl = absoluteAPIUrl + hash.thumbnailPath |
43f61d26 | 98 | this.previewPath = hash.previewPath |
c6e0bfbf | 99 | this.previewUrl = absoluteAPIUrl + hash.previewPath |
d8755eed | 100 | this.embedPath = hash.embedPath |
c6e0bfbf | 101 | this.embedUrl = absoluteAPIUrl + hash.embedPath |
df98563e C |
102 | this.views = hash.views |
103 | this.likes = hash.likes | |
104 | this.dislikes = hash.dislikes | |
105 | this.nsfw = hash.nsfw | |
b64c950a | 106 | this.account = hash.account |
52d9f792 | 107 | this.channel = hash.channel |
4fd8aa32 | 108 | |
22a16e36 C |
109 | this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) |
110 | this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) | |
d3e91a5f | 111 | this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) |
52d9f792 | 112 | this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) |
7ce44a74 C |
113 | |
114 | this.category.label = peertubeTranslate(this.category.label, translations) | |
115 | this.licence.label = peertubeTranslate(this.licence.label, translations) | |
116 | this.language.label = peertubeTranslate(this.language.label, translations) | |
117 | this.privacy.label = peertubeTranslate(this.privacy.label, translations) | |
2186386c | 118 | |
bbe0f064 | 119 | this.scheduledUpdate = hash.scheduledUpdate |
c8034165 | 120 | this.originallyPublishedAt = hash.originallyPublishedAt ? |
121 | new Date(hash.originallyPublishedAt.toString()) | |
122 | : null | |
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 | |
6e46de09 C |
127 | |
128 | this.userHistory = hash.userHistory | |
501bc6c2 C |
129 | } |
130 | ||
0883b324 C |
131 | isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { |
132 | // Video is not NSFW, skip | |
133 | if (this.nsfw === false) return false | |
134 | ||
135 | // Return user setting if logged in | |
136 | if (user) return user.nsfwPolicy !== 'display' | |
137 | ||
138 | // Return default instance config | |
139 | return serverConfig.instance.defaultNSFWPolicy !== 'display' | |
92fb909c | 140 | } |
501bc6c2 | 141 | } |