ActivityPub-federated video streaming platform using P2P directly in your web browser
Refactor AP video logger tags
Chocobozzz908e6ead78cc
diff --git a/server/lib/activitypub/videos/refresh.ts b/server/lib/activitypub/videos/refresh.tsindex da068cde9e..71a4e75b0b 100644--- a/server/lib/activitypub/videos/refresh.ts+++ b/server/lib/activitypub/videos/refresh.ts@@ -8,8 +8,6 @@ import { HttpStatusCode } from '@shared/core-utils'import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'import { APVideoUpdater } from './updater'-const lTags = loggerTagsFactory('ap', 'video', 'refresh')-async function refreshVideoIfNeeded (options: {video: MVideoThumbnailfetchedType: VideoFetchByUrlType@@ -22,11 +20,13 @@ async function refreshVideoIfNeeded (options: {? options.video as MVideoAccountLightBlacklistAllFiles: await VideoModel.loadByUrlAndPopulateAccount(options.video.url)+ const lTags = loggerTagsFactory('ap', 'video', 'refresh', video.uuid, video.url)+try {const { videoObject } = await fetchRemoteVideo(video.url)if (videoObject === undefined) {- logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags(video.uuid))+ logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags())await video.setAsRefreshed()return video@@ -42,14 +42,14 @@ async function refreshVideoIfNeeded (options: {return video} catch (err) {if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) {- logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags(video.uuid))+ logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags())// Video does not exist anymoreawait video.destroy()return undefined}- logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags(video.uuid) })+ logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags() })ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)diff --git a/server/lib/activitypub/videos/shared/abstract-builder.ts b/server/lib/activitypub/videos/shared/abstract-builder.tsindex f8e4d6aa3a..4bd38b40c1 100644--- a/server/lib/activitypub/videos/shared/abstract-builder.ts+++ b/server/lib/activitypub/videos/shared/abstract-builder.ts@@ -43,7 +43,7 @@ export abstract class APVideoAbstractBuilder {video,type: ThumbnailType.MINIATURE}).catch(err => {- logger.warn('Cannot generate thumbnail of %s.', this.videoObject.id, { err, ...this.lTags(video.uuid) })+ logger.warn('Cannot generate thumbnail of %s.', this.videoObject.id, { err, ...this.lTags() })return undefined})diff --git a/server/lib/activitypub/videos/shared/creator.ts b/server/lib/activitypub/videos/shared/creator.tsindex ba3f6f77fd..767bf06952 100644--- a/server/lib/activitypub/videos/shared/creator.ts+++ b/server/lib/activitypub/videos/shared/creator.ts@@ -1,5 +1,5 @@-import { logger, loggerTagsFactory } from '@server/helpers/logger'+import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'import { sequelizeTypescript } from '@server/initializers/database'import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'import { VideoModel } from '@server/models/video/video'@@ -9,14 +9,16 @@ import { APVideoAbstractBuilder } from './abstract-builder'import { getVideoAttributesFromObject } from './object-to-model-attributes'export class APVideoCreator extends APVideoAbstractBuilder {- protected lTags = loggerTagsFactory('ap', 'video', 'create')+ protected lTags: LoggerTagsFnconstructor (protected readonly videoObject: VideoObject) {super()++ this.lTags = loggerTagsFactory('ap', 'video', 'create', this.videoObject.uuid, this.videoObject.id)}async create (waitThumbnail = false) {- logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags(this.videoObject.uuid))+ logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags())const channelActor = await this.getOrCreateVideoChannelFromVideoObject()const channel = channelActor.VideoChannel@@ -57,7 +59,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {transaction: t})- logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags(videoCreated.uuid))+ logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags())return { autoBlacklisted, videoCreated }} catch (err) {diff --git a/server/lib/activitypub/videos/shared/video-sync-attributes.ts b/server/lib/activitypub/videos/shared/video-sync-attributes.tsindex 102d406214..c4e1010054 100644--- a/server/lib/activitypub/videos/shared/video-sync-attributes.ts+++ b/server/lib/activitypub/videos/shared/video-sync-attributes.ts@@ -62,7 +62,7 @@ function syncRates (type: 'like' | 'dislike', video: MVideo, fetchedVideo: Videoconst cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, type, crawlStartDate)return crawlCollectionPage<string>(uri, handler, cleaner)- .catch(err => logger.error('Cannot add rate of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))+ .catch(err => logger.error('Cannot add rate of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))}function syncShares (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {@@ -76,7 +76,7 @@ function syncShares (video: MVideo, fetchedVideo: VideoObject, isSync: boolean)const cleaner = crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate)return crawlCollectionPage<string>(uri, handler, cleaner)- .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))+ .catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))}function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {@@ -90,5 +90,5 @@ function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: booleanconst cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)return crawlCollectionPage<string>(uri, handler, cleaner)- .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))+ .catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))}diff --git a/server/lib/activitypub/videos/updater.ts b/server/lib/activitypub/videos/updater.tsindex 6745e2efd0..3339611fc0 100644--- a/server/lib/activitypub/videos/updater.ts+++ b/server/lib/activitypub/videos/updater.ts@@ -1,6 +1,6 @@import { Transaction } from 'sequelize/types'import { resetSequelizeInstance } from '@server/helpers/database-utils'-import { logger, loggerTagsFactory } from '@server/helpers/logger'+import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'import { sequelizeTypescript } from '@server/initializers/database'import { Notifier } from '@server/lib/notifier'import { PeerTubeSocket } from '@server/lib/peertube-socket'@@ -19,7 +19,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {private readonly oldVideoChannel: MChannelAccountLight- protected lTags = loggerTagsFactory('ap', 'video', 'update')+ protected lTags: LoggerTagsFnconstructor (protected readonly videoObject: VideoObject,@@ -33,12 +33,14 @@ export class APVideoUpdater extends APVideoAbstractBuilder {this.oldVideoChannel = this.video.VideoChannelthis.videoFieldsSave = this.video.toJSON()++ this.lTags = loggerTagsFactory('ap', 'video', 'update', video.uuid, video.url)}async update (overrideTo?: string[]) {logger.debug('Updating remote video "%s".', this.videoObject.uuid,- { videoObject: this.videoObject, ...this.lTags(this.videoObject.uuid) }+ { videoObject: this.videoObject, ...this.lTags() })try {@@ -82,7 +84,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {PeerTubeSocket.Instance.sendVideoViewsUpdate(videoUpdated)}- logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags(this.videoObject.uuid))+ logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags())return videoUpdated} catch (err) {@@ -158,7 +160,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {}// This is just a debug because we will retry the insert- logger.debug('Cannot update the remote video.', { err, ...this.lTags(this.videoObject.uuid) })+ logger.debug('Cannot update the remote video.', { err, ...this.lTags() })throw err}}