} from '../../helpers/custom-validators/videos'
import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
import { logger } from '../../helpers/logger'
-import { getServerActor } from '../../helpers/utils'
import {
ACTIVITY_PUB,
API_VERSION,
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
import { ModelCache } from '@server/models/model-cache'
import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder'
+import { buildNSFWFilter } from '@server/helpers/express-utils'
+import { getServerActor } from '@server/models/application/application'
export enum ScopeNames {
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
@HasMany(() => VideoAbuseModel, {
foreignKey: {
name: 'videoId',
- allowNull: false
+ allowNull: true
},
- onDelete: 'cascade'
+ onDelete: 'set null'
})
VideoAbuses: VideoAbuseModel[]
ModelCache.Instance.invalidateCache('video', instance.id)
}
+ @BeforeDestroy
+ static async saveEssentialDataToAbuses (instance: VideoModel, options) {
+ const tasks: Promise<any>[] = []
+
+ logger.info('Saving video abuses details of video %s.', instance.url)
+
+ if (!Array.isArray(instance.VideoAbuses)) {
+ instance.VideoAbuses = await instance.$get('VideoAbuses')
+
+ if (instance.VideoAbuses.length === 0) return undefined
+ }
+
+ const details = instance.toFormattedDetailsJSON()
+
+ for (const abuse of instance.VideoAbuses) {
+ abuse.deletedVideo = details
+ tasks.push(abuse.save({ transaction: options.transaction }))
+ }
+
+ Promise.all(tasks)
+ .catch(err => {
+ logger.error('Some errors when saving details of video %s in its abuses before destroy hook.', instance.uuid, { err })
+ })
+
+ return undefined
+ }
+
static listLocal (): Bluebird<MVideoWithAllFiles[]> {
const query = {
where: {
remote: false
}
})
- const totalVideos = await VideoModel.count()
let totalLocalVideoViews = await VideoModel.sum('views', {
where: {
remote: false
}
})
+
// Sequelize could return null...
if (!totalLocalVideoViews) totalLocalVideoViews = 0
+ const { total: totalVideos } = await VideoModel.listForApi({
+ start: 0,
+ count: 0,
+ sort: '-publishedAt',
+ nsfw: buildNSFWFilter(),
+ includeLocalVideos: true,
+ withFiles: false
+ })
+
return {
totalLocalVideos,
totalLocalVideoViews,
}
function getModels () {
+ if (options.count === 0) return Promise.resolve([])
+
const { query, replacements, order } = buildListQuery(VideoModel, options)
const queryModels = wrapForAPIResults(query, replacements, options, order)
getVideoFileMetadataUrl (videoFile: MVideoFile, baseUrlHttp: string) {
const path = '/api/v1/videos/'
- return videoFile.metadata
+
+ return this.isOwned()
? baseUrlHttp + path + this.uuid + '/metadata/' + videoFile.id
: videoFile.metadataUrl
}