import { UserModel } from '../user/user'
import { UserVideoHistoryModel } from '../user/user-video-history'
import { buildTrigramSearchIndex, buildWhereIdOrUUID, getVideoSort, isOutdated, throwIfNotValid } from '../utils'
+import { VideoViewModel } from '../view/video-view'
import {
videoFilesModelToFormattedJSON,
VideoFormattingJSONOptions,
import { VideoShareModel } from './video-share'
import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
import { VideoTagModel } from './video-tag'
-import { VideoViewModel } from './video-view'
export enum ScopeNames {
FOR_API = 'FOR_API',
logger.info('Stopping live of video %s after video deletion.', instance.uuid)
- LiveManager.Instance.stopSessionOf(instance.id)
+ LiveManager.Instance.stopSessionOf(instance.id, null)
}
@BeforeDestroy
}) {
const { accountId, channelId, start, count, sort, search, isLive } = options
- function buildBaseQuery (): FindOptions {
+ function buildBaseQuery (forCount: boolean): FindOptions {
const where: WhereOptions = {}
if (search) {
where: channelWhere,
include: [
{
- model: AccountModel,
+ model: forCount
+ ? AccountModel.unscoped()
+ : AccountModel,
where: {
id: accountId
},
return baseQuery
}
- const countQuery = buildBaseQuery()
- const findQuery = buildBaseQuery()
+ const countQuery = buildBaseQuery(true)
+ const findQuery = buildBaseQuery(false)
const findScopes: (string | ScopeOptions)[] = [
ScopeNames.WITH_SCHEDULED_UPDATE,
})
}
- static updateRatesOf (videoId: number, type: VideoRateType, t: Transaction) {
+ static updateRatesOf (videoId: number, type: VideoRateType, count: number, t: Transaction) {
+ const field = type === 'like'
+ ? 'likes'
+ : 'dislikes'
+
+ const rawQuery = `UPDATE "video" SET "${field}" = :count WHERE "video"."id" = :videoId`
+
+ return AccountVideoRateModel.sequelize.query(rawQuery, {
+ transaction: t,
+ replacements: { videoId, rateType: type, count },
+ type: QueryTypes.UPDATE
+ })
+ }
+
+ static syncLocalRates (videoId: number, type: VideoRateType, t: Transaction) {
const field = type === 'like'
? 'likes'
: 'dislikes'
return peertubeTruncate(this.description, { length: maxLength })
}
+ getAllFiles () {
+ let files: MVideoFile[] = []
+
+ if (Array.isArray(this.VideoFiles)) {
+ files = files.concat(this.VideoFiles)
+ }
+
+ if (Array.isArray(this.VideoStreamingPlaylists)) {
+ for (const p of this.VideoStreamingPlaylists) {
+ if (Array.isArray(p.VideoFiles)) {
+ files = files.concat(p.VideoFiles)
+ }
+ }
+ }
+
+ return files
+ }
+
probeMaxQualityFile () {
const file = this.getMaxQualityFile()
const videoOrPlaylist = file.getVideoOrStreamingPlaylist()