import { sample } from 'lodash'
-import { FindOptions, literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
+import { literal, Op, QueryTypes, Transaction, WhereOptions } from 'sequelize'
import {
AllowNull,
BeforeDestroy,
} 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 {
+ CacheFileObject,
FileRedundancyInformation,
StreamingPlaylistRedundancyInformation,
- VideoRedundancy
-} from '@shared/models/redundancy/video-redundancy.model'
-import { CacheFileObject, VideoPrivacy } from '../../../shared'
-import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy'
+ VideoPrivacy,
+ VideoRedundanciesTarget,
+ VideoRedundancy,
+ VideoRedundancyStrategy,
+ VideoRedundancyStrategyWithManual
+} from '@shared/models'
+import { AttributesOnly } from '@shared/typescript-utils'
import { isTestInstance } from '../../helpers/core-utils'
import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { logger } from '../../helpers/logger'
{
fields: [ 'actorId' ]
},
+ {
+ fields: [ 'expiresOn' ]
+ },
{
fields: [ 'url' ],
unique: true
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) {
return VideoRedundancyModel.scope([ ScopeNames.WITH_VIDEO ]).findOne(query)
}
- static async getTotalDuplicated (strategy: VideoRedundancyStrategy) {
- const actor = await getServerActor()
- const redundancyInclude = {
- attributes: [],
- model: VideoRedundancyModel,
- required: true,
- where: {
- actorId: actor.id,
- strategy
- }
- }
-
- const queryFiles: FindOptions = {
- include: [ redundancyInclude ]
- }
-
- const queryStreamingPlaylists: FindOptions = {
- include: [
- {
- attributes: [],
- model: VideoModel.unscoped(),
- required: true,
- include: [
- {
- required: true,
- attributes: [],
- model: VideoStreamingPlaylistModel.unscoped(),
- include: [
- redundancyInclude
- ]
- }
- ]
- }
- ]
- }
-
- return Promise.all([
- VideoFileModel.aggregate('size', 'SUM', queryFiles),
- VideoFileModel.aggregate('size', 'SUM', queryStreamingPlaylists)
- ]).then(([ r1, r2 ]) => {
- return parseAggregateResult(r1) + parseAggregateResult(r2)
- })
- }
-
- static async listLocalExpired () {
+ static async listLocalExpired (): Promise<MVideoRedundancyVideo[]> {
const actor = await getServerActor()
const query = {
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() ]
}
return undefined
}
+ getVideoUUID () {
+ const video = this.getVideo()
+ if (!video) return undefined
+
+ return video.uuid
+ }
+
isOwned () {
return !!this.strategy
}