diff options
Diffstat (limited to 'server/lib/video-privacy.ts')
-rw-r--r-- | server/lib/video-privacy.ts | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/server/lib/video-privacy.ts b/server/lib/video-privacy.ts index 41f9d62b3..5dd4d9781 100644 --- a/server/lib/video-privacy.ts +++ b/server/lib/video-privacy.ts | |||
@@ -4,7 +4,13 @@ import { logger } from '@server/helpers/logger' | |||
4 | import { DIRECTORIES } from '@server/initializers/constants' | 4 | import { DIRECTORIES } from '@server/initializers/constants' |
5 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' | 5 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' |
6 | import { VideoPrivacy, VideoStorage } from '@shared/models' | 6 | import { VideoPrivacy, VideoStorage } from '@shared/models' |
7 | import { updateHLSFilesACL, updateWebTorrentFileACL } from './object-storage' | 7 | import { updateHLSFilesACL, updateWebVideoFileACL } from './object-storage' |
8 | |||
9 | const validPrivacySet = new Set([ | ||
10 | VideoPrivacy.PRIVATE, | ||
11 | VideoPrivacy.INTERNAL, | ||
12 | VideoPrivacy.PASSWORD_PROTECTED | ||
13 | ]) | ||
8 | 14 | ||
9 | function setVideoPrivacy (video: MVideo, newPrivacy: VideoPrivacy) { | 15 | function setVideoPrivacy (video: MVideo, newPrivacy: VideoPrivacy) { |
10 | if (video.privacy === VideoPrivacy.PRIVATE && newPrivacy !== VideoPrivacy.PRIVATE) { | 16 | if (video.privacy === VideoPrivacy.PRIVATE && newPrivacy !== VideoPrivacy.PRIVATE) { |
@@ -14,8 +20,8 @@ function setVideoPrivacy (video: MVideo, newPrivacy: VideoPrivacy) { | |||
14 | video.privacy = newPrivacy | 20 | video.privacy = newPrivacy |
15 | } | 21 | } |
16 | 22 | ||
17 | function isVideoInPrivateDirectory (privacy: VideoPrivacy) { | 23 | function isVideoInPrivateDirectory (privacy) { |
18 | return privacy === VideoPrivacy.PRIVATE || privacy === VideoPrivacy.INTERNAL | 24 | return validPrivacySet.has(privacy) |
19 | } | 25 | } |
20 | 26 | ||
21 | function isVideoInPublicDirectory (privacy: VideoPrivacy) { | 27 | function isVideoInPublicDirectory (privacy: VideoPrivacy) { |
@@ -61,9 +67,9 @@ async function moveFiles (options: { | |||
61 | 67 | ||
62 | for (const file of video.VideoFiles) { | 68 | for (const file of video.VideoFiles) { |
63 | if (file.storage === VideoStorage.FILE_SYSTEM) { | 69 | if (file.storage === VideoStorage.FILE_SYSTEM) { |
64 | await moveWebTorrentFileOnFS(type, video, file) | 70 | await moveWebVideoFileOnFS(type, video, file) |
65 | } else { | 71 | } else { |
66 | await updateWebTorrentFileACL(video, file) | 72 | await updateWebVideoFileACL(video, file) |
67 | } | 73 | } |
68 | } | 74 | } |
69 | 75 | ||
@@ -78,22 +84,22 @@ async function moveFiles (options: { | |||
78 | } | 84 | } |
79 | } | 85 | } |
80 | 86 | ||
81 | async function moveWebTorrentFileOnFS (type: MoveType, video: MVideo, file: MVideoFile) { | 87 | async function moveWebVideoFileOnFS (type: MoveType, video: MVideo, file: MVideoFile) { |
82 | const directories = getWebTorrentDirectories(type) | 88 | const directories = getWebVideoDirectories(type) |
83 | 89 | ||
84 | const source = join(directories.old, file.filename) | 90 | const source = join(directories.old, file.filename) |
85 | const destination = join(directories.new, file.filename) | 91 | const destination = join(directories.new, file.filename) |
86 | 92 | ||
87 | try { | 93 | try { |
88 | logger.info('Moving WebTorrent files of %s after privacy change (%s -> %s).', video.uuid, source, destination) | 94 | logger.info('Moving web video files of %s after privacy change (%s -> %s).', video.uuid, source, destination) |
89 | 95 | ||
90 | await move(source, destination) | 96 | await move(source, destination) |
91 | } catch (err) { | 97 | } catch (err) { |
92 | logger.error('Cannot move webtorrent file %s to %s after privacy change', source, destination, { err }) | 98 | logger.error('Cannot move web video file %s to %s after privacy change', source, destination, { err }) |
93 | } | 99 | } |
94 | } | 100 | } |
95 | 101 | ||
96 | function getWebTorrentDirectories (moveType: MoveType) { | 102 | function getWebVideoDirectories (moveType: MoveType) { |
97 | if (moveType === 'private-to-public') { | 103 | if (moveType === 'private-to-public') { |
98 | return { old: DIRECTORIES.VIDEOS.PRIVATE, new: DIRECTORIES.VIDEOS.PUBLIC } | 104 | return { old: DIRECTORIES.VIDEOS.PRIVATE, new: DIRECTORIES.VIDEOS.PUBLIC } |
99 | } | 105 | } |