Allow to update a live with untouched privacy
This commit is contained in:
parent
8b95440c8a
commit
e7c89cc3f3
4 changed files with 34 additions and 5 deletions
|
@ -9,6 +9,7 @@ import { Video, VideoCaptionEdit, VideoCaptionService, VideoDetails, VideoEdit,
|
||||||
import { LiveVideoService } from '@app/shared/shared-video-live'
|
import { LiveVideoService } from '@app/shared/shared-video-live'
|
||||||
import { LoadingBarService } from '@ngx-loading-bar/core'
|
import { LoadingBarService } from '@ngx-loading-bar/core'
|
||||||
import { logger } from '@root-helpers/logger'
|
import { logger } from '@root-helpers/logger'
|
||||||
|
import { pick, simpleObjectsDeepEqual } from '@shared/core-utils'
|
||||||
import { LiveVideo, LiveVideoUpdate, VideoPrivacy } from '@shared/models'
|
import { LiveVideo, LiveVideoUpdate, VideoPrivacy } from '@shared/models'
|
||||||
import { VideoSource } from '@shared/models/videos/video-source'
|
import { VideoSource } from '@shared/models/videos/video-source'
|
||||||
import { hydrateFormFromVideo } from './shared/video-edit-utils'
|
import { hydrateFormFromVideo } from './shared/video-edit-utils'
|
||||||
|
@ -134,8 +135,8 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't update live attributes if they did not change
|
// Don't update live attributes if they did not change
|
||||||
const liveChanged = Object.keys(liveVideoUpdate)
|
const baseVideo = pick(this.liveVideo, Object.keys(liveVideoUpdate) as (keyof LiveVideoUpdate)[])
|
||||||
.some(key => this.liveVideo[key] !== liveVideoUpdate[key])
|
const liveChanged = !simpleObjectsDeepEqual(baseVideo, liveVideoUpdate)
|
||||||
if (!liveChanged) return of(undefined)
|
if (!liveChanged) return of(undefined)
|
||||||
|
|
||||||
return this.liveVideoService.updateLive(this.videoEdit.id, liveVideoUpdate)
|
return this.liveVideoService.updateLive(this.videoEdit.id, liveVideoUpdate)
|
||||||
|
|
|
@ -234,7 +234,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([
|
||||||
if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req)
|
if (!await doesVideoExist(req.params.id, res)) return cleanUpReqFiles(req)
|
||||||
|
|
||||||
const video = getVideoWithAttributes(res)
|
const video = getVideoWithAttributes(res)
|
||||||
if (req.body.privacy && video.isLive && video.state !== VideoState.WAITING_FOR_LIVE) {
|
if (video.isLive && video.privacy !== req.body.privacy && video.state !== VideoState.WAITING_FOR_LIVE) {
|
||||||
return res.fail({ message: 'Cannot update privacy of a live that has already started' })
|
return res.fail({ message: 'Cannot update privacy of a live that has already started' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -553,9 +553,15 @@ describe('Test video lives API validator', function () {
|
||||||
const ffmpegCommand = sendRTMPStream({ rtmpBaseUrl: live.rtmpUrl, streamKey: live.streamKey })
|
const ffmpegCommand = sendRTMPStream({ rtmpBaseUrl: live.rtmpUrl, streamKey: live.streamKey })
|
||||||
|
|
||||||
await command.waitUntilPublished({ videoId: video.id })
|
await command.waitUntilPublished({ videoId: video.id })
|
||||||
|
|
||||||
await server.videos.update({
|
await server.videos.update({
|
||||||
id: video.id,
|
id: video.id,
|
||||||
attributes: { privacy: VideoPrivacy.PUBLIC },
|
attributes: { privacy: VideoPrivacy.PUBLIC } // Same privacy, it's fine
|
||||||
|
})
|
||||||
|
|
||||||
|
await server.videos.update({
|
||||||
|
id: video.id,
|
||||||
|
attributes: { privacy: VideoPrivacy.UNLISTED },
|
||||||
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,32 @@ function shallowCopy <T> (o: T): T {
|
||||||
return Object.assign(Object.create(Object.getPrototypeOf(o)), o)
|
return Object.assign(Object.create(Object.getPrototypeOf(o)), o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function simpleObjectsDeepEqual (a: any, b: any) {
|
||||||
|
if (a === b) return true
|
||||||
|
|
||||||
|
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const keysA = Object.keys(a)
|
||||||
|
const keysB = Object.keys(b)
|
||||||
|
|
||||||
|
if (keysA.length !== keysB.length) return false
|
||||||
|
|
||||||
|
for (const key of keysA) {
|
||||||
|
if (!keysB.includes(key)) return false
|
||||||
|
|
||||||
|
if (!simpleObjectsDeepEqual(a[key], b[key])) return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
pick,
|
pick,
|
||||||
omit,
|
omit,
|
||||||
getKeys,
|
getKeys,
|
||||||
shallowCopy,
|
shallowCopy,
|
||||||
sortObjectComparator
|
sortObjectComparator,
|
||||||
|
simpleObjectsDeepEqual
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue