diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts index e7e87a967..c7b49d6e4 100644 --- a/server/lib/activitypub/actors/get.ts +++ b/server/lib/activitypub/actors/get.ts @@ -3,7 +3,7 @@ import { checkUrlsSameHost, getAPId } from '@server/helpers/activitypub' import { retryTransactionWrapper } from '@server/helpers/database-utils' import { logger } from '@server/helpers/logger' import { JobQueue } from '@server/lib/job-queue' -import { ActorFetchByUrlType, fetchActorByUrl } from '@server/lib/model-loaders' +import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders' import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' import { ActivityPubActor } from '@shared/models' import { refreshActorIfNeeded } from './refresh' @@ -25,7 +25,7 @@ function getOrCreateAPActor ( async function getOrCreateAPActor ( activityActor: string | ActivityPubActor, - fetchType: ActorFetchByUrlType = 'association-ids', + fetchType: ActorLoadByUrlType = 'association-ids', recurseIfNeeded = true, updateCollections = false ): Promise { @@ -73,8 +73,8 @@ export { // --------------------------------------------------------------------------- -async function loadActorFromDB (actorUrl: string, fetchType: ActorFetchByUrlType) { - let actor = await fetchActorByUrl(actorUrl, fetchType) +async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType) { + let actor = await loadActorByUrl(actorUrl, fetchType) // Orphan actor (not associated to an account of channel) so recreate it if (actor && (!actor.Account && !actor.VideoChannel)) { diff --git a/server/lib/activitypub/actors/refresh.ts b/server/lib/activitypub/actors/refresh.ts index 9f2289bfa..9758649a5 100644 --- a/server/lib/activitypub/actors/refresh.ts +++ b/server/lib/activitypub/actors/refresh.ts @@ -1,6 +1,6 @@ import { logger } from '@server/helpers/logger' import { PeerTubeRequestError } from '@server/helpers/requests' -import { ActorFetchByUrlType } from '@server/lib/model-loaders' +import { ActorLoadByUrlType } from '@server/lib/model-loaders' import { ActorModel } from '@server/models/actor/actor' import { MActorAccountChannelId, MActorFull } from '@server/types/models' import { HttpStatusCode } from '@shared/core-utils' @@ -10,7 +10,7 @@ import { getUrlFromWebfinger } from './webfinger' async function refreshActorIfNeeded ( actorArg: T, - fetchedType: ActorFetchByUrlType + fetchedType: ActorLoadByUrlType ): Promise<{ actor: T | MActorFull, refreshed: boolean }> { if (!actorArg.isOutdated()) return { actor: actorArg, refreshed: false } diff --git a/server/lib/activitypub/videos/get.ts b/server/lib/activitypub/videos/get.ts index 38ba4978c..5d1f92bba 100644 --- a/server/lib/activitypub/videos/get.ts +++ b/server/lib/activitypub/videos/get.ts @@ -1,7 +1,7 @@ import { getAPId } from '@server/helpers/activitypub' import { retryTransactionWrapper } from '@server/helpers/database-utils' import { JobQueue } from '@server/lib/job-queue' -import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/lib/model-loaders' +import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders' import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' import { refreshVideoIfNeeded } from './refresh' import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' @@ -47,7 +47,7 @@ async function getOrCreateAPVideo ( // Get video url const videoUrl = getAPId(options.videoObject) - let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) + let videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType) if (videoFromDatabase) { if (allowRefresh === true) { @@ -71,7 +71,7 @@ async function getOrCreateAPVideo ( } catch (err) { // Maybe a concurrent getOrCreateAPVideo call created this video if (err.name === 'SequelizeUniqueConstraintError') { - const alreadyCreatedVideo = await fetchVideoByUrl(videoUrl, fetchType) + const alreadyCreatedVideo = await loadVideoByUrl(videoUrl, fetchType) if (alreadyCreatedVideo) return { video: alreadyCreatedVideo, created: false } } @@ -87,7 +87,7 @@ export { // --------------------------------------------------------------------------- -async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoFetchByUrlType, syncParam: SyncParam) { +async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) { if (!video.isOutdated()) return video const refreshOptions = { diff --git a/server/lib/activitypub/videos/refresh.ts b/server/lib/activitypub/videos/refresh.ts index f1a3a6fac..82b3b13bf 100644 --- a/server/lib/activitypub/videos/refresh.ts +++ b/server/lib/activitypub/videos/refresh.ts @@ -1,7 +1,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' import { PeerTubeRequestError } from '@server/helpers/requests' import { ActorFollowScoreCache } from '@server/lib/files-cache' -import { VideoFetchByUrlType } from '@server/lib/model-loaders' +import { VideoLoadByUrlType } from '@server/lib/model-loaders' import { VideoModel } from '@server/models/video/video' import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' import { HttpStatusCode } from '@shared/core-utils' @@ -10,7 +10,7 @@ import { APVideoUpdater } from './updater' async function refreshVideoIfNeeded (options: { video: MVideoThumbnail - fetchedType: VideoFetchByUrlType + fetchedType: VideoLoadByUrlType syncParam: SyncParam }): Promise { if (!options.video.isOutdated()) return options.video diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts index 2508a4793..f1c7d01b6 100644 --- a/server/lib/job-queue/handlers/activitypub-refresher.ts +++ b/server/lib/job-queue/handlers/activitypub-refresher.ts @@ -1,7 +1,7 @@ import * as Bull from 'bull' import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists' import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos' -import { fetchVideoByUrl } from '@server/lib/model-loaders' +import { loadVideoByUrl } from '@server/lib/model-loaders' import { RefreshPayload } from '@shared/models' import { logger } from '../../../helpers/logger' import { ActorModel } from '../../../models/actor/actor' @@ -30,7 +30,7 @@ async function refreshVideo (videoUrl: string) { const fetchType = 'all' as 'all' const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } - const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) + const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType) if (videoFromDatabase) { const refreshOptions = { video: videoFromDatabase, diff --git a/server/lib/model-loaders/actor.ts b/server/lib/model-loaders/actor.ts index 234cb344f..1355d8ee2 100644 --- a/server/lib/model-loaders/actor.ts +++ b/server/lib/model-loaders/actor.ts @@ -2,15 +2,16 @@ import { ActorModel } from '../../models/actor/actor' import { MActorAccountChannelId, MActorFull } from '../../types/models' -type ActorFetchByUrlType = 'all' | 'association-ids' +type ActorLoadByUrlType = 'all' | 'association-ids' -function fetchActorByUrl (url: string, fetchType: ActorFetchByUrlType): Promise { +function loadActorByUrl (url: string, fetchType: ActorLoadByUrlType): Promise { if (fetchType === 'all') return ActorModel.loadByUrlAndPopulateAccountAndChannel(url) if (fetchType === 'association-ids') return ActorModel.loadByUrl(url) } export { - ActorFetchByUrlType, - fetchActorByUrl + ActorLoadByUrlType, + + loadActorByUrl } diff --git a/server/lib/model-loaders/video.ts b/server/lib/model-loaders/video.ts index 7aaf00e89..597c94395 100644 --- a/server/lib/model-loaders/video.ts +++ b/server/lib/model-loaders/video.ts @@ -8,21 +8,21 @@ import { MVideoWithRights } from '@server/types/models' -type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' +type VideoLoadType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' -function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise -function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise -function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise -function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise -function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise -function fetchVideo ( +function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise +function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise +function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise +function loadVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise +function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise +function loadVideo ( id: number | string, - fetchType: VideoFetchType, + fetchType: VideoLoadType, userId?: number ): Promise -function fetchVideo ( +function loadVideo ( id: number | string, - fetchType: VideoFetchType, + fetchType: VideoLoadType, userId?: number ): Promise { if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) @@ -36,18 +36,18 @@ function fetchVideo ( if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) } -type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' +type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' -function fetchVideoByUrl (url: string, fetchType: 'all'): Promise -function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise -function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise -function fetchVideoByUrl ( +function loadVideoByUrl (url: string, fetchType: 'all'): Promise +function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise +function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise +function loadVideoByUrl ( url: string, - fetchType: VideoFetchByUrlType + fetchType: VideoLoadByUrlType ): Promise -function fetchVideoByUrl ( +function loadVideoByUrl ( url: string, - fetchType: VideoFetchByUrlType + fetchType: VideoLoadByUrlType ): Promise { if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) @@ -57,8 +57,9 @@ function fetchVideoByUrl ( } export { - VideoFetchType, - VideoFetchByUrlType, - fetchVideo, - fetchVideoByUrl + VideoLoadType, + VideoLoadByUrlType, + + loadVideo, + loadVideoByUrl } diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index ab117635e..e1015d7fd 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -1,7 +1,7 @@ import * as express from 'express' import { query } from 'express-validator' import { join } from 'path' -import { fetchVideo } from '@server/lib/model-loaders' +import { loadVideo } from '@server/lib/model-loaders' import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' @@ -85,7 +85,7 @@ const oembedValidator = [ } if (isVideo) { - const video = await fetchVideo(elementId, 'all') + const video = await loadVideo(elementId, 'all') if (!video) { return res.fail({ diff --git a/server/middlewares/validators/shared/videos.ts b/server/middlewares/validators/shared/videos.ts index a6dad4374..3134f623d 100644 --- a/server/middlewares/validators/shared/videos.ts +++ b/server/middlewares/validators/shared/videos.ts @@ -1,5 +1,5 @@ import { Response } from 'express' -import { fetchVideo, VideoFetchType } from '@server/lib/model-loaders' +import { loadVideo, VideoLoadType } from '@server/lib/model-loaders' import { VideoChannelModel } from '@server/models/video/video-channel' import { VideoFileModel } from '@server/models/video/video-file' import { @@ -15,10 +15,10 @@ import { import { HttpStatusCode } from '@shared/core-utils' import { UserRight } from '@shared/models' -async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { +async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') { const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined - const video = await fetchVideo(id, fetchType, userId) + const video = await loadVideo(id, fetchType, userId) if (video === null) { res.fail({