aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts25
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'
27import { setAsUpdated } from '@server/helpers/database-utils'
27import { buildNSFWFilter } from '@server/helpers/express-utils' 28import { buildNSFWFilter } from '@server/helpers/express-utils'
28import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' 29import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
29import { LiveManager } from '@server/lib/live-manager' 30import { LiveManager } from '@server/lib/live-manager'
30import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' 31import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
31import { getServerActor } from '@server/models/application/application' 32import { getServerActor } from '@server/models/application/application'
32import { ModelCache } from '@server/models/model-cache' 33import { ModelCache } from '@server/models/model-cache'
34import { AttributesOnly } from '@shared/core-utils'
33import { VideoFile } from '@shared/models/videos/video-file.model' 35import { VideoFile } from '@shared/models/videos/video-file.model'
34import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' 36import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
35import { VideoObject } from '../../../shared/models/activitypub/objects' 37import { VideoObject } from '../../../shared/models/activitypub/objects'
@@ -99,14 +101,14 @@ import { MVideoFile, MVideoFileStreamingPlaylistVideo } from '../../types/models
99import { VideoAbuseModel } from '../abuse/video-abuse' 101import { VideoAbuseModel } from '../abuse/video-abuse'
100import { AccountModel } from '../account/account' 102import { AccountModel } from '../account/account'
101import { AccountVideoRateModel } from '../account/account-video-rate' 103import { AccountVideoRateModel } from '../account/account-video-rate'
102import { ActorImageModel } from '../account/actor-image' 104import { ActorModel } from '../actor/actor'
103import { UserModel } from '../account/user' 105import { ActorImageModel } from '../actor/actor-image'
104import { UserVideoHistoryModel } from '../account/user-video-history'
105import { ActorModel } from '../activitypub/actor'
106import { VideoRedundancyModel } from '../redundancy/video-redundancy' 106import { VideoRedundancyModel } from '../redundancy/video-redundancy'
107import { ServerModel } from '../server/server' 107import { ServerModel } from '../server/server'
108import { TrackerModel } from '../server/tracker' 108import { TrackerModel } from '../server/tracker'
109import { VideoTrackerModel } from '../server/video-tracker' 109import { VideoTrackerModel } from '../server/video-tracker'
110import { UserModel } from '../user/user'
111import { UserVideoHistoryModel } from '../user/user-video-history'
110import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils' 112import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils'
111import { ScheduleVideoUpdateModel } from './schedule-video-update' 113import { ScheduleVideoUpdateModel } from './schedule-video-update'
112import { TagModel } from './tag' 114import { TagModel } from './tag'
@@ -488,7 +490,7 @@ export type AvailableForListIDsOptions = {
488 } 490 }
489 ] 491 ]
490}) 492})
491export class VideoModel extends Model { 493export 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 () {