diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-27 14:37:04 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-10-29 11:48:21 +0200 |
commit | 2760b454a761f6af3138b2fb5f34340772ab0d1e (patch) | |
tree | 2b3a2d81478f8b432eb54cce4caa5a760c494627 /server/models/video/formatter | |
parent | e4611b54910d8e7f2b4f8a97ee2d9cc8e1054127 (diff) | |
download | PeerTube-2760b454a761f6af3138b2fb5f34340772ab0d1e.tar.gz PeerTube-2760b454a761f6af3138b2fb5f34340772ab0d1e.tar.zst PeerTube-2760b454a761f6af3138b2fb5f34340772ab0d1e.zip |
Deprecate filter video query
Introduce include and isLocal instead
Diffstat (limited to 'server/models/video/formatter')
-rw-r--r-- | server/models/video/formatter/video-format-utils.ts | 68 |
1 files changed, 47 insertions, 21 deletions
diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts index 0cbad5684..5dc2c2f1b 100644 --- a/server/models/video/formatter/video-format-utils.ts +++ b/server/models/video/formatter/video-format-utils.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import { uuidToShort } from '@server/helpers/uuid' | 1 | import { uuidToShort } from '@server/helpers/uuid' |
2 | import { generateMagnetUri } from '@server/helpers/webtorrent' | 2 | import { generateMagnetUri } from '@server/helpers/webtorrent' |
3 | import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls' | 3 | import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls' |
4 | import { VideosCommonQueryAfterSanitize } from '@shared/models' | ||
4 | import { VideoFile } from '@shared/models/videos/video-file.model' | 5 | import { VideoFile } from '@shared/models/videos/video-file.model' |
5 | import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects' | 6 | import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects' |
6 | import { Video, VideoDetails } from '../../../../shared/models/videos' | 7 | import { Video, VideoDetails, VideoInclude } from '../../../../shared/models/videos' |
7 | import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' | 8 | import { VideoStreamingPlaylist } from '../../../../shared/models/videos/video-streaming-playlist.model' |
8 | import { isArray } from '../../../helpers/custom-validators/misc' | 9 | import { isArray } from '../../../helpers/custom-validators/misc' |
9 | import { | 10 | import { |
@@ -22,6 +23,7 @@ import { | |||
22 | getLocalVideoSharesActivityPubUrl | 23 | getLocalVideoSharesActivityPubUrl |
23 | } from '../../../lib/activitypub/url' | 24 | } from '../../../lib/activitypub/url' |
24 | import { | 25 | import { |
26 | MServer, | ||
25 | MStreamingPlaylistRedundanciesOpt, | 27 | MStreamingPlaylistRedundanciesOpt, |
26 | MVideo, | 28 | MVideo, |
27 | MVideoAP, | 29 | MVideoAP, |
@@ -34,15 +36,31 @@ import { VideoCaptionModel } from '../video-caption' | |||
34 | 36 | ||
35 | export type VideoFormattingJSONOptions = { | 37 | export type VideoFormattingJSONOptions = { |
36 | completeDescription?: boolean | 38 | completeDescription?: boolean |
37 | additionalAttributes: { | 39 | |
40 | additionalAttributes?: { | ||
38 | state?: boolean | 41 | state?: boolean |
39 | waitTranscoding?: boolean | 42 | waitTranscoding?: boolean |
40 | scheduledUpdate?: boolean | 43 | scheduledUpdate?: boolean |
41 | blacklistInfo?: boolean | 44 | blacklistInfo?: boolean |
45 | blockedOwner?: boolean | ||
42 | } | 46 | } |
43 | } | 47 | } |
44 | 48 | ||
45 | function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFormattingJSONOptions): Video { | 49 | function guessAdditionalAttributesFromQuery (query: VideosCommonQueryAfterSanitize): VideoFormattingJSONOptions { |
50 | if (!query || !query.include) return {} | ||
51 | |||
52 | return { | ||
53 | additionalAttributes: { | ||
54 | state: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), | ||
55 | waitTranscoding: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), | ||
56 | scheduledUpdate: !!(query.include & VideoInclude.NOT_PUBLISHED_STATE), | ||
57 | blacklistInfo: !!(query.include & VideoInclude.BLACKLISTED), | ||
58 | blockedOwner: !!(query.include & VideoInclude.BLOCKED_OWNER) | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | function videoModelToFormattedJSON (video: MVideoFormattable, options: VideoFormattingJSONOptions = {}): Video { | ||
46 | const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined | 64 | const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined |
47 | 65 | ||
48 | const videoObject: Video = { | 66 | const videoObject: Video = { |
@@ -101,29 +119,35 @@ function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFor | |||
101 | pluginData: (video as any).pluginData | 119 | pluginData: (video as any).pluginData |
102 | } | 120 | } |
103 | 121 | ||
104 | if (options) { | 122 | const add = options.additionalAttributes |
105 | if (options.additionalAttributes.state === true) { | 123 | if (add?.state === true) { |
106 | videoObject.state = { | 124 | videoObject.state = { |
107 | id: video.state, | 125 | id: video.state, |
108 | label: getStateLabel(video.state) | 126 | label: getStateLabel(video.state) |
109 | } | ||
110 | } | 127 | } |
128 | } | ||
111 | 129 | ||
112 | if (options.additionalAttributes.waitTranscoding === true) { | 130 | if (add?.waitTranscoding === true) { |
113 | videoObject.waitTranscoding = video.waitTranscoding | 131 | videoObject.waitTranscoding = video.waitTranscoding |
114 | } | 132 | } |
115 | 133 | ||
116 | if (options.additionalAttributes.scheduledUpdate === true && video.ScheduleVideoUpdate) { | 134 | if (add?.scheduledUpdate === true && video.ScheduleVideoUpdate) { |
117 | videoObject.scheduledUpdate = { | 135 | videoObject.scheduledUpdate = { |
118 | updateAt: video.ScheduleVideoUpdate.updateAt, | 136 | updateAt: video.ScheduleVideoUpdate.updateAt, |
119 | privacy: video.ScheduleVideoUpdate.privacy || undefined | 137 | privacy: video.ScheduleVideoUpdate.privacy || undefined |
120 | } | ||
121 | } | 138 | } |
139 | } | ||
122 | 140 | ||
123 | if (options.additionalAttributes.blacklistInfo === true) { | 141 | if (add?.blacklistInfo === true) { |
124 | videoObject.blacklisted = !!video.VideoBlacklist | 142 | videoObject.blacklisted = !!video.VideoBlacklist |
125 | videoObject.blacklistedReason = video.VideoBlacklist ? video.VideoBlacklist.reason : null | 143 | videoObject.blacklistedReason = video.VideoBlacklist ? video.VideoBlacklist.reason : null |
126 | } | 144 | } |
145 | |||
146 | if (add?.blockedOwner === true) { | ||
147 | videoObject.blockedOwner = video.VideoChannel.Account.isBlocked() | ||
148 | |||
149 | const server = video.VideoChannel.Account.Actor.Server as MServer | ||
150 | videoObject.blockedServer = !!(server?.isBlocked()) | ||
127 | } | 151 | } |
128 | 152 | ||
129 | return videoObject | 153 | return videoObject |
@@ -464,6 +488,8 @@ export { | |||
464 | videoModelToActivityPubObject, | 488 | videoModelToActivityPubObject, |
465 | getActivityStreamDuration, | 489 | getActivityStreamDuration, |
466 | 490 | ||
491 | guessAdditionalAttributesFromQuery, | ||
492 | |||
467 | getCategoryLabel, | 493 | getCategoryLabel, |
468 | getLicenceLabel, | 494 | getLicenceLabel, |
469 | getLanguageLabel, | 495 | getLanguageLabel, |