aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-file.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r--server/models/video/video-file.ts62
1 files changed, 49 insertions, 13 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index 1a608932f..c20c90c1b 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -22,7 +22,12 @@ import validator from 'validator'
22import { logger } from '@server/helpers/logger' 22import { logger } from '@server/helpers/logger'
23import { extractVideo } from '@server/helpers/video' 23import { extractVideo } from '@server/helpers/video'
24import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url' 24import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url'
25import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage' 25import {
26 getHLSPrivateFileUrl,
27 getHLSPublicFileUrl,
28 getWebTorrentPrivateFileUrl,
29 getWebTorrentPublicFileUrl
30} from '@server/lib/object-storage'
26import { getFSTorrentFilePath } from '@server/lib/paths' 31import { getFSTorrentFilePath } from '@server/lib/paths'
27import { isVideoInPrivateDirectory } from '@server/lib/video-privacy' 32import { isVideoInPrivateDirectory } from '@server/lib/video-privacy'
28import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' 33import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models'
@@ -503,7 +508,25 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
503 return !!this.videoStreamingPlaylistId 508 return !!this.videoStreamingPlaylistId
504 } 509 }
505 510
506 getObjectStorageUrl () { 511 // ---------------------------------------------------------------------------
512
513 getObjectStorageUrl (video: MVideo) {
514 if (video.hasPrivateStaticPath()) {
515 return this.getPrivateObjectStorageUrl(video)
516 }
517
518 return this.getPublicObjectStorageUrl()
519 }
520
521 private getPrivateObjectStorageUrl (video: MVideo) {
522 if (this.isHLS()) {
523 return getHLSPrivateFileUrl(video, this.filename)
524 }
525
526 return getWebTorrentPrivateFileUrl(this.filename)
527 }
528
529 private getPublicObjectStorageUrl () {
507 if (this.isHLS()) { 530 if (this.isHLS()) {
508 return getHLSPublicFileUrl(this.fileUrl) 531 return getHLSPublicFileUrl(this.fileUrl)
509 } 532 }
@@ -511,26 +534,29 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
511 return getWebTorrentPublicFileUrl(this.fileUrl) 534 return getWebTorrentPublicFileUrl(this.fileUrl)
512 } 535 }
513 536
537 // ---------------------------------------------------------------------------
538
514 getFileUrl (video: MVideo) { 539 getFileUrl (video: MVideo) {
515 if (this.storage === VideoStorage.OBJECT_STORAGE) { 540 if (video.isOwned()) {
516 return this.getObjectStorageUrl() 541 if (this.storage === VideoStorage.OBJECT_STORAGE) {
517 } 542 return this.getObjectStorageUrl(video)
543 }
518 544
519 if (!this.Video) this.Video = video as VideoModel 545 return WEBSERVER.URL + this.getFileStaticPath(video)
520 if (video.isOwned()) return WEBSERVER.URL + this.getFileStaticPath(video) 546 }
521 547
522 return this.fileUrl 548 return this.fileUrl
523 } 549 }
524 550
551 // ---------------------------------------------------------------------------
552
525 getFileStaticPath (video: MVideo) { 553 getFileStaticPath (video: MVideo) {
526 if (this.isHLS()) { 554 if (this.isHLS()) return this.getHLSFileStaticPath(video)
527 if (isVideoInPrivateDirectory(video.privacy)) {
528 return join(STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS, video.uuid, this.filename)
529 }
530 555
531 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, video.uuid, this.filename) 556 return this.getWebTorrentFileStaticPath(video)
532 } 557 }
533 558
559 private getWebTorrentFileStaticPath (video: MVideo) {
534 if (isVideoInPrivateDirectory(video.privacy)) { 560 if (isVideoInPrivateDirectory(video.privacy)) {
535 return join(STATIC_PATHS.PRIVATE_WEBSEED, this.filename) 561 return join(STATIC_PATHS.PRIVATE_WEBSEED, this.filename)
536 } 562 }
@@ -538,6 +564,16 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
538 return join(STATIC_PATHS.WEBSEED, this.filename) 564 return join(STATIC_PATHS.WEBSEED, this.filename)
539 } 565 }
540 566
567 private getHLSFileStaticPath (video: MVideo) {
568 if (isVideoInPrivateDirectory(video.privacy)) {
569 return join(STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS, video.uuid, this.filename)
570 }
571
572 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, video.uuid, this.filename)
573 }
574
575 // ---------------------------------------------------------------------------
576
541 getFileDownloadUrl (video: MVideoWithHost) { 577 getFileDownloadUrl (video: MVideoWithHost) {
542 const path = this.isHLS() 578 const path = this.isHLS()
543 ? join(STATIC_DOWNLOAD_PATHS.HLS_VIDEOS, `${video.uuid}-${this.resolution}-fragmented${this.extname}`) 579 ? join(STATIC_DOWNLOAD_PATHS.HLS_VIDEOS, `${video.uuid}-${this.resolution}-fragmented${this.extname}`)