1 import * as Sequelize from 'sequelize'
2 import * as Promise from 'bluebird'
3 import { join } from 'path'
5 import { readdirPromise, renamePromise } from '../../helpers/core-utils'
6 import { CONFIG } from '../../initializers/constants'
9 transaction: Sequelize.Transaction,
10 queryInterface: Sequelize.QueryInterface,
11 sequelize: Sequelize.Sequelize,
14 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
15 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR
17 return readdirPromise(torrentDir)
18 .then(torrentFiles => {
19 const tasks: Promise<any>[] = []
20 for (const torrentFile of torrentFiles) {
21 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.torrent/.exec(torrentFile)
22 if (matches === null) {
23 console.log('Invalid torrent file name %s.', torrentFile)
27 const newTorrentName = matches[1] + '-original.torrent'
28 const p = renamePromise(join(torrentDir, torrentFile), join(torrentDir, newTorrentName))
32 return Promise.all(tasks)
35 return readdirPromise(videoFileDir)
38 const tasks: Promise<any>[] = []
39 for (const videoFile of videoFiles) {
40 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.([a-z0-9]+)/.exec(videoFile)
41 if (matches === null) {
42 console.log('Invalid video file name %s.', videoFile)
46 const newVideoFileName = matches[1] + '-original.' + matches[2]
47 const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName))
51 return Promise.all(tasks).then(() => undefined)
55 function down (options) {
56 throw new Error('Not implemented.')