aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-streaming-playlist.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-streaming-playlist.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-streaming-playlist.ts')
-rw-r--r--server/models/video/video-streaming-playlist.ts58
1 files changed, 11 insertions, 47 deletions
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index 148768c21..c9375b433 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -1,28 +1,18 @@
1import * as memoizee from 'memoizee'
2import { join } from 'path'
3import { Op, QueryTypes } from 'sequelize'
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 4import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' 5import { VideoFileModel } from '@server/models/video/video-file'
3import { throwIfNotValid } from '../utils' 6import { MStreamingPlaylist } from '@server/types/models'
4import { VideoModel } from './video'
5import { VideoRedundancyModel } from '../redundancy/video-redundancy'
6import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 7import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
8import {
9 CONSTRAINTS_FIELDS,
10 MEMOIZE_LENGTH,
11 MEMOIZE_TTL,
12 P2P_MEDIA_LOADER_PEER_VERSION,
13 STATIC_DOWNLOAD_PATHS,
14 STATIC_PATHS
15} from '../../initializers/constants'
16import { join } from 'path'
17import { sha1 } from '../../helpers/core-utils' 8import { sha1 } from '../../helpers/core-utils'
9import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
18import { isArrayOf } from '../../helpers/custom-validators/misc' 10import { isArrayOf } from '../../helpers/custom-validators/misc'
19import { Op, QueryTypes } from 'sequelize' 11import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
20import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' 12import { CONSTRAINTS_FIELDS, MEMOIZE_LENGTH, MEMOIZE_TTL, P2P_MEDIA_LOADER_PEER_VERSION, STATIC_PATHS } from '../../initializers/constants'
21import { VideoFileModel } from '@server/models/video/video-file' 13import { VideoRedundancyModel } from '../redundancy/video-redundancy'
22import { getTorrentFileName, getTorrentFilePath, getVideoFilename } from '@server/lib/video-paths' 14import { throwIfNotValid } from '../utils'
23import * as memoizee from 'memoizee' 15import { VideoModel } from './video'
24import { remove } from 'fs-extra'
25import { logger } from '@server/helpers/logger'
26 16
27@Table({ 17@Table({
28 tableName: 'videoStreamingPlaylist', 18 tableName: 'videoStreamingPlaylist',
@@ -196,26 +186,6 @@ export class VideoStreamingPlaylistModel extends Model {
196 return 'unknown' 186 return 'unknown'
197 } 187 }
198 188
199 getVideoRedundancyUrl (baseUrlHttp: string) {
200 return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getStringType() + '/' + this.Video.uuid
201 }
202
203 getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
204 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + getTorrentFileName(this, videoFile)
205 }
206
207 getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
208 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.HLS_VIDEOS + getVideoFilename(this, videoFile)
209 }
210
211 getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) {
212 return baseUrlHttp + join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, this.Video.uuid, getVideoFilename(this, videoFile))
213 }
214
215 getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) {
216 return baseUrlHttp + join(STATIC_PATHS.TORRENTS, getTorrentFileName(this, videoFile))
217 }
218
219 getTrackerUrls (baseUrlHttp: string, baseUrlWs: string) { 189 getTrackerUrls (baseUrlHttp: string, baseUrlWs: string) {
220 return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ] 190 return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]
221 } 191 }
@@ -224,10 +194,4 @@ export class VideoStreamingPlaylistModel extends Model {
224 return this.type === other.type && 194 return this.type === other.type &&
225 this.videoId === other.videoId 195 this.videoId === other.videoId
226 } 196 }
227
228 removeTorrent (this: MStreamingPlaylistVideo, videoFile: MVideoFile) {
229 const torrentPath = getTorrentFilePath(this, videoFile)
230 return remove(torrentPath)
231 .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
232 }
233} 197}