Skip to content

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

fetch -> load

Chocobozzz868fce62f868
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts
index e7e87a9674..c7b49d6e48 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<MActorFullActor | MActorAccountChannelId> {
@@ -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 9f2289bfa2..9758649a56 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 <T extends MActorFull | MActorAccountChannelId> (
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 38ba4978c2..5d1f92bba4 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 f1a3a6facf..82b3b13bfb 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<MVideoThumbnail> {
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 2508a47932..f1c7d01b6e 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 234cb344f0..1355d8ee2c 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<MActorFull | MActorAccountChannelId> {
+function loadActorByUrl (url: string, fetchType: ActorLoadByUrlType): Promise<MActorFull | MActorAccountChannelId> {
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 7aaf00e895..597c94395b 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<MVideoFullLight>
-function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
-function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
-function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
-function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
-function fetchVideo (
+function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
+function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
+function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
+function loadVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
+function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
+function loadVideo (
id: number | string,
- fetchType: VideoFetchType,
+ fetchType: VideoLoadType,
userId?: number
): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
-function fetchVideo (
+function loadVideo (
id: number | string,
- fetchType: VideoFetchType,
+ fetchType: VideoLoadType,
userId?: number
): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
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<MVideoAccountLightBlacklistAllFiles>
-function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
-function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
-function fetchVideoByUrl (
+function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
+function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
+function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
+function loadVideoByUrl (
url: string,
- fetchType: VideoFetchByUrlType
+ fetchType: VideoLoadByUrlType
): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
-function fetchVideoByUrl (
+function loadVideoByUrl (
url: string,
- fetchType: VideoFetchByUrlType
+ fetchType: VideoLoadByUrlType
): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
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 ab117635eb..e1015d7fdd 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 a6dad4374b..3134f623d9 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({