2016-11-14 22:49:19 +01:00
|
|
|
/*
|
|
|
|
Use remote id as identifier
|
|
|
|
*/
|
|
|
|
|
|
|
|
const map = require('lodash/map')
|
|
|
|
const mongoose = require('mongoose')
|
|
|
|
const readline = require('readline')
|
|
|
|
|
|
|
|
const rl = readline.createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
|
|
|
})
|
|
|
|
|
|
|
|
const logger = require('../../helpers/logger')
|
|
|
|
const friends = require('../../lib/friends')
|
|
|
|
|
|
|
|
const Pod = mongoose.model('Pod')
|
|
|
|
const Video = mongoose.model('Video')
|
|
|
|
|
|
|
|
exports.up = function (callback) {
|
|
|
|
Pod.find({}).lean().exec(function (err, pods) {
|
|
|
|
if (err) return callback(err)
|
|
|
|
|
|
|
|
// We need to quit friends first
|
|
|
|
if (pods.length === 0) {
|
|
|
|
return setVideosRemoteId(callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeout = setTimeout(function () {
|
|
|
|
throw new Error('You need to enter a value!')
|
|
|
|
}, 10000)
|
|
|
|
|
|
|
|
rl.question('I am sorry but I need to quit friends for upgrading. Do you want to continue? (yes/*)', function (answer) {
|
|
|
|
if (answer !== 'yes') throw new Error('I cannot continue.')
|
|
|
|
|
|
|
|
clearTimeout(timeout)
|
|
|
|
rl.close()
|
|
|
|
|
|
|
|
const urls = map(pods, 'url')
|
|
|
|
logger.info('Saying goodbye to: ' + urls.join(', '))
|
|
|
|
|
2016-11-21 22:08:40 +01:00
|
|
|
setVideosRemoteId(function () {
|
|
|
|
friends.quitFriends(callback)
|
2016-11-14 22:49:19 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.down = function (callback) {
|
|
|
|
throw new Error('Not implemented.')
|
|
|
|
}
|
|
|
|
|
|
|
|
function setVideosRemoteId (callback) {
|
2016-11-21 22:08:40 +01:00
|
|
|
Video.update({ filename: { $ne: null } }, { remoteId: null }, function (err) {
|
|
|
|
if (err) throw err
|
2016-11-14 22:49:19 +01:00
|
|
|
|
2016-11-21 22:08:40 +01:00
|
|
|
Video.update({ filename: null }, { remoteId: mongoose.Types.ObjectId() }, callback)
|
2016-11-14 22:49:19 +01:00
|
|
|
})
|
|
|
|
}
|