1
0
Fork 0

Better isNewVideo variable/functions name

This commit is contained in:
Chocobozzz 2023-12-15 14:52:12 +01:00
parent bd1dd8fd95
commit af8a47125f
No known key found for this signature in database
GPG key ID: 583A612D890159BE
9 changed files with 24 additions and 17 deletions

View file

@ -269,7 +269,7 @@ export type NotifyPayload =
export interface FederateVideoPayload { export interface FederateVideoPayload {
videoUUID: string videoUUID: string
isNewVideo: boolean isNewVideoForFederation: boolean
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View file

@ -165,7 +165,7 @@ async function addVideoJobsAfterUpload (video: MVideoFullLight, videoFile: MVide
type: 'federate-video' as 'federate-video', type: 'federate-video' as 'federate-video',
payload: { payload: {
videoUUID: video.uuid, videoUUID: video.uuid,
isNewVideo: false isNewVideoForFederation: false
} }
} }
] ]

View file

@ -64,7 +64,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
const videoFileLockReleaser = await VideoPathManager.Instance.lockFiles(videoFromReq.uuid) const videoFileLockReleaser = await VideoPathManager.Instance.lockFiles(videoFromReq.uuid)
try { try {
const { videoInstanceUpdated, isNewVideo } = await sequelizeTypescript.transaction(async t => { const { videoInstanceUpdated, isNewVideoForFederation } = await sequelizeTypescript.transaction(async t => {
// Refresh video since thumbnails to prevent concurrent updates // Refresh video since thumbnails to prevent concurrent updates
const video = await VideoModel.loadFull(videoFromReq.id, t) const video = await VideoModel.loadFull(videoFromReq.id, t)
@ -95,9 +95,15 @@ async function updateVideo (req: express.Request, res: express.Response) {
} }
// Privacy update? // Privacy update?
let isNewVideo = false let isNewVideoForFederation = false
if (videoInfoToUpdate.privacy !== undefined) { if (videoInfoToUpdate.privacy !== undefined) {
isNewVideo = await updateVideoPrivacy({ videoInstance: video, videoInfoToUpdate, hadPrivacyForFederation, transaction: t }) isNewVideoForFederation = await updateVideoPrivacy({
videoInstance: video,
videoInfoToUpdate,
hadPrivacyForFederation,
transaction: t
})
} }
// Force updatedAt attribute change // Force updatedAt attribute change
@ -154,7 +160,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
) )
logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid)) logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid))
return { videoInstanceUpdated, isNewVideo } return { videoInstanceUpdated, isNewVideoForFederation }
}) })
Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
@ -163,7 +169,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
video: videoInstanceUpdated, video: videoInstanceUpdated,
nameChanged: !!videoInfoToUpdate.name, nameChanged: !!videoInfoToUpdate.name,
oldPrivacy, oldPrivacy,
isNewVideo isNewVideoForFederation
}) })
} catch (err) { } catch (err) {
// If the transaction is retried, sequelize will think the object has not changed // If the transaction is retried, sequelize will think the object has not changed
@ -180,6 +186,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
.end() .end()
} }
// Return a boolean indicating if the video is considered as "new" for remote instances in the federation
async function updateVideoPrivacy (options: { async function updateVideoPrivacy (options: {
videoInstance: MVideoFullLight videoInstance: MVideoFullLight
videoInfoToUpdate: VideoUpdate videoInfoToUpdate: VideoUpdate
@ -187,7 +194,7 @@ async function updateVideoPrivacy (options: {
transaction: Transaction transaction: Transaction
}) { }) {
const { videoInstance, videoInfoToUpdate, hadPrivacyForFederation, transaction } = options const { videoInstance, videoInfoToUpdate, hadPrivacyForFederation, transaction } = options
const isNewVideo = videoInstance.isNewVideo(videoInfoToUpdate.privacy) const isNewVideoForFederation = videoInstance.isNewVideoForFederation(videoInfoToUpdate.privacy)
const newPrivacy = forceNumber(videoInfoToUpdate.privacy) as VideoPrivacyType const newPrivacy = forceNumber(videoInfoToUpdate.privacy) as VideoPrivacyType
setVideoPrivacy(videoInstance, newPrivacy) setVideoPrivacy(videoInstance, newPrivacy)
@ -207,7 +214,7 @@ async function updateVideoPrivacy (options: {
await VideoModel.sendDelete(videoInstance, { transaction }) await VideoModel.sendDelete(videoInstance, { transaction })
} }
return isNewVideo return isNewVideoForFederation
} }
function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: VideoUpdate, transaction: Transaction) { function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: VideoUpdate, transaction: Transaction) {

View file

@ -269,7 +269,7 @@ async function addVideoJobsAfterUpload (video: MVideoFullLight, videoFile: MVide
type: 'federate-video' as 'federate-video', type: 'federate-video' as 'federate-video',
payload: { payload: {
videoUUID: video.uuid, videoUUID: video.uuid,
isNewVideo: true isNewVideoForFederation: true
} }
} }
] ]

