1 import { ensureDir } from 'fs-extra'
2 import { Op } from 'sequelize'
3 import { updateTorrentMetadata } from '@server/helpers/webtorrent'
4 import { DIRECTORIES } from '@server/initializers/constants'
5 import { moveFilesIfPrivacyChanged } from '@server/lib/video-privacy'
6 import { VideoModel } from '@server/models/video/video'
7 import { MVideoFullLight } from '@server/types/models'
8 import { VideoPrivacy } from '@shared/models'
9 import { initDatabaseModels } from '../../server/initializers/database'
12 .then(() => process.exit(0))
18 async function run () {
19 console.log('Moving private video files in dedicated folders.')
21 await ensureDir(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE)
22 await ensureDir(DIRECTORIES.VIDEOS.PRIVATE)
24 await initDatabaseModels(true)
26 const videos = await VideoModel.unscoped().findAll({
27 attributes: [ 'uuid' ],
30 [Op.in]: [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]
35 for (const { uuid } of videos) {
37 console.log('Moving files of video %s.', uuid)
39 const video = await VideoModel.loadFull(uuid)
42 await moveFilesIfPrivacyChanged(video, VideoPrivacy.PUBLIC)
44 console.error('Cannot move files of video %s.', uuid, err)
48 await updateTorrents(video)
50 console.error('Cannot regenerate torrents of video %s.', uuid, err)
53 console.error('Cannot process video %s.', uuid, err)
58 async function updateTorrents (video: MVideoFullLight) {
59 for (const file of video.VideoFiles) {
60 await updateTorrentMetadata(video, file)
65 const playlist = video.getHLSPlaylist()
66 for (const file of (playlist?.VideoFiles || [])) {
67 await updateTorrentMetadata(playlist, file)