Skip to content

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

Don't update publishedAt with null scheduleUpdate

Chocobozzz08029076f949
diff --git a/packages/tests/src/api/videos/single-server.ts b/packages/tests/src/api/videos/single-server.ts
index 1370a23691..7a0701be0a 100644
--- a/packages/tests/src/api/videos/single-server.ts
+++ b/packages/tests/src/api/videos/single-server.ts
@@ -16,13 +16,13 @@ import {
} from '@peertube/peertube-server-commands'
describe('Test a single server', function () {
-
function runSuite (mode: 'legacy' | 'resumable') {
let server: PeerTubeServer = null
let videoId: number | string
let videoId2: string
let videoUUID = ''
let videosListBase: any[] = null
+ let publishedAt: Date
const getCheckAttributes = () => ({
name: 'my super name',
@@ -215,8 +215,12 @@ describe('Test a single server', function () {
this.timeout(120000)
const videos = new Set([
- 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
- 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
+ 'video_short.mp4',
+ 'video_short.ogv',
+ 'video_short.webm',
+ 'video_short1.webm',
+ 'video_short2.webm',
+ 'video_short3.webm'
])
for (const video of videos) {
@@ -242,8 +246,10 @@ describe('Test a single server', function () {
expect(data).to.be.an('array')
expect(data).to.have.lengthOf(6)
- const videosByName: { [ name: string ]: Video } = {}
- data.forEach(v => { videosByName[v.name] = v })
+ const videosByName: { [name: string]: Video } = {}
+ data.forEach(v => {
+ videosByName[v.name] = v
+ })
expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
expect(videosByName['video_short.ogv name'].duration).to.equal(5)
@@ -338,6 +344,9 @@ describe('Test a single server', function () {
})
it('Should update a video', async function () {
+ const video = await server.videos.get({ id: videoId })
+ publishedAt = new Date(video.publishedAt)
+
const attributes = {
name: 'my super video updated',
category: 4,
@@ -360,6 +369,17 @@ describe('Test a single server', function () {
const video = await server.videos.get({ id: videoId })
await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() })
+
+ expect(new Date(video.publishedAt).getTime()).to.equal(publishedAt.getTime())
+ })
+
+ it('Should not update the publication date with scheduleAt = null', async function () {
+ const attributes = { name: 'my super video updated', scheduleUpdate: null }
+ await server.videos.update({ id: videoId, attributes })
+
+ const video = await server.videos.get({ id: videoId })
+
+ expect(new Date(video.publishedAt).getTime()).to.equal(publishedAt.getTime())
})
it('Should update only the tags of a video', async function () {
diff --git a/packages/tests/src/api/videos/video-schedule-update.ts b/packages/tests/src/api/videos/video-schedule-update.ts
index 9ac7b41a72..175c39c276 100644
--- a/packages/tests/src/api/videos/video-schedule-update.ts
+++ b/packages/tests/src/api/videos/video-schedule-update.ts
@@ -80,14 +80,20 @@ describe('Test video update scheduler', function () {
it('Should wait some seconds and have the video in public privacy', async function () {
this.timeout(50000)
- await wait(15000)
- await waitJobs(servers)
-
- for (const server of servers) {
+ const check = async (server: PeerTubeServer) => {
const { total, data } = await server.videos.list()
- expect(total).to.equal(1)
- expect(data[0].name).to.equal('video 1')
+ return total === 1 && data[0].name === 'video 1'
+ }
+
+ while (true) {
+ const allGood = await Promise.all(servers.map(s => check(s)))
+
+ if (allGood.every(g => g)) {
+ break
+ }
+
+ await wait(500)
}
})
diff --git a/server/core/controllers/api/videos/update.ts b/server/core/controllers/api/videos/update.ts
index 912d74264f..73b9ece2c0 100644
--- a/server/core/controllers/api/videos/update.ts
+++ b/server/core/controllers/api/videos/update.ts
@@ -264,10 +264,12 @@ async function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate
}
if (videoInfoToUpdate.scheduleUpdate === null) {
- videoInstance.publishedAt = new Date()
- await videoInstance.save({ transaction })
+ const deleted = await ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
- await ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
+ if (deleted) {
+ videoInstance.publishedAt = new Date()
+ await videoInstance.save({ transaction })
+ }
}
}