import { getServerActor } from '@server/models/application/application'
import { ModelCache } from '@server/models/model-cache'
import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils'
-import { VideoInclude } from '@shared/models'
-import { VideoFile } from '@shared/models/videos/video-file.model'
+import { VideoFile, VideoInclude } from '@shared/models'
import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
import { VideoObject } from '../../../shared/models/activitypub/objects'
import { Video, VideoDetails, VideoRateType, VideoStorage } from '../../../shared/models/videos'
// Remove physical files and torrents
instance.VideoFiles.forEach(file => {
- tasks.push(instance.removeFileAndTorrent(file))
+ tasks.push(instance.removeWebTorrentFileAndTorrent(file))
})
// Remove playlists file
await Promise.all(tasks)
}
- static listLocal (): Promise<MVideo[]> {
+ static listLocalIds (): Promise<number[]> {
const query = {
+ attributes: [ 'id' ],
+ raw: true,
where: {
remote: false
}
}
return VideoModel.findAll(query)
+ .then(rows => rows.map(r => r.id))
}
static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
languageOneOf?: string[]
tagsOneOf?: string[]
tagsAllOf?: string[]
+ privacyOneOf?: VideoPrivacy[]
accountId?: number
videoChannelId?: number
search?: string
}) {
VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user)
+ VideoModel.throwIfPrivacyOneOfWithoutUser(options.privacyOneOf, options.user)
const trendingDays = options.sort.endsWith('trending')
? CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS
'languageOneOf',
'tagsOneOf',
'tagsAllOf',
+ 'privacyOneOf',
'isLocal',
'include',
'displayOnlyForFollower',
languageOneOf?: string[]
tagsOneOf?: string[]
tagsAllOf?: string[]
+ privacyOneOf?: VideoPrivacy[]
displayOnlyForFollower: DisplayOnlyForFollowerOptions | null
uuids?: string[]
}) {
VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user)
+ VideoModel.throwIfPrivacyOneOfWithoutUser(options.privacyOneOf, options.user)
const serverActor = await getServerActor()
'languageOneOf',
'tagsOneOf',
'tagsAllOf',
+ 'privacyOneOf',
'user',
'isLocal',
'host',
private static throwIfPrivateIncludeWithoutUser (include: VideoInclude, user: MUserAccountId) {
if (VideoModel.isPrivateInclude(include) && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) {
- throw new Error('Try to filter all-local but no user has not the see all videos right')
+ throw new Error('Try to filter all-local but user cannot see all videos')
+ }
+ }
+
+ private static throwIfPrivacyOneOfWithoutUser (privacyOneOf: VideoPrivacy[], user: MUserAccountId) {
+ if (privacyOneOf && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) {
+ throw new Error('Try to choose video privacies but user cannot see all videos')
}
}
private static isPrivateInclude (include: VideoInclude) {
return include & VideoInclude.BLACKLISTED ||
include & VideoInclude.BLOCKED_OWNER ||
- include & VideoInclude.HIDDEN_PRIVACY ||
include & VideoInclude.NOT_PUBLISHED_STATE
}
if (Array.isArray(this.Thumbnails) === false) this.Thumbnails = []
- // Already have this thumbnail, skip
- if (this.Thumbnails.find(t => t.id === savedThumbnail.id)) return
-
+ this.Thumbnails = this.Thumbnails.filter(t => t.id !== savedThumbnail.id)
this.Thumbnails.push(savedThumbnail)
}
const file = this.getMaxQualityFile()
const videoOrPlaylist = file.getVideoOrStreamingPlaylist()
- return VideoPathManager.Instance.makeAvailableVideoFile(videoOrPlaylist, file, originalFilePath => {
+ return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), originalFilePath => {
return getVideoFileResolution(originalFilePath)
})
}
if (!this.VideoStreamingPlaylists) return undefined
const playlist = this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
+ if (!playlist) return undefined
+
playlist.Video = this
return playlist
.concat(toAdd)
}
- removeFileAndTorrent (videoFile: MVideoFile, isRedundancy = false) {
+ removeWebTorrentFileAndTorrent (videoFile: MVideoFile, isRedundancy = false) {
const filePath = isRedundancy
? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile)
: VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile)
)
if (streamingPlaylist.storage === VideoStorage.OBJECT_STORAGE) {
- await removeHLSObjectStorage(streamingPlaylist, this)
+ await removeHLSObjectStorage(streamingPlaylist.withVideo(this))
}
}
}
return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true
}
- setAsRefreshed () {
- return setAsUpdated('video', this.id)
+ setAsRefreshed (transaction?: Transaction) {
+ return setAsUpdated('video', this.id, transaction)
}
requiresAuth () {
await this.save({ transaction })
}
- getBandwidthBits (videoFile: MVideoFile) {
+ getBandwidthBits (this: MVideo, videoFile: MVideoFile) {
return Math.ceil((videoFile.size * 8) / this.duration)
}