X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fredundancy%2Fvideo-redundancy.ts;h=e8d79a3ab23dc218a5795751a22c76cdb72ee5eb;hb=842a15732b5ddcd9c9c90e790a448235800ef870;hp=a61c3578c97311e30a553485fbef2a1f4e4c6550;hpb=53e7f82fe394eff220e1b76aa4d2b6018ed26267;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index a61c3578c..e8d79a3ab 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts @@ -1,5 +1,5 @@ import { sample } from 'lodash' -import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' +import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize' import { AllowNull, BeforeDestroy, @@ -16,6 +16,7 @@ import { } from 'sequelize-typescript' import { getServerActor } from '@server/models/application/application' import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' +import { AttributesOnly } from '@shared/core-utils' import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' import { FileRedundancyInformation, @@ -29,7 +30,7 @@ import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validato import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers/constants' -import { ActorModel } from '../activitypub/actor' +import { ActorModel } from '../actor/actor' import { ServerModel } from '../server/server' import { getSort, getVideoSort, parseAggregateResult, throwIfNotValid } from '../utils' import { ScheduleVideoUpdateModel } from '../video/schedule-video-update' @@ -78,13 +79,16 @@ export enum ScopeNames { { fields: [ 'actorId' ] }, + { + fields: [ 'expiresOn' ] + }, { fields: [ 'url' ], unique: true } ] }) -export class VideoRedundancyModel extends Model { +export class VideoRedundancyModel extends Model>> { @CreatedAt createdAt: Date @@ -156,8 +160,8 @@ export class VideoRedundancyModel extends Model { const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` logger.info('Removing duplicated video file %s.', logIdentifier) - videoFile.Video.removeFile(videoFile, true) - .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) + videoFile.Video.removeWebTorrentFileAndTorrent(videoFile, true) + .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) } if (instance.videoStreamingPlaylistId) { @@ -407,7 +411,7 @@ export class VideoRedundancyModel extends Model { return VideoRedundancyModel.scope([ ScopeNames.WITH_VIDEO ]).findOne(query) } - static async listLocalExpired () { + static async listLocalExpired (): Promise { const actor = await getServerActor() const query = { @@ -466,16 +470,34 @@ export class VideoRedundancyModel extends Model { const query = { where: { - actorId: actor.id + [Op.and]: [ + { + actorId: actor.id + }, + { + [Op.or]: [ + { + '$VideoStreamingPlaylist.id$': { + [Op.ne]: null + } + }, + { + '$VideoFile.id$': { + [Op.ne]: null + } + } + ] + } + ] }, include: [ { - model: VideoFileModel, + model: VideoFileModel.unscoped(), required: false, include: [ buildVideoInclude() ] }, { - model: VideoStreamingPlaylistModel, + model: VideoStreamingPlaylistModel.unscoped(), required: false, include: [ buildVideoInclude() ] } @@ -679,6 +701,13 @@ export class VideoRedundancyModel extends Model { return undefined } + getVideoUUID () { + const video = this.getVideo() + if (!video) return undefined + + return video.uuid + } + isOwned () { return !!this.strategy }