diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-29 14:50:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-01 14:55:10 +0200 |
commit | 1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7 (patch) | |
tree | a6554ee0a3ccc2ae402665b2ecf57bb38fd0ed72 /server/models | |
parent | 12d84abeca4917d2f1e3f308010bfcd56d37cb7c (diff) | |
download | PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.gz PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.tar.zst PeerTube-1bb4c9ab2e8b3b3022351b33a82a5e527fa5d4d7.zip |
Add ability to delete a specific video file
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-streaming-playlist.ts | 36 | ||||
-rw-r--r-- | server/models/video/video.ts | 10 |
3 files changed, 41 insertions, 7 deletions
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index b363afb28..15909d5f3 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -162,7 +162,7 @@ export class VideoRedundancyModel extends Model<Partial<AttributesOnly<VideoRedu | |||
162 | const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` | 162 | const logIdentifier = `${videoFile.Video.uuid}-${videoFile.resolution}` |
163 | logger.info('Removing duplicated video file %s.', logIdentifier) | 163 | logger.info('Removing duplicated video file %s.', logIdentifier) |
164 | 164 | ||
165 | videoFile.Video.removeWebTorrentFileAndTorrent(videoFile, true) | 165 | videoFile.Video.removeWebTorrentFile(videoFile, true) |
166 | .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) | 166 | .catch(err => logger.error('Cannot delete %s files.', logIdentifier, { err })) |
167 | } | 167 | } |
168 | 168 | ||
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 2c4dbd8ec..f587989dc 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -16,8 +16,9 @@ import { | |||
16 | UpdatedAt | 16 | UpdatedAt |
17 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
18 | import { getHLSPublicFileUrl } from '@server/lib/object-storage' | 18 | import { getHLSPublicFileUrl } from '@server/lib/object-storage' |
19 | import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename } from '@server/lib/paths' | ||
19 | import { VideoFileModel } from '@server/models/video/video-file' | 20 | import { VideoFileModel } from '@server/models/video/video-file' |
20 | import { MStreamingPlaylist, MVideo } from '@server/types/models' | 21 | import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' |
21 | import { sha1 } from '@shared/extra-utils' | 22 | import { sha1 } from '@shared/extra-utils' |
22 | import { VideoStorage } from '@shared/models' | 23 | import { VideoStorage } from '@shared/models' |
23 | import { AttributesOnly } from '@shared/typescript-utils' | 24 | import { AttributesOnly } from '@shared/typescript-utils' |
@@ -167,6 +168,22 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi | |||
167 | return VideoStreamingPlaylistModel.findAll(query) | 168 | return VideoStreamingPlaylistModel.findAll(query) |
168 | } | 169 | } |
169 | 170 | ||
171 | static loadWithVideoAndFiles (id: number) { | ||
172 | const options = { | ||
173 | include: [ | ||
174 | { | ||
175 | model: VideoModel.unscoped(), | ||
176 | required: true | ||
177 | }, | ||
178 | { | ||
179 | model: VideoFileModel.unscoped() | ||
180 | } | ||
181 | ] | ||
182 | } | ||
183 | |||
184 | return VideoStreamingPlaylistModel.findByPk<MStreamingPlaylistFilesVideo>(id, options) | ||
185 | } | ||
186 | |||
170 | static loadWithVideo (id: number) { | 187 | static loadWithVideo (id: number) { |
171 | const options = { | 188 | const options = { |
172 | include: [ | 189 | include: [ |
@@ -194,9 +211,22 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi | |||
194 | 211 | ||
195 | static async loadOrGenerate (video: MVideo, transaction?: Transaction) { | 212 | static async loadOrGenerate (video: MVideo, transaction?: Transaction) { |
196 | let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction) | 213 | let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction) |
197 | if (!playlist) playlist = new VideoStreamingPlaylistModel() | ||
198 | 214 | ||
199 | return Object.assign(playlist, { videoId: video.id, Video: video }) | 215 | if (!playlist) { |
216 | playlist = new VideoStreamingPlaylistModel({ | ||
217 | p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, | ||
218 | type: VideoStreamingPlaylistType.HLS, | ||
219 | storage: VideoStorage.FILE_SYSTEM, | ||
220 | p2pMediaLoaderInfohashes: [], | ||
221 | playlistFilename: generateHLSMasterPlaylistFilename(video.isLive), | ||
222 | segmentsSha256Filename: generateHlsSha256SegmentsFilename(video.isLive), | ||
223 | videoId: video.id | ||
224 | }) | ||
225 | |||
226 | await playlist.save({ transaction }) | ||
227 | } | ||
228 | |||
229 | return Object.assign(playlist, { Video: video }) | ||
200 | } | 230 | } |
201 | 231 | ||
202 | static doesOwnedHLSPlaylistExist (videoUUID: string) { | 232 | static doesOwnedHLSPlaylistExist (videoUUID: string) { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 7e9bb4db4..b8e383502 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -28,7 +28,7 @@ import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation | |||
28 | import { LiveManager } from '@server/lib/live/live-manager' | 28 | import { LiveManager } from '@server/lib/live/live-manager' |
29 | import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' | 29 | import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' |
30 | import { tracer } from '@server/lib/opentelemetry/tracing' | 30 | import { tracer } from '@server/lib/opentelemetry/tracing' |
31 | import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths' | 31 | import { getHLSDirectory, getHLSRedundancyDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' |
32 | import { VideoPathManager } from '@server/lib/video-path-manager' | 32 | import { VideoPathManager } from '@server/lib/video-path-manager' |
33 | import { getServerActor } from '@server/models/application/application' | 33 | import { getServerActor } from '@server/models/application/application' |
34 | import { ModelCache } from '@server/models/model-cache' | 34 | import { ModelCache } from '@server/models/model-cache' |
@@ -769,7 +769,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
769 | 769 | ||
770 | // Remove physical files and torrents | 770 | // Remove physical files and torrents |
771 | instance.VideoFiles.forEach(file => { | 771 | instance.VideoFiles.forEach(file => { |
772 | tasks.push(instance.removeWebTorrentFileAndTorrent(file)) | 772 | tasks.push(instance.removeWebTorrentFile(file)) |
773 | }) | 773 | }) |
774 | 774 | ||
775 | // Remove playlists file | 775 | // Remove playlists file |
@@ -1783,7 +1783,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1783 | .concat(toAdd) | 1783 | .concat(toAdd) |
1784 | } | 1784 | } |
1785 | 1785 | ||
1786 | removeWebTorrentFileAndTorrent (videoFile: MVideoFile, isRedundancy = false) { | 1786 | removeWebTorrentFile (videoFile: MVideoFile, isRedundancy = false) { |
1787 | const filePath = isRedundancy | 1787 | const filePath = isRedundancy |
1788 | ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile) | 1788 | ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile) |
1789 | : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile) | 1789 | : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile) |
@@ -1829,8 +1829,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1829 | await videoFile.removeTorrent() | 1829 | await videoFile.removeTorrent() |
1830 | await remove(filePath) | 1830 | await remove(filePath) |
1831 | 1831 | ||
1832 | const resolutionFilename = getHlsResolutionPlaylistFilename(videoFile.filename) | ||
1833 | await remove(VideoPathManager.Instance.getFSHLSOutputPath(this, resolutionFilename)) | ||
1834 | |||
1832 | if (videoFile.storage === VideoStorage.OBJECT_STORAGE) { | 1835 | if (videoFile.storage === VideoStorage.OBJECT_STORAGE) { |
1833 | await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), videoFile.filename) | 1836 | await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), videoFile.filename) |
1837 | await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), resolutionFilename) | ||
1834 | } | 1838 | } |
1835 | } | 1839 | } |
1836 | 1840 | ||