diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index e55a21a6b..d4a258187 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -24,12 +24,14 @@ 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' | ||
27 | import { buildNSFWFilter } from '@server/helpers/express-utils' | 28 | import { buildNSFWFilter } from '@server/helpers/express-utils' |
28 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' | 29 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' |
29 | import { LiveManager } from '@server/lib/live-manager' | 30 | import { LiveManager } from '@server/lib/live-manager' |
30 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' | 31 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' |
31 | import { getServerActor } from '@server/models/application/application' | 32 | import { getServerActor } from '@server/models/application/application' |
32 | import { ModelCache } from '@server/models/model-cache' | 33 | import { ModelCache } from '@server/models/model-cache' |
34 | import { AttributesOnly } from '@shared/core-utils' | ||
33 | import { VideoFile } from '@shared/models/videos/video-file.model' | 35 | import { VideoFile } from '@shared/models/videos/video-file.model' |
34 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' | 36 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' |
35 | import { VideoObject } from '../../../shared/models/activitypub/objects' | 37 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
@@ -99,14 +101,14 @@ import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models | |||
99 | import { VideoAbuseModel } from '../abuse/video-abuse' | 101 | import { VideoAbuseModel } from '../abuse/video-abuse' |
100 | import { AccountModel } from '../account/account' | 102 | import { AccountModel } from '../account/account' |
101 | import { AccountVideoRateModel } from '../account/account-video-rate' | 103 | import { AccountVideoRateModel } from '../account/account-video-rate' |
102 | import { ActorImageModel } from '../account/actor-image' | 104 | import { ActorModel } from '../actor/actor' |
103 | import { UserModel } from '../account/user' | 105 | import { ActorImageModel } from '../actor/actor-image' |
104 | import { UserVideoHistoryModel } from '../account/user-video-history' | ||
105 | import { ActorModel } from '../activitypub/actor' | ||
106 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 106 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
107 | import { ServerModel } from '../server/server' | 107 | import { ServerModel } from '../server/server' |
108 | import { TrackerModel } from '../server/tracker' | 108 | import { TrackerModel } from '../server/tracker' |
109 | import { VideoTrackerModel } from '../server/video-tracker' | 109 | import { VideoTrackerModel } from '../server/video-tracker' |
110 | import { UserModel } from '../user/user' | ||
111 | import { UserVideoHistoryModel } from '../user/user-video-history' | ||
110 | import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' | 112 | import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' |
111 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | 113 | import { ScheduleVideoUpdateModel } from './schedule-video-update' |
112 | import { TagModel } from './tag' | 114 | import { TagModel } from './tag' |
@@ -488,7 +490,7 @@ export type AvailableForListIDsOptions = { | |||
488 | } | 490 | } |
489 | ] | 491 | ] |
490 | }) | 492 | }) |
491 | export class VideoModel extends Model { | 493 | export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { |
492 | 494 | ||
493 | @AllowNull(false) | 495 | @AllowNull(false) |
494 | @Default(DataType.UUIDV4) | 496 | @Default(DataType.UUIDV4) |
@@ -1007,6 +1009,7 @@ export class VideoModel extends Model { | |||
1007 | attributes: [ 'id' ], | 1009 | attributes: [ 'id' ], |
1008 | where: { | 1010 | where: { |
1009 | isLive: true, | 1011 | isLive: true, |
1012 | remote: false, | ||
1010 | state: VideoState.PUBLISHED | 1013 | state: VideoState.PUBLISHED |
1011 | } | 1014 | } |
1012 | } | 1015 | } |
@@ -1616,7 +1619,7 @@ export class VideoModel extends Model { | |||
1616 | includeLocalVideos: true | 1619 | includeLocalVideos: true |
1617 | } | 1620 | } |
1618 | 1621 | ||
1619 | const { query, replacements } = buildListQuery(VideoModel, queryOptions) | 1622 | const { query, replacements } = buildListQuery(VideoModel.sequelize, queryOptions) |
1620 | 1623 | ||
1621 | return this.sequelize.query<any>(query, { replacements, type: QueryTypes.SELECT }) | 1624 | return this.sequelize.query<any>(query, { replacements, type: QueryTypes.SELECT }) |
1622 | .then(rows => rows.map(r => r[field])) | 1625 | .then(rows => rows.map(r => r[field])) |
@@ -1644,7 +1647,7 @@ export class VideoModel extends Model { | |||
1644 | if (countVideos !== true) return Promise.resolve(undefined) | 1647 | if (countVideos !== true) return Promise.resolve(undefined) |
1645 | 1648 | ||
1646 | const countOptions = Object.assign({}, options, { isCount: true }) | 1649 | const countOptions = Object.assign({}, options, { isCount: true }) |
1647 | const { query: queryCount, replacements: replacementsCount } = buildListQuery(VideoModel, countOptions) | 1650 | const { query: queryCount, replacements: replacementsCount } = buildListQuery(VideoModel.sequelize, countOptions) |
1648 | 1651 | ||
1649 | return VideoModel.sequelize.query<any>(queryCount, { replacements: replacementsCount, type: QueryTypes.SELECT }) | 1652 | return VideoModel.sequelize.query<any>(queryCount, { replacements: replacementsCount, type: QueryTypes.SELECT }) |
1650 | .then(rows => rows.length !== 0 ? rows[0].total : 0) | 1653 | .then(rows => rows.length !== 0 ? rows[0].total : 0) |
@@ -1653,7 +1656,7 @@ export class VideoModel extends Model { | |||
1653 | function getModels () { | 1656 | function getModels () { |
1654 | if (options.count === 0) return Promise.resolve([]) | 1657 | if (options.count === 0) return Promise.resolve([]) |
1655 | 1658 | ||
1656 | const { query, replacements, order } = buildListQuery(VideoModel, options) | 1659 | const { query, replacements, order } = buildListQuery(VideoModel.sequelize, options) |
1657 | const queryModels = wrapForAPIResults(query, replacements, options, order) | 1660 | const queryModels = wrapForAPIResults(query, replacements, options, order) |
1658 | 1661 | ||
1659 | return VideoModel.sequelize.query<any>(queryModels, { replacements, type: QueryTypes.SELECT, nest: true }) | 1662 | return VideoModel.sequelize.query<any>(queryModels, { replacements, type: QueryTypes.SELECT, nest: true }) |
@@ -2053,11 +2056,7 @@ export class VideoModel extends Model { | |||
2053 | } | 2056 | } |
2054 | 2057 | ||
2055 | setAsRefreshed () { | 2058 | setAsRefreshed () { |
2056 | const options = { | 2059 | return setAsUpdated('video', this.id) |
2057 | where: { id: this.id } | ||
2058 | } | ||
2059 | |||
2060 | return VideoModel.update({ updatedAt: new Date() }, options) | ||
2061 | } | 2060 | } |
2062 | 2061 | ||
2063 | requiresAuth () { | 2062 | requiresAuth () { |