mirror of https://github.com/Chocobozzz/PeerTube
Server: fix update remote video infohash
parent
63d00f5ded
commit
7f4e7c3637
|
@ -259,6 +259,7 @@ function updateVideoRetryWrapper (req, res, next) {
|
|||
|
||||
function updateVideo (req, res, finalCallback) {
|
||||
const videoInstance = res.locals.video
|
||||
const videoFieldsSave = videoInstance.toJSON()
|
||||
const videoInfosToUpdate = req.body
|
||||
|
||||
waterfall([
|
||||
|
@ -280,12 +281,13 @@ function updateVideo (req, res, finalCallback) {
|
|||
},
|
||||
|
||||
function updateVideoIntoDB (t, tagInstances, callback) {
|
||||
const options = { transaction: t }
|
||||
const options = {
|
||||
transaction: t
|
||||
}
|
||||
|
||||
if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
|
||||
if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
|
||||
|
||||
// Add tags association
|
||||
videoInstance.save(options).asCallback(function (err) {
|
||||
return callback(err, t, tagInstances)
|
||||
})
|
||||
|
@ -321,6 +323,14 @@ function updateVideo (req, res, finalCallback) {
|
|||
// Abort transaction?
|
||||
if (t) t.rollback()
|
||||
|
||||
// Force fields we want to update
|
||||
// If the transaction is retried, sequelize will think the object has not changed
|
||||
// So it will skip the SQL request, even if the last one was ROLLBACKed!
|
||||
Object.keys(videoFieldsSave).forEach(function (key) {
|
||||
const value = videoFieldsSave[key]
|
||||
videoInstance.set(key, value)
|
||||
})
|
||||
|
||||
return finalCallback(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||
}
|
||||
|
||||
function beforeValidate (video, options, next) {
|
||||
if (video.isOwned()) {
|
||||
// Put a fake infoHash if it does not exists yet
|
||||
if (video.isOwned() && !video.infoHash) {
|
||||
// 40 hexa length
|
||||
video.infoHash = '0123456789abcdef0123456789abcdef01234567'
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ const chai = require('chai')
|
|||
const each = require('async/each')
|
||||
const expect = chai.expect
|
||||
const series = require('async/series')
|
||||
const webtorrent = new (require('webtorrent'))()
|
||||
const WebTorrent = require('webtorrent')
|
||||
const webtorrent = new WebTorrent()
|
||||
|
||||
const loginUtils = require('../utils/login')
|
||||
const miscsUtils = require('../utils/miscs')
|
||||
|
@ -311,7 +312,7 @@ describe('Test multiple pods', function () {
|
|||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
done()
|
||||
webtorrent.remove(video.magnetUri, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -330,7 +331,7 @@ describe('Test multiple pods', function () {
|
|||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
done()
|
||||
webtorrent.remove(video.magnetUri, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -349,7 +350,7 @@ describe('Test multiple pods', function () {
|
|||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
done()
|
||||
webtorrent.remove(video.magnetUri, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -368,7 +369,7 @@ describe('Test multiple pods', function () {
|
|||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
done()
|
||||
webtorrent.remove(video.magnetUri, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -390,7 +391,12 @@ describe('Test multiple pods', function () {
|
|||
})
|
||||
|
||||
it('Should have the video 3 updated on each pod', function (done) {
|
||||
this.timeout(200000)
|
||||
|
||||
each(servers, function (server, callback) {
|
||||
// Avoid "duplicate torrent" errors
|
||||
const webtorrent = new WebTorrent()
|
||||
|
||||
videosUtils.getVideosList(server.url, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
|
@ -404,7 +410,18 @@ describe('Test multiple pods', function () {
|
|||
expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
|
||||
expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
|
||||
|
||||
callback()
|
||||
videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
|
||||
if (err) throw err
|
||||
expect(test).to.equal(true)
|
||||
|
||||
webtorrent.add(videoUpdated.magnetUri, function (torrent) {
|
||||
expect(torrent.files).to.exist
|
||||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
webtorrent.remove(videoUpdated.magnetUri, callback)
|
||||
})
|
||||
})
|
||||
})
|
||||
}, done)
|
||||
})
|
||||
|
|
|
@ -96,7 +96,7 @@ describe('Test a single pod', function () {
|
|||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
done()
|
||||
webtorrent.remove(video.magnetUri, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -515,6 +515,8 @@ describe('Test a single pod', function () {
|
|||
})
|
||||
|
||||
it('Should have the video updated', function (done) {
|
||||
this.timeout(60000)
|
||||
|
||||
videosUtils.getVideo(server.url, videoId, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
|
@ -529,7 +531,20 @@ describe('Test a single pod', function () {
|
|||
expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
|
||||
expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
|
||||
|
||||
done()
|
||||
videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
|
||||
if (err) throw err
|
||||
expect(test).to.equal(true)
|
||||
|
||||
videoId = video.id
|
||||
|
||||
webtorrent.add(video.magnetUri, function (torrent) {
|
||||
expect(torrent.files).to.exist
|
||||
expect(torrent.files.length).to.equal(1)
|
||||
expect(torrent.files[0].path).to.exist.and.to.not.equal('')
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ const numberOfPods = 6
|
|||
// Wait requests between pods
|
||||
const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? integrityInterval : constants.REQUESTS_INTERVAL
|
||||
const requestsMaxPerInterval = baseRequestInterval / actionInterval
|
||||
const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / (constants.REQUESTS_LIMIT_PER_POD * numberOfPods))
|
||||
const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD)
|
||||
const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) + 1000
|
||||
|
||||
console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)
|
||||
|
|
Loading…
Reference in New Issue