diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-channel.ts | 59 | ||||
-rw-r--r-- | server/models/video/video-file.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-playlist.ts | 24 | ||||
-rw-r--r-- | server/models/video/video-streaming-playlist.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 2 |
5 files changed, 65 insertions, 24 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 183e7448c..9aa271711 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction } from 'sequelize' | 1 | import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction, WhereOptions } from 'sequelize' |
2 | import { | 2 | import { |
3 | AllowNull, | 3 | AllowNull, |
4 | BeforeDestroy, | 4 | BeforeDestroy, |
@@ -17,7 +17,6 @@ import { | |||
17 | Table, | 17 | Table, |
18 | UpdatedAt | 18 | UpdatedAt |
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { setAsUpdated } from '@server/helpers/database-utils' | ||
21 | import { MAccountActor } from '@server/types/models' | 20 | import { MAccountActor } from '@server/types/models' |
22 | import { AttributesOnly } from '@shared/core-utils' | 21 | import { AttributesOnly } from '@shared/core-utils' |
23 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 22 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
@@ -41,6 +40,7 @@ import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor' | |||
41 | import { ActorFollowModel } from '../actor/actor-follow' | 40 | import { ActorFollowModel } from '../actor/actor-follow' |
42 | import { ActorImageModel } from '../actor/actor-image' | 41 | import { ActorImageModel } from '../actor/actor-image' |
43 | import { ServerModel } from '../server/server' | 42 | import { ServerModel } from '../server/server' |
43 | import { setAsUpdated } from '../shared' | ||
44 | import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' | 44 | import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' |
45 | import { VideoModel } from './video' | 45 | import { VideoModel } from './video' |
46 | import { VideoPlaylistModel } from './video-playlist' | 46 | import { VideoPlaylistModel } from './video-playlist' |
@@ -58,6 +58,7 @@ export enum ScopeNames { | |||
58 | type AvailableForListOptions = { | 58 | type AvailableForListOptions = { |
59 | actorId: number | 59 | actorId: number |
60 | search?: string | 60 | search?: string |
61 | host?: string | ||
61 | } | 62 | } |
62 | 63 | ||
63 | type AvailableWithStatsOptions = { | 64 | type AvailableWithStatsOptions = { |
@@ -83,6 +84,33 @@ export type SummaryOptions = { | |||
83 | // Only list local channels OR channels that are on an instance followed by actorId | 84 | // Only list local channels OR channels that are on an instance followed by actorId |
84 | const inQueryInstanceFollow = buildServerIdsFollowedBy(options.actorId) | 85 | const inQueryInstanceFollow = buildServerIdsFollowedBy(options.actorId) |
85 | 86 | ||
87 | const whereActor = { | ||
88 | [Op.or]: [ | ||
89 | { | ||
90 | serverId: null | ||
91 | }, | ||
92 | { | ||
93 | serverId: { | ||
94 | [Op.in]: Sequelize.literal(inQueryInstanceFollow) | ||
95 | } | ||
96 | } | ||
97 | ] | ||
98 | } | ||
99 | |||
100 | let serverRequired = false | ||
101 | let whereServer: WhereOptions | ||
102 | |||
103 | if (options.host && options.host !== WEBSERVER.HOST) { | ||
104 | serverRequired = true | ||
105 | whereServer = { host: options.host } | ||
106 | } | ||
107 | |||
108 | if (options.host === WEBSERVER.HOST) { | ||
109 | Object.assign(whereActor, { | ||
110 | [Op.and]: [ { serverId: null } ] | ||
111 | }) | ||
112 | } | ||
113 | |||
86 | return { | 114 | return { |
87 | include: [ | 115 | include: [ |
88 | { | 116 | { |
@@ -90,20 +118,19 @@ export type SummaryOptions = { | |||
90 | exclude: unusedActorAttributesForAPI | 118 | exclude: unusedActorAttributesForAPI |
91 | }, | 119 | }, |
92 | model: ActorModel, | 120 | model: ActorModel, |
93 | where: { | 121 | where: whereActor, |
94 | [Op.or]: [ | ||
95 | { | ||
96 | serverId: null | ||
97 | }, | ||
98 | { | ||
99 | serverId: { | ||
100 | [Op.in]: Sequelize.literal(inQueryInstanceFollow) | ||
101 | } | ||
102 | } | ||
103 | ] | ||
104 | }, | ||
105 | include: [ | 122 | include: [ |
106 | { | 123 | { |
124 | model: ServerModel, | ||
125 | required: serverRequired, | ||
126 | where: whereServer | ||
127 | }, | ||
128 | { | ||
129 | model: ActorImageModel, | ||
130 | as: 'Avatar', | ||
131 | required: false | ||
132 | }, | ||
133 | { | ||
107 | model: ActorImageModel, | 134 | model: ActorImageModel, |
108 | as: 'Banner', | 135 | as: 'Banner', |
109 | required: false | 136 | required: false |
@@ -431,6 +458,8 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` | |||
431 | start: number | 458 | start: number |
432 | count: number | 459 | count: number |
433 | sort: string | 460 | sort: string |
461 | |||
462 | host?: string | ||
434 | }) { | 463 | }) { |
435 | const attributesInclude = [] | 464 | const attributesInclude = [] |
436 | const escapedSearch = VideoChannelModel.sequelize.escape(options.search) | 465 | const escapedSearch = VideoChannelModel.sequelize.escape(options.search) |
@@ -458,7 +487,7 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"` | |||
458 | 487 | ||
459 | return VideoChannelModel | 488 | return VideoChannelModel |
460 | .scope({ | 489 | .scope({ |
461 | method: [ ScopeNames.FOR_API, { actorId: options.actorId } as AvailableForListOptions ] | 490 | method: [ ScopeNames.FOR_API, { actorId: options.actorId, host: options.host } as AvailableForListOptions ] |
462 | }) | 491 | }) |
463 | .findAndCountAll(query) | 492 | .findAndCountAll(query) |
464 | .then(({ rows, count }) => { | 493 | .then(({ rows, count }) => { |
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 797a85a4e..09fc5288b 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -21,7 +21,6 @@ import { | |||
21 | import { Where } from 'sequelize/types/lib/utils' | 21 | import { Where } from 'sequelize/types/lib/utils' |
22 | import validator from 'validator' | 22 | import validator from 'validator' |
23 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' | 23 | import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' |
24 | import { doesExist } from '@server/helpers/database-utils' | ||
25 | import { logger } from '@server/helpers/logger' | 24 | import { logger } from '@server/helpers/logger' |
26 | import { extractVideo } from '@server/helpers/video' | 25 | import { extractVideo } from '@server/helpers/video' |
27 | import { getTorrentFilePath } from '@server/lib/video-paths' | 26 | import { getTorrentFilePath } from '@server/lib/video-paths' |
@@ -45,6 +44,7 @@ import { | |||
45 | } from '../../initializers/constants' | 44 | } from '../../initializers/constants' |
46 | import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileVideo } from '../../types/models/video/video-file' | 45 | import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileVideo } from '../../types/models/video/video-file' |
47 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 46 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
47 | import { doesExist } from '../shared' | ||
48 | import { parseAggregateResult, throwIfNotValid } from '../utils' | 48 | import { parseAggregateResult, throwIfNotValid } from '../utils' |
49 | import { VideoModel } from './video' | 49 | import { VideoModel } from './video' |
50 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' | 50 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 72ba474b4..a2dc7075d 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -17,7 +17,6 @@ import { | |||
17 | Table, | 17 | Table, |
18 | UpdatedAt | 18 | UpdatedAt |
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { setAsUpdated } from '@server/helpers/database-utils' | ||
21 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' | 20 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' |
22 | import { MAccountId, MChannelId } from '@server/types/models' | 21 | import { MAccountId, MChannelId } from '@server/types/models' |
23 | import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils' | 22 | import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath } from '@shared/core-utils' |
@@ -53,6 +52,7 @@ import { | |||
53 | } from '../../types/models/video/video-playlist' | 52 | } from '../../types/models/video/video-playlist' |
54 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' | 53 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' |
55 | import { ActorModel } from '../actor/actor' | 54 | import { ActorModel } from '../actor/actor' |
55 | import { setAsUpdated } from '../shared' | ||
56 | import { | 56 | import { |
57 | buildServerIdsFollowedBy, | 57 | buildServerIdsFollowedBy, |
58 | buildTrigramSearchIndex, | 58 | buildTrigramSearchIndex, |
@@ -82,6 +82,7 @@ type AvailableForListOptions = { | |||
82 | videoChannelId?: number | 82 | videoChannelId?: number |
83 | listMyPlaylists?: boolean | 83 | listMyPlaylists?: boolean |
84 | search?: string | 84 | search?: string |
85 | host?: string | ||
85 | withVideos?: boolean | 86 | withVideos?: boolean |
86 | } | 87 | } |
87 | 88 | ||
@@ -141,9 +142,19 @@ function getVideoLengthSelect () { | |||
141 | ] | 142 | ] |
142 | }, | 143 | }, |
143 | [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => { | 144 | [ScopeNames.AVAILABLE_FOR_LIST]: (options: AvailableForListOptions) => { |
145 | const whereAnd: WhereOptions[] = [] | ||
146 | |||
147 | const whereServer = options.host && options.host !== WEBSERVER.HOST | ||
148 | ? { host: options.host } | ||
149 | : undefined | ||
150 | |||
144 | let whereActor: WhereOptions = {} | 151 | let whereActor: WhereOptions = {} |
145 | 152 | ||
146 | const whereAnd: WhereOptions[] = [] | 153 | if (options.host === WEBSERVER.HOST) { |
154 | whereActor = { | ||
155 | [Op.and]: [ { serverId: null } ] | ||
156 | } | ||
157 | } | ||
147 | 158 | ||
148 | if (options.listMyPlaylists !== true) { | 159 | if (options.listMyPlaylists !== true) { |
149 | whereAnd.push({ | 160 | whereAnd.push({ |
@@ -168,9 +179,7 @@ function getVideoLengthSelect () { | |||
168 | }) | 179 | }) |
169 | } | 180 | } |
170 | 181 | ||
171 | whereActor = { | 182 | Object.assign(whereActor, { [Op.or]: whereActorOr }) |
172 | [Op.or]: whereActorOr | ||
173 | } | ||
174 | } | 183 | } |
175 | 184 | ||
176 | if (options.accountId) { | 185 | if (options.accountId) { |
@@ -228,7 +237,7 @@ function getVideoLengthSelect () { | |||
228 | include: [ | 237 | include: [ |
229 | { | 238 | { |
230 | model: AccountModel.scope({ | 239 | model: AccountModel.scope({ |
231 | method: [ AccountScopeNames.SUMMARY, { whereActor } as SummaryOptions ] | 240 | method: [ AccountScopeNames.SUMMARY, { whereActor, whereServer } as SummaryOptions ] |
232 | }), | 241 | }), |
233 | required: true | 242 | required: true |
234 | }, | 243 | }, |
@@ -349,6 +358,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
349 | videoChannelId?: number | 358 | videoChannelId?: number |
350 | listMyPlaylists?: boolean | 359 | listMyPlaylists?: boolean |
351 | search?: string | 360 | search?: string |
361 | host?: string | ||
352 | withVideos?: boolean // false by default | 362 | withVideos?: boolean // false by default |
353 | }) { | 363 | }) { |
354 | const query = { | 364 | const query = { |
@@ -368,6 +378,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
368 | videoChannelId: options.videoChannelId, | 378 | videoChannelId: options.videoChannelId, |
369 | listMyPlaylists: options.listMyPlaylists, | 379 | listMyPlaylists: options.listMyPlaylists, |
370 | search: options.search, | 380 | search: options.search, |
381 | host: options.host, | ||
371 | withVideos: options.withVideos || false | 382 | withVideos: options.withVideos || false |
372 | } as AvailableForListOptions | 383 | } as AvailableForListOptions |
373 | ] | 384 | ] |
@@ -390,6 +401,7 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
390 | count: number | 401 | count: number |
391 | sort: string | 402 | sort: string |
392 | search?: string | 403 | search?: string |
404 | host?: string | ||
393 | }) { | 405 | }) { |
394 | return VideoPlaylistModel.listForApi({ | 406 | return VideoPlaylistModel.listForApi({ |
395 | ...options, | 407 | ...options, |
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index b15d20cf9..d591a3134 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -2,7 +2,6 @@ import * as memoizee from 'memoizee' | |||
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { Op } from 'sequelize' | 3 | import { Op } from 'sequelize' |
4 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 4 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
5 | import { doesExist } from '@server/helpers/database-utils' | ||
6 | import { VideoFileModel } from '@server/models/video/video-file' | 5 | import { VideoFileModel } from '@server/models/video/video-file' |
7 | import { MStreamingPlaylist, MVideo } from '@server/types/models' | 6 | import { MStreamingPlaylist, MVideo } from '@server/types/models' |
8 | import { AttributesOnly } from '@shared/core-utils' | 7 | import { AttributesOnly } from '@shared/core-utils' |
@@ -20,6 +19,7 @@ import { | |||
20 | WEBSERVER | 19 | WEBSERVER |
21 | } from '../../initializers/constants' | 20 | } from '../../initializers/constants' |
22 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 21 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
22 | import { doesExist } from '../shared' | ||
23 | import { throwIfNotValid } from '../utils' | 23 | import { throwIfNotValid } from '../utils' |
24 | import { VideoModel } from './video' | 24 | import { VideoModel } from './video' |
25 | 25 | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index c006a91af..c444f381e 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -24,7 +24,6 @@ import { | |||
24 | Table, | 24 | Table, |
25 | UpdatedAt | 25 | UpdatedAt |
26 | } from 'sequelize-typescript' | 26 | } from 'sequelize-typescript' |
27 | import { setAsUpdated } from '@server/helpers/database-utils' | ||
28 | import { buildNSFWFilter } from '@server/helpers/express-utils' | 27 | import { buildNSFWFilter } from '@server/helpers/express-utils' |
29 | import { uuidToShort } from '@server/helpers/uuid' | 28 | import { uuidToShort } from '@server/helpers/uuid' |
30 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' | 29 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' |
@@ -92,6 +91,7 @@ import { VideoRedundancyModel } from '../redundancy/video-redundancy' | |||
92 | import { ServerModel } from '../server/server' | 91 | import { ServerModel } from '../server/server' |
93 | import { TrackerModel } from '../server/tracker' | 92 | import { TrackerModel } from '../server/tracker' |
94 | import { VideoTrackerModel } from '../server/video-tracker' | 93 | import { VideoTrackerModel } from '../server/video-tracker' |
94 | import { setAsUpdated } from '../shared' | ||
95 | import { UserModel } from '../user/user' | 95 | import { UserModel } from '../user/user' |
96 | import { UserVideoHistoryModel } from '../user/user-video-history' | 96 | import { UserVideoHistoryModel } from '../user/user-video-history' |
97 | import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' | 97 | import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' |