import { remove } from 'fs-extra'
import { maxBy, minBy, pick } from 'lodash'
import { join } from 'path'
-import { FindOptions, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
+import { FindOptions, Includeable, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
import {
AllowNull,
BeforeDestroy,
UpdatedAt
} from 'sequelize-typescript'
import { buildNSFWFilter } from '@server/helpers/express-utils'
-import { getPrivaciesForFederation, isPrivacyForFederation } from '@server/helpers/video'
+import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
import { LiveManager } from '@server/lib/live-manager'
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
import { getServerActor } from '@server/models/application/application'
isVideoStateValid,
isVideoSupportValid
} from '../../helpers/custom-validators/videos'
-import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
+import { getVideoFileResolution } from '../../helpers/ffprobe-utils'
import { logger } from '../../helpers/logger'
import { CONFIG } from '../../initializers/config'
import {
attributes: [ 'id', 'url', 'uuid', 'remote' ]
},
[ScopeNames.FOR_API]: (options: ForAPIOptions) => {
- const query: FindOptions = {
- include: [
- {
- model: VideoChannelModel.scope({
- method: [
- VideoChannelScopeNames.SUMMARY, {
- withAccount: true,
- withAccountBlockerIds: options.withAccountBlockerIds
- } as SummaryOptions
- ]
- }),
- required: true
- },
- {
- attributes: [ 'type', 'filename' ],
- model: ThumbnailModel,
- required: false
- }
- ]
- }
+ const include: Includeable[] = [
+ {
+ model: VideoChannelModel.scope({
+ method: [
+ VideoChannelScopeNames.SUMMARY, {
+ withAccount: true,
+ withAccountBlockerIds: options.withAccountBlockerIds
+ } as SummaryOptions
+ ]
+ }),
+ required: true
+ },
+ {
+ attributes: [ 'type', 'filename' ],
+ model: ThumbnailModel,
+ required: false
+ }
+ ]
+
+ const query: FindOptions = {}
if (options.ids) {
query.where = {
}
if (options.withFiles === true) {
- query.include.push({
+ include.push({
model: VideoFileModel,
required: true
})
}
if (options.videoPlaylistId) {
- query.include.push({
+ include.push({
model: VideoPlaylistElementModel.unscoped(),
required: true,
where: {
})
}
+ query.include = include
+
return query
},
[ScopeNames.WITH_THUMBNAILS]: {
}
]
})
-export class VideoModel extends Model<VideoModel> {
+export class VideoModel extends Model {
@AllowNull(false)
@Default(DataType.UUIDV4)
static stopLiveIfNeeded (instance: VideoModel) {
if (!instance.isLive) return
+ logger.info('Stopping live of video %s after video deletion.', instance.uuid)
+
return LiveManager.Instance.stopSessionOf(instance.id)
}
return undefined
}
- static listLocal (): Bluebird<MVideoWithAllFiles[]> {
+ static listLocal (): Promise<MVideoWithAllFiles[]> {
const query = {
where: {
remote: false
}
]
},
- VideoLiveModel,
+ VideoLiveModel.unscoped(),
VideoFileModel,
TagModel
]
})
}
+ static async listPublishedLiveIds () {
+ const options = {
+ attributes: [ 'id' ],
+ where: {
+ isLive: true,
+ state: VideoState.PUBLISHED
+ }
+ }
+
+ const result = await VideoModel.findAll(options)
+
+ return result.map(v => v.id)
+ }
+
static listUserVideosForApi (
accountId: number,
start: number,
user?: MUserAccountId
historyOfUser?: MUserId
countVideos?: boolean
+ search?: string
}) {
- if (options.filter && options.filter === 'all-local' && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
+ if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
throw new Error('Try to filter all-local but no user has not the see all videos right')
}
includeLocalVideos: options.includeLocalVideos,
user: options.user,
historyOfUser: options.historyOfUser,
- trendingDays
+ trendingDays,
+ search: options.search
}
return VideoModel.getAvailableForApi(queryOptions, options.countVideos)
const options = {
where: {
remote: false,
- isLive: true
+ isLive: true,
+ state: {
+ [Op.ne]: VideoState.LIVE_ENDED
+ }
}
}
const options = {
where: {
remote: false,
- isLive: true
+ isLive: true,
+ state: {
+ [Op.ne]: VideoState.LIVE_ENDED
+ }
},
include: [
{
return VideoModel.count(options)
}
- static load (id: number | string, t?: Transaction): Bluebird<MVideoThumbnail> {
+ static load (id: number | string, t?: Transaction): Promise<MVideoThumbnail> {
const where = buildWhereIdOrUUID(id)
const options = {
where,
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
}
- static loadWithBlacklist (id: number | string, t?: Transaction): Bluebird<MVideoThumbnailBlacklist> {
+ static loadWithBlacklist (id: number | string, t?: Transaction): Promise<MVideoThumbnailBlacklist> {
const where = buildWhereIdOrUUID(id)
const options = {
where,
]).findOne(options)
}
- static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> {
+ static loadImmutableAttributes (id: number | string, t?: Transaction): Promise<MVideoImmutable> {
const fun = () => {
const query = {
where: buildWhereIdOrUUID(id),
})
}
- static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> {
+ static loadWithRights (id: number | string, t?: Transaction): Promise<MVideoWithRights> {
const where = buildWhereIdOrUUID(id)
const options = {
where,
]).findOne(options)
}
- static loadOnlyId (id: number | string, t?: Transaction): Bluebird<MVideoIdThumbnail> {
+ static loadOnlyId (id: number | string, t?: Transaction): Promise<MVideoIdThumbnail> {
const where = buildWhereIdOrUUID(id)
const options = {
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
}
- static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Bluebird<MVideoWithAllFiles> {
+ static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean): Promise<MVideoWithAllFiles> {
const where = buildWhereIdOrUUID(id)
const query = {
]).findOne(query)
}
- static loadByUUID (uuid: string): Bluebird<MVideoThumbnail> {
+ static loadByUUID (uuid: string): Promise<MVideoThumbnail> {
const options = {
where: {
uuid
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
}
- static loadByUrl (url: string, transaction?: Transaction): Bluebird<MVideoThumbnail> {
+ static loadByUrl (url: string, transaction?: Transaction): Promise<MVideoThumbnail> {
const query: FindOptions = {
where: {
url
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query)
}
- static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> {
+ static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Promise<MVideoImmutable> {
const fun = () => {
const query: FindOptions = {
where: {
})
}
- static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> {
+ static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Promise<MVideoAccountLightBlacklistAllFiles> {
const query: FindOptions = {
where: {
url
]).findOne(query)
}
- static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Bluebird<MVideoFullLight> {
+ static loadAndPopulateAccountAndServerAndTags (id: number | string, t?: Transaction, userId?: number): Promise<MVideoFullLight> {
const where = buildWhereIdOrUUID(id)
const options = {
id: number | string
t?: Transaction
userId?: number
- }): Bluebird<MVideoDetails> {
+ }): Promise<MVideoDetails> {
const { id, t, userId } = parameters
const where = buildWhereIdOrUUID(id)
return VideoModel.update({ support: videoChannel.support }, options)
}
- static getAllIdsFromChannel (videoChannel: MChannelId): Bluebird<number[]> {
+ static getAllIdsFromChannel (videoChannel: MChannelId): Promise<number[]> {
const query = {
attributes: [ 'id' ],
where: {
'likes',
'dislikes',
'remote',
+ 'isLive',
'url',
'commentsEnabled',
'downloadEnabled',
videoFilesDone.add(row.VideoFiles.id)
}
- if (row.VideoFiles?.id && !videoFilesDone.has(row.VideoFiles.id)) {
- const videoFileModel = new VideoFileModel(pick(row.VideoFiles, videoFileKeys))
- videoModel.VideoFiles.push(videoFileModel)
-
- videoFilesDone.add(row.VideoFiles.id)
- }
-
if (row.VideoStreamingPlaylists?.id && !videoStreamingPlaylistMemo[row.VideoStreamingPlaylists.id]) {
const streamingPlaylist = new VideoStreamingPlaylistModel(pick(row.VideoStreamingPlaylists, videoStreamingPlaylistKeys))
streamingPlaylist.VideoFiles = []
return isPrivacyForFederation(this.privacy)
}
+ hasStateForFederation () {
+ return isStateForFederation(this.state)
+ }
+
isNewVideo (newPrivacy: VideoPrivacy) {
return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true
}