Skip to content

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

Use schedule at date for publishedAt

Chocobozzzba3bb0f142fa
diff --git a/packages/tests/src/api/videos/video-schedule-update.ts b/packages/tests/src/api/videos/video-schedule-update.ts
index 37c4373271..9ac7b41a72 100644
--- a/packages/tests/src/api/videos/video-schedule-update.ts
+++ b/packages/tests/src/api/videos/video-schedule-update.ts
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { expect } from 'chai'
import { wait } from '@peertube/peertube-core-utils'
import { VideoPrivacy } from '@peertube/peertube-models'
import {
@@ -11,6 +10,7 @@ import {
setAccessTokensToServers,
waitJobs
} from '@peertube/peertube-server-commands'
+import { expect } from 'chai'
function in15Seconds () {
const now = new Date()
@@ -35,16 +35,21 @@ describe('Test video update scheduler', function () {
})
it('Should upload a video and schedule an update in 10 seconds', async function () {
+ const updateAt = in15Seconds().toISOString()
+
const attributes = {
name: 'video 1',
privacy: VideoPrivacy.PRIVATE,
scheduleUpdate: {
- updateAt: in15Seconds().toISOString(),
+ updateAt,
privacy: VideoPrivacy.PUBLIC
}
}
- await servers[0].videos.upload({ attributes })
+ const { uuid } = await servers[0].videos.upload({ attributes })
+
+ const video = await servers[0].videos.getWithToken({ id: uuid })
+ expect(video.publishedAt).to.equal(updateAt)
await waitJobs(servers)
})
@@ -99,15 +104,21 @@ describe('Test video update scheduler', function () {
})
it('Should update a video by scheduling an update', async function () {
+ const updateAt = in15Seconds().toISOString()
+
const attributes = {
name: 'video 2 updated',
scheduleUpdate: {
- updateAt: in15Seconds().toISOString(),
+ updateAt,
privacy: VideoPrivacy.PUBLIC
}
}
await servers[0].videos.update({ id: video2UUID, attributes })
+
+ const video = await servers[0].videos.getWithToken({ id: video2UUID })
+ expect(video.publishedAt).to.equal(updateAt)
+
await waitJobs(servers)
})
@@ -156,6 +167,33 @@ describe('Test video update scheduler', function () {
}
})
+ it('Should abort a scheduled update', async function () {
+ const updateAt = in15Seconds().toISOString()
+
+ const attributes = {
+ name: 'video 1',
+ privacy: VideoPrivacy.PRIVATE,
+ scheduleUpdate: {
+ updateAt,
+ privacy: VideoPrivacy.PUBLIC
+ }
+ }
+
+ const { uuid } = await servers[0].videos.upload({ attributes })
+
+ {
+ const video = await servers[0].videos.getWithToken({ id: uuid })
+ expect(video.publishedAt).to.equal(updateAt)
+ }
+
+ await servers[0].videos.update({ id: uuid, attributes: { scheduleUpdate: null } })
+
+ {
+ const video = await servers[0].videos.getWithToken({ id: uuid })
+ expect(video.publishedAt).to.not.equal(updateAt)
+ }
+ })
+
after(async function () {
await cleanupTests(servers)
})
diff --git a/server/core/controllers/api/videos/update.ts b/server/core/controllers/api/videos/update.ts
index 74165d0a69..912d74264f 100644
--- a/server/core/controllers/api/videos/update.ts
+++ b/server/core/controllers/api/videos/update.ts
@@ -247,15 +247,27 @@ async function updateVideoPrivacy (options: {
return isNewVideoForFederation
}
-function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: VideoUpdate, transaction: Transaction) {
+async function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: VideoUpdate, transaction: Transaction) {
if (videoInfoToUpdate.scheduleUpdate) {
- return ScheduleVideoUpdateModel.upsert({
+ const updateAt = new Date(videoInfoToUpdate.scheduleUpdate.updateAt)
+
+ videoInstance.publishedAt = updateAt
+ await videoInstance.save({ transaction })
+
+ await ScheduleVideoUpdateModel.upsert({
videoId: videoInstance.id,
- updateAt: new Date(videoInfoToUpdate.scheduleUpdate.updateAt),
+ updateAt,
privacy: videoInfoToUpdate.scheduleUpdate.privacy || null
}, { transaction })
- } else if (videoInfoToUpdate.scheduleUpdate === null) {
- return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
+
+ return
+ }
+
+ if (videoInfoToUpdate.scheduleUpdate === null) {
+ videoInstance.publishedAt = new Date()
+ await videoInstance.save({ transaction })
+
+ await ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction)
}
}
diff --git a/server/core/lib/local-video-creator.ts b/server/core/lib/local-video-creator.ts
index a84556dccd..ef82d49f9a 100644
--- a/server/core/lib/local-video-creator.ts
+++ b/server/core/lib/local-video-creator.ts
@@ -314,6 +314,10 @@ export class LocalVideoCreator {
? new Date(videoInfo.originallyPublishedAt)
: null,
+ publishedAt: this.videoAttributes.scheduleUpdate?.updateAt
+ ? new Date(this.videoAttributes.scheduleUpdate?.updateAt)
+ : undefined,
+
uuid: buildUUID(),
duration: videoInfo.duration
}