aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-16 16:25:53 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-18 13:38:09 +0100
commit90a8bd305de4153ec21137a73ff482dcc2e3e19b (patch)
tree2e35b5504ec11bc51579c92a70c77ed3d5ace816 /server/models/video/video.ts
parent684cdacbbd775b5f404dd7b373e02dd21baf5ff0 (diff)
downloadPeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.tar.gz
PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.tar.zst
PeerTube-90a8bd305de4153ec21137a73ff482dcc2e3e19b.zip
Dissociate video file names and video uuid
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts60
1 files changed, 13 insertions, 47 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 3321deed3..2e6b6aeec 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -24,10 +24,11 @@ import {
24 Table, 24 Table,
25 UpdatedAt 25 UpdatedAt
26} from 'sequelize-typescript' 26} from 'sequelize-typescript'
27import { v4 as uuidv4 } from 'uuid'
27import { buildNSFWFilter } from '@server/helpers/express-utils' 28import { buildNSFWFilter } from '@server/helpers/express-utils'
28import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' 29import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
29import { LiveManager } from '@server/lib/live-manager' 30import { LiveManager } from '@server/lib/live-manager'
30import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 31import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
31import { getServerActor } from '@server/models/application/application' 32import { getServerActor } from '@server/models/application/application'
32import { ModelCache } from '@server/models/model-cache' 33import { ModelCache } from '@server/models/model-cache'
33import { VideoFile } from '@shared/models/videos/video-file.model' 34import { VideoFile } from '@shared/models/videos/video-file.model'
@@ -60,7 +61,6 @@ import {
60 CONSTRAINTS_FIELDS, 61 CONSTRAINTS_FIELDS,
61 LAZY_STATIC_PATHS, 62 LAZY_STATIC_PATHS,
62 REMOTE_SCHEME, 63 REMOTE_SCHEME,
63 STATIC_DOWNLOAD_PATHS,
64 STATIC_PATHS, 64 STATIC_PATHS,
65 VIDEO_CATEGORIES, 65 VIDEO_CATEGORIES,
66 VIDEO_LANGUAGES, 66 VIDEO_LANGUAGES,
@@ -78,6 +78,7 @@ import {
78 MStreamingPlaylistFilesVideo, 78 MStreamingPlaylistFilesVideo,
79 MUserAccountId, 79 MUserAccountId,
80 MUserId, 80 MUserId,
81 MVideo,
81 MVideoAccountLight, 82 MVideoAccountLight,
82 MVideoAccountLightBlacklistAllFiles, 83 MVideoAccountLightBlacklistAllFiles,
83 MVideoAP, 84 MVideoAP,
@@ -130,7 +131,6 @@ import { VideoShareModel } from './video-share'
130import { VideoStreamingPlaylistModel } from './video-streaming-playlist' 131import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
131import { VideoTagModel } from './video-tag' 132import { VideoTagModel } from './video-tag'
132import { VideoViewModel } from './video-view' 133import { VideoViewModel } from './video-view'
133import { v4 as uuidv4 } from 'uuid'
134 134
135export enum ScopeNames { 135export enum ScopeNames {
136 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', 136 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
@@ -790,7 +790,7 @@ export class VideoModel extends Model {
790 // Remove physical files and torrents 790 // Remove physical files and torrents
791 instance.VideoFiles.forEach(file => { 791 instance.VideoFiles.forEach(file => {
792 tasks.push(instance.removeFile(file)) 792 tasks.push(instance.removeFile(file))
793 tasks.push(instance.removeTorrent(file)) 793 tasks.push(file.removeTorrent())
794 }) 794 })
795 795
796 // Remove playlists file 796 // Remove playlists file
@@ -853,18 +853,14 @@ export class VideoModel extends Model {
853 return undefined 853 return undefined
854 } 854 }
855 855
856 static listLocal (): Promise<MVideoWithAllFiles[]> { 856 static listLocal (): Promise<MVideo[]> {
857 const query = { 857 const query = {
858 where: { 858 where: {
859 remote: false 859 remote: false
860 } 860 }
861 } 861 }
862 862
863 return VideoModel.scope([ 863 return VideoModel.findAll(query)
864 ScopeNames.WITH_WEBTORRENT_FILES,
865 ScopeNames.WITH_STREAMING_PLAYLISTS,
866 ScopeNames.WITH_THUMBNAILS
867 ]).findAll(query)
868 } 864 }
869 865
870 static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) { 866 static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
@@ -1623,6 +1619,10 @@ export class VideoModel extends Model {
1623 'resolution', 1619 'resolution',
1624 'size', 1620 'size',
1625 'extname', 1621 'extname',
1622 'filename',
1623 'fileUrl',
1624 'torrentFilename',
1625 'torrentUrl',
1626 'infoHash', 1626 'infoHash',
1627 'fps', 1627 'fps',
1628 'videoId', 1628 'videoId',
@@ -1891,14 +1891,14 @@ export class VideoModel extends Model {
1891 let files: VideoFile[] = [] 1891 let files: VideoFile[] = []
1892 1892
1893 if (Array.isArray(this.VideoFiles)) { 1893 if (Array.isArray(this.VideoFiles)) {
1894 const result = videoFilesModelToFormattedJSON(this, baseUrlHttp, baseUrlWs, this.VideoFiles) 1894 const result = videoFilesModelToFormattedJSON(this, this, baseUrlHttp, baseUrlWs, this.VideoFiles)
1895 files = files.concat(result) 1895 files = files.concat(result)
1896 } 1896 }
1897 1897
1898 for (const p of (this.VideoStreamingPlaylists || [])) { 1898 for (const p of (this.VideoStreamingPlaylists || [])) {
1899 p.Video = this 1899 p.Video = this
1900 1900
1901 const result = videoFilesModelToFormattedJSON(p, baseUrlHttp, baseUrlWs, p.VideoFiles) 1901 const result = videoFilesModelToFormattedJSON(p, this, baseUrlHttp, baseUrlWs, p.VideoFiles)
1902 files = files.concat(result) 1902 files = files.concat(result)
1903 } 1903 }
1904 1904
@@ -1956,12 +1956,6 @@ export class VideoModel extends Model {
1956 .catch(err => logger.warn('Cannot delete file %s.', filePath, { err })) 1956 .catch(err => logger.warn('Cannot delete file %s.', filePath, { err }))
1957 } 1957 }
1958 1958
1959 removeTorrent (videoFile: MVideoFile) {
1960 const torrentPath = getTorrentFilePath(this, videoFile)
1961 return remove(torrentPath)
1962 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
1963 }
1964
1965 async removeStreamingPlaylistFiles (streamingPlaylist: MStreamingPlaylist, isRedundancy = false) { 1959 async removeStreamingPlaylistFiles (streamingPlaylist: MStreamingPlaylist, isRedundancy = false) {
1966 const directoryPath = getHLSDirectory(this, isRedundancy) 1960 const directoryPath = getHLSDirectory(this, isRedundancy)
1967 1961
@@ -1977,7 +1971,7 @@ export class VideoModel extends Model {
1977 1971
1978 // Remove physical files and torrents 1972 // Remove physical files and torrents
1979 await Promise.all( 1973 await Promise.all(
1980 streamingPlaylistWithFiles.VideoFiles.map(file => streamingPlaylistWithFiles.removeTorrent(file)) 1974 streamingPlaylistWithFiles.VideoFiles.map(file => file.removeTorrent())
1981 ) 1975 )
1982 } 1976 }
1983 } 1977 }
@@ -2054,34 +2048,6 @@ export class VideoModel extends Model {
2054 return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] 2048 return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]
2055 } 2049 }
2056 2050
2057 getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2058 return baseUrlHttp + STATIC_PATHS.TORRENTS + getTorrentFileName(this, videoFile)
2059 }
2060
2061 getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2062 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + getTorrentFileName(this, videoFile)
2063 }
2064
2065 getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2066 return baseUrlHttp + STATIC_PATHS.WEBSEED + getVideoFilename(this, videoFile)
2067 }
2068
2069 getVideoFileMetadataUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2070 const path = '/api/v1/videos/'
2071
2072 return this.isOwned()
2073 ? baseUrlHttp + path + this.uuid + '/metadata/' + videoFile.id
2074 : videoFile.metadataUrl
2075 }
2076
2077 getVideoRedundancyUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2078 return baseUrlHttp + STATIC_PATHS.REDUNDANCY + getVideoFilename(this, videoFile)
2079 }
2080
2081 getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
2082 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.VIDEOS + getVideoFilename(this, videoFile)
2083 }
2084
2085 getBandwidthBits (videoFile: MVideoFile) { 2051 getBandwidthBits (videoFile: MVideoFile) {
2086 return Math.ceil((videoFile.size * 8) / this.duration) 2052 return Math.ceil((videoFile.size * 8) / this.duration)
2087 } 2053 }