View file

@ -16,7 +16,7 @@ function processFederateVideo (job: Job) {
const video = await VideoModel.loadFull(payload.videoUUID, t) const video = await VideoModel.loadFull(payload.videoUUID, t)
if (!video) return if (!video) return
return federateVideoIfNeeded(video, payload.isNewVideo, t) return federateVideoIfNeeded(video, payload.isNewVideoForFederation, t)
}) })
}) })
} }

View file

@ -58,7 +58,7 @@ export class UpdateVideosScheduler extends AbstractScheduler {
logger.info('Executing scheduled video update on %s.', video.uuid) logger.info('Executing scheduled video update on %s.', video.uuid)
if (schedule.privacy) { if (schedule.privacy) {
isNewVideo = video.isNewVideo(schedule.privacy) isNewVideo = video.isNewVideoForFederation(schedule.privacy)
oldPrivacy = video.privacy oldPrivacy = video.privacy
setVideoPrivacy(video, schedule.privacy) setVideoPrivacy(video, schedule.privacy)

View file

@ -118,7 +118,7 @@ export async function onVideoStudioEnded (options: {
type: 'federate-video' as 'federate-video', type: 'federate-video' as 'federate-video',
payload: { payload: {
videoUUID: video.uuid, videoUUID: video.uuid,
isNewVideo: false isNewVideoForFederation: false
} }
}, },

View file

@ -137,12 +137,12 @@ export const getCachedVideoDuration = memoizee(getVideoDuration, {
export async function addVideoJobsAfterUpdate (options: { export async function addVideoJobsAfterUpdate (options: {
video: MVideoFullLight video: MVideoFullLight
isNewVideo: boolean isNewVideoForFederation: boolean
nameChanged: boolean nameChanged: boolean
oldPrivacy: VideoPrivacyType oldPrivacy: VideoPrivacyType
}) { }) {
const { video, nameChanged, oldPrivacy, isNewVideo } = options const { video, nameChanged, oldPrivacy, isNewVideoForFederation } = options
const jobs: CreateJobArgument[] = [] const jobs: CreateJobArgument[] = []
const filePathChanged = await moveFilesIfPrivacyChanged(video, oldPrivacy) const filePathChanged = await moveFilesIfPrivacyChanged(video, oldPrivacy)
@ -167,7 +167,7 @@ export async function addVideoJobsAfterUpdate (options: {
type: 'federate-video', type: 'federate-video',
payload: { payload: {
videoUUID: video.uuid, videoUUID: video.uuid,
isNewVideo isNewVideoForFederation
} }
}) })

View file

@ -2004,7 +2004,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
return isStateForFederation(this.state) return isStateForFederation(this.state)
} }
isNewVideo (newPrivacy: VideoPrivacyType) { isNewVideoForFederation (newPrivacy: VideoPrivacyType) {
return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true return this.hasPrivacyForFederation() === false && isPrivacyForFederation(newPrivacy) === true
} }