aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0025-video-filenames.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/migrations/0025-video-filenames.js')
-rw-r--r--server/initializers/migrations/0025-video-filenames.js57
1 files changed, 0 insertions, 57 deletions
diff --git a/server/initializers/migrations/0025-video-filenames.js b/server/initializers/migrations/0025-video-filenames.js
deleted file mode 100644
index df21494d7..000000000
--- a/server/initializers/migrations/0025-video-filenames.js
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2 Rename thumbnails and video filenames to _id.extension
3*/
4
5const each = require('async/each')
6const fs = require('fs')
7const path = require('path')
8const mongoose = require('mongoose')
9
10const constants = require('../constants')
11const logger = require('../../helpers/logger')
12
13const Video = mongoose.model('Video')
14
15exports.up = function (callback) {
16 // Use of lean because the new Video scheme does not have filename field
17 Video.find({ filename: { $ne: null } }).lean().exec(function (err, videos) {
18 if (err) throw err
19
20 each(videos, function (video, callbackEach) {
21 const torrentName = video.filename + '.torrent'
22 const thumbnailName = video.thumbnail
23 const thumbnailExtension = path.extname(thumbnailName)
24 const videoName = video.filename
25 const videoExtension = path.extname(videoName)
26
27 const newTorrentName = video._id + '.torrent'
28 const newThumbnailName = video._id + thumbnailExtension
29 const newVideoName = video._id + videoExtension
30
31 const torrentsDir = constants.CONFIG.STORAGE.TORRENTS_DIR
32 const thumbnailsDir = constants.CONFIG.STORAGE.THUMBNAILS_DIR
33 const videosDir = constants.CONFIG.STORAGE.VIDEOS_DIR
34
35 logger.info('Renaming %s to %s.', torrentsDir + torrentName, torrentsDir + newTorrentName)
36 fs.renameSync(torrentsDir + torrentName, torrentsDir + newTorrentName)
37
38 logger.info('Renaming %s to %s.', thumbnailsDir + thumbnailName, thumbnailsDir + newThumbnailName)
39 fs.renameSync(thumbnailsDir + thumbnailName, thumbnailsDir + newThumbnailName)
40
41 logger.info('Renaming %s to %s.', videosDir + videoName, videosDir + newVideoName)
42 fs.renameSync(videosDir + videoName, videosDir + newVideoName)
43
44 Video.load(video._id, function (err, videoObj) {
45 if (err) return callbackEach(err)
46
47 videoObj.extname = videoExtension
48 videoObj.remoteId = null
49 videoObj.save(callbackEach)
50 })
51 }, callback)
52 })
53}
54
55exports.down = function (callback) {
56 throw new Error('Not implemented.')
57}