aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts53
1 files changed, 41 insertions, 12 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index baa8c120a..8e3af62a4 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1,9 +1,11 @@
1import Bluebird from 'bluebird' 1import Bluebird from 'bluebird'
2import { remove } from 'fs-extra' 2import { remove } from 'fs-extra'
3import { maxBy, minBy } from 'lodash' 3import { maxBy, minBy } from 'lodash'
4import { join } from 'path'
5import { FindOptions, Includeable, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' 4import { FindOptions, Includeable, IncludeOptions, Op, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize'
6import { 5import {
6 AfterCreate,
7 AfterDestroy,
8 AfterUpdate,
7 AllowNull, 9 AllowNull,
8 BeforeDestroy, 10 BeforeDestroy,
9 BelongsTo, 11 BelongsTo,
@@ -25,6 +27,7 @@ import {
25 UpdatedAt 27 UpdatedAt
26} from 'sequelize-typescript' 28} from 'sequelize-typescript'
27import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' 29import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
30import { InternalEventEmitter } from '@server/lib/internal-event-emitter'
28import { LiveManager } from '@server/lib/live/live-manager' 31import { LiveManager } from '@server/lib/live/live-manager'
29import { removeHLSFileObjectStorageByFilename, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' 32import { removeHLSFileObjectStorageByFilename, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage'
30import { tracer } from '@server/lib/opentelemetry/tracing' 33import { tracer } from '@server/lib/opentelemetry/tracing'
@@ -66,7 +69,7 @@ import {
66} from '../../helpers/custom-validators/videos' 69} from '../../helpers/custom-validators/videos'
67import { logger } from '../../helpers/logger' 70import { logger } from '../../helpers/logger'
68import { CONFIG } from '../../initializers/config' 71import { CONFIG } from '../../initializers/config'
69import { ACTIVITY_PUB, API_VERSION, CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, WEBSERVER } from '../../initializers/constants' 72import { ACTIVITY_PUB, API_VERSION, CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
70import { sendDeleteVideo } from '../../lib/activitypub/send' 73import { sendDeleteVideo } from '../../lib/activitypub/send'
71import { 74import {
72 MChannel, 75 MChannel,
@@ -740,8 +743,23 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
740 }) 743 })
741 VideoJobInfo: VideoJobInfoModel 744 VideoJobInfo: VideoJobInfoModel
742 745
746 @AfterCreate
747 static notifyCreate (video: MVideo) {
748 InternalEventEmitter.Instance.emit('video-created', { video })
749 }
750
751 @AfterUpdate
752 static notifyUpdate (video: MVideo) {
753 InternalEventEmitter.Instance.emit('video-updated', { video })
754 }
755
756 @AfterDestroy
757 static notifyDestroy (video: MVideo) {
758 InternalEventEmitter.Instance.emit('video-deleted', { video })
759 }
760
743 @BeforeDestroy 761 @BeforeDestroy
744 static async sendDelete (instance: MVideoAccountLight, options) { 762 static async sendDelete (instance: MVideoAccountLight, options: { transaction: Transaction }) {
745 if (!instance.isOwned()) return undefined 763 if (!instance.isOwned()) return undefined
746 764
747 // Lazy load channels 765 // Lazy load channels
@@ -1686,15 +1704,14 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1686 const thumbnail = this.getMiniature() 1704 const thumbnail = this.getMiniature()
1687 if (!thumbnail) return null 1705 if (!thumbnail) return null
1688 1706
1689 return join(STATIC_PATHS.THUMBNAILS, thumbnail.filename) 1707 return thumbnail.getLocalStaticPath()
1690 } 1708 }
1691 1709
1692 getPreviewStaticPath () { 1710 getPreviewStaticPath () {
1693 const preview = this.getPreview() 1711 const preview = this.getPreview()
1694 if (!preview) return null 1712 if (!preview) return null
1695 1713
1696 // We use a local cache, so specify our cache endpoint instead of potential remote URL 1714 return preview.getLocalStaticPath()
1697 return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename)
1698 } 1715 }
1699 1716
1700 toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video { 1717 toFormattedJSON (this: MVideoFormattable, options?: VideoFormattingJSONOptions): Video {
@@ -1705,17 +1722,29 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1705 return videoModelToFormattedDetailsJSON(this) 1722 return videoModelToFormattedDetailsJSON(this)
1706 } 1723 }
1707 1724
1708 getFormattedVideoFilesJSON (includeMagnet = true): VideoFile[] { 1725 getFormattedWebVideoFilesJSON (includeMagnet = true): VideoFile[] {
1726 return videoFilesModelToFormattedJSON(this, this.VideoFiles, { includeMagnet })
1727 }
1728
1729 getFormattedHLSVideoFilesJSON (includeMagnet = true): VideoFile[] {
1730 let acc: VideoFile[] = []
1731
1732 for (const p of this.VideoStreamingPlaylists) {
1733 acc = acc.concat(videoFilesModelToFormattedJSON(this, p.VideoFiles, { includeMagnet }))
1734 }
1735
1736 return acc
1737 }
1738
1739 getFormattedAllVideoFilesJSON (includeMagnet = true): VideoFile[] {
1709 let files: VideoFile[] = [] 1740 let files: VideoFile[] = []
1710 1741
1711 if (Array.isArray(this.VideoFiles)) { 1742 if (Array.isArray(this.VideoFiles)) {
1712 const result = videoFilesModelToFormattedJSON(this, this.VideoFiles, { includeMagnet }) 1743 files = files.concat(this.getFormattedWebVideoFilesJSON(includeMagnet))
1713 files = files.concat(result)
1714 } 1744 }
1715 1745
1716 for (const p of (this.VideoStreamingPlaylists || [])) { 1746 if (Array.isArray(this.VideoStreamingPlaylists)) {
1717 const result = videoFilesModelToFormattedJSON(this, p.VideoFiles, { includeMagnet }) 1747 files = files.concat(this.getFormattedHLSVideoFilesJSON(includeMagnet))
1718 files = files.concat(result)
1719 } 1748 }
1720 1749
1721 return files 1750 return files