Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Federate video on thumbnail re-generation

Chocobozzzf28671fce69f
diff --git a/packages/tests/src/cli/regenerate-thumbnails.ts b/packages/tests/src/cli/regenerate-thumbnails.ts
index e73f273129..bcdb2f1a14 100644
--- a/packages/tests/src/cli/regenerate-thumbnails.ts
+++ b/packages/tests/src/cli/regenerate-thumbnails.ts
@@ -1,4 +1,4 @@
-import { minBy, wait } from '@peertube/peertube-core-utils'
+import { minBy } from '@peertube/peertube-core-utils'
import { HttpStatusCode, Thumbnail, Video } from '@peertube/peertube-models'
import {
cleanupTests,
@@ -112,43 +112,27 @@ describe('Test regenerate thumbnails CLI', function () {
it('Should regenerate remote thumbnails', async function () {
await servers[1].cli.execWithEnv(`npm run regenerate-thumbnails`)
- })
- it('Should still have cached remote thumbnails on server 1', async function () {
- for (const thumbnail of remoteVideo.thumbnails) {
- const { body } = await makeRawRequest({ url: thumbnail.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
+ await waitJobs(servers)
+
+ for (const server of servers) {
+ const video = await server.videos.get({ id: remoteVideo.uuid })
+
+ for (const thumbnail of video.thumbnails) {
+ const { body } = await makeRawRequest({ url: thumbnail.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
- if (isTruncatedThumbnail(thumbnail)) {
- expect(body).to.have.lengthOf(0)
- } else {
expect(body).to.not.have.lengthOf(0)
}
}
})
- it('Should refresh the video and remove previous cached thumbnails', async function () {
- await wait(10000)
-
- await servers[0].videos.get({ id: remoteVideo.uuid }) // Refresh remote video thumbnails
- await waitJobs(servers)
-
+ it('Should not have cached previous remote thumbnails on server 1', async function () {
for (const thumbnail of remoteVideo.thumbnails) {
await makeRawRequest({ url: thumbnail.fileUrl, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
}
})
it('Should have the appropriate thumbnails count', async function () {
- expect(await servers[0].servers.countFiles('thumbnails')).to.equal(10)
- expect(await servers[0].servers.countFiles('cache/thumbnails')).to.equal(0)
- })
-
- it('Should re-cache thumbnails on server 1', async function () {
- const remoteVideoRefreshed = await servers[0].videos.get({ id: remoteVideo.uuid })
-
- for (const thumbnail of remoteVideoRefreshed.thumbnails) {
- await makeRawRequest({ url: thumbnail.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
- }
-
expect(await servers[0].servers.countFiles('thumbnails')).to.equal(10)
expect(await servers[0].servers.countFiles('cache/thumbnails')).to.equal(5)
})
diff --git a/server/core/models/video/video.ts b/server/core/models/video/video.ts
index f6d0df1f16..70b36f6e3a 100644
--- a/server/core/models/video/video.ts
+++ b/server/core/models/video/video.ts
@@ -1904,16 +1904,16 @@ export class VideoModel extends SequelizeModel<VideoModel> {
throw new Error('Cannot replace thumbnails with an empty array, at least one thumbnail is required')
}
- if (Array.isArray(this.Thumbnails) === false) this.Thumbnails = []
+ let oldThumbnails = Array.isArray(this.Thumbnails)
+ ? [ ...this.Thumbnails ]
+ : []
- let oldThumbnails = [ ...this.Thumbnails ]
+ this.Thumbnails = []
for (const thumbnail of thumbnails) {
thumbnail.videoId = this.id
const savedThumbnail = await thumbnail.save({ transaction })
-
- this.Thumbnails = this.Thumbnails.filter(t => t.id !== savedThumbnail.id)
oldThumbnails = oldThumbnails.filter(t => t.id !== savedThumbnail.id)
this.Thumbnails.push(savedThumbnail)
diff --git a/server/scripts/regenerate-thumbnails.ts b/server/scripts/regenerate-thumbnails.ts
index cf76a9ee9a..73cb2e1d5e 100644
--- a/server/scripts/regenerate-thumbnails.ts
+++ b/server/scripts/regenerate-thumbnails.ts
@@ -1,6 +1,8 @@
import { generateImageFilename, processImage } from '@server/helpers/image-utils.js'
import { CONFIG } from '@server/initializers/config.js'
import { initDatabaseModels } from '@server/initializers/database.js'
+import { federateVideoIfNeeded } from '@server/lib/activitypub/videos/index.js'
+import { JobQueue } from '@server/lib/job-queue/job-queue.js'
import { ThumbnailModel } from '@server/models/video/thumbnail.js'
import { VideoModel } from '@server/models/video/video.js'
import Bluebird from 'bluebird'
@@ -18,6 +20,8 @@ run()
async function run () {
await initDatabaseModels(true)
+ JobQueue.Instance.init()
+
const ids = await VideoModel.listLocalIds()
await Bluebird.map(ids, id => {
@@ -27,7 +31,7 @@ async function run () {
}
async function processVideo (id: number) {
- const video = await VideoModel.loadWithFiles(id)
+ const video = await VideoModel.loadFull(id)
console.log('Processing video %s.', video.name)
@@ -68,5 +72,5 @@ async function processVideo (id: number) {
await oldThumbnail.removeFile()
}
- // Don't federate, remote instances will refresh the thumbnails after a while
+ await federateVideoIfNeeded(video, false)
}