X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=e6a8d3f9550475a3f7a13aa249eeca31194658b0;hb=e771ff815dba3b4a95633f4e1e10dacd222dfe61;hp=a4093ce3ba9aba83f2cf0f0d3b0c23be6644b99e;hpb=28dca0a2211524bbf3ad17666c607eb6325763b8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a4093ce3b..e6a8d3f95 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -106,6 +106,7 @@ import { setAsUpdated } from '../shared' 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, @@ -135,7 +136,6 @@ import { VideoPlaylistElementModel } from './video-playlist-element' 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', @@ -787,7 +787,7 @@ export class VideoModel extends Model>> { logger.info('Stopping live of video %s after video deletion.', instance.uuid) - LiveManager.Instance.stopSessionOf(instance.id) + LiveManager.Instance.stopSessionOf(instance.id, null) } @BeforeDestroy @@ -972,7 +972,7 @@ export class VideoModel extends Model>> { }) { const { accountId, channelId, start, count, sort, search, isLive } = options - function buildBaseQuery (): FindOptions { + function buildBaseQuery (forCount: boolean): FindOptions { const where: WhereOptions = {} if (search) { @@ -1001,7 +1001,9 @@ export class VideoModel extends Model>> { where: channelWhere, include: [ { - model: AccountModel, + model: forCount + ? AccountModel.unscoped() + : AccountModel, where: { id: accountId }, @@ -1015,8 +1017,8 @@ export class VideoModel extends Model>> { return baseQuery } - const countQuery = buildBaseQuery() - const findQuery = buildBaseQuery() + const countQuery = buildBaseQuery(true) + const findQuery = buildBaseQuery(false) const findScopes: (string | ScopeOptions)[] = [ ScopeNames.WITH_SCHEDULED_UPDATE, @@ -1402,7 +1404,21 @@ export class VideoModel extends Model>> { }) } - 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' @@ -1683,6 +1699,24 @@ export class VideoModel extends Model>> { 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()