diff options
Diffstat (limited to 'server/models/video/video-streaming-playlist.ts')
-rw-r--r-- | server/models/video/video-streaming-playlist.ts | 58 |
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 @@ | |||
1 | import * as memoizee from 'memoizee' | ||
2 | import { join } from 'path' | ||
3 | import { Op, QueryTypes } from 'sequelize' | ||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 4 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' | 5 | import { VideoFileModel } from '@server/models/video/video-file' |
3 | import { throwIfNotValid } from '../utils' | 6 | import { MStreamingPlaylist } from '@server/types/models' |
4 | import { VideoModel } from './video' | ||
5 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | ||
6 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 7 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' |
7 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
8 | import { | ||
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' | ||
16 | import { join } from 'path' | ||
17 | import { sha1 } from '../../helpers/core-utils' | 8 | import { sha1 } from '../../helpers/core-utils' |
9 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | ||
18 | import { isArrayOf } from '../../helpers/custom-validators/misc' | 10 | import { isArrayOf } from '../../helpers/custom-validators/misc' |
19 | import { Op, QueryTypes } from 'sequelize' | 11 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' |
20 | import { MStreamingPlaylist, MStreamingPlaylistVideo, MVideoFile } from '@server/types/models' | 12 | import { CONSTRAINTS_FIELDS, MEMOIZE_LENGTH, MEMOIZE_TTL, P2P_MEDIA_LOADER_PEER_VERSION, STATIC_PATHS } from '../../initializers/constants' |
21 | import { VideoFileModel } from '@server/models/video/video-file' | 13 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
22 | import { getTorrentFileName, getTorrentFilePath, getVideoFilename } from '@server/lib/video-paths' | 14 | import { throwIfNotValid } from '../utils' |
23 | import * as memoizee from 'memoizee' | 15 | import { VideoModel } from './video' |
24 | import { remove } from 'fs-extra' | ||
25 | import { 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 | } |