aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/lib/activitypub/actors/get.ts8
-rw-r--r--server/lib/activitypub/actors/refresh.ts4
-rw-r--r--server/lib/activitypub/videos/get.ts8
-rw-r--r--server/lib/activitypub/videos/refresh.ts4
-rw-r--r--server/lib/job-queue/handlers/activitypub-refresher.ts4
-rw-r--r--server/lib/model-loaders/actor.ts9
-rw-r--r--server/lib/model-loaders/video.ts45
-rw-r--r--server/middlewares/validators/oembed.ts4
-rw-r--r--server/middlewares/validators/shared/videos.ts6
9 files changed, 47 insertions, 45 deletions
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'
3import { retryTransactionWrapper } from '@server/helpers/database-utils' 3import { retryTransactionWrapper } from '@server/helpers/database-utils'
4import { logger } from '@server/helpers/logger' 4import { logger } from '@server/helpers/logger'
5import { JobQueue } from '@server/lib/job-queue' 5import { JobQueue } from '@server/lib/job-queue'
6import { ActorFetchByUrlType, fetchActorByUrl } from '@server/lib/model-loaders' 6import { ActorLoadByUrlType, loadActorByUrl } from '@server/lib/model-loaders'
7import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models' 7import { MActor, MActorAccountChannelId, MActorAccountChannelIdActor, MActorAccountId, MActorFullActor } from '@server/types/models'
8import { ActivityPubActor } from '@shared/models' 8import { ActivityPubActor } from '@shared/models'
9import { refreshActorIfNeeded } from './refresh' 9import { refreshActorIfNeeded } from './refresh'
@@ -25,7 +25,7 @@ function getOrCreateAPActor (
25 25
26async function getOrCreateAPActor ( 26async function getOrCreateAPActor (
27 activityActor: string | ActivityPubActor, 27 activityActor: string | ActivityPubActor,
28 fetchType: ActorFetchByUrlType = 'association-ids', 28 fetchType: ActorLoadByUrlType = 'association-ids',
29 recurseIfNeeded = true, 29 recurseIfNeeded = true,
30 updateCollections = false 30 updateCollections = false
31): Promise<MActorFullActor | MActorAccountChannelId> { 31): Promise<MActorFullActor | MActorAccountChannelId> {
@@ -73,8 +73,8 @@ export {
73 73
74// --------------------------------------------------------------------------- 74// ---------------------------------------------------------------------------
75 75
76async function loadActorFromDB (actorUrl: string, fetchType: ActorFetchByUrlType) { 76async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType) {
77 let actor = await fetchActorByUrl(actorUrl, fetchType) 77 let actor = await loadActorByUrl(actorUrl, fetchType)
78 78
79 // Orphan actor (not associated to an account of channel) so recreate it 79 // Orphan actor (not associated to an account of channel) so recreate it
80 if (actor && (!actor.Account && !actor.VideoChannel)) { 80 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 @@
1import { logger } from '@server/helpers/logger' 1import { logger } from '@server/helpers/logger'
2import { PeerTubeRequestError } from '@server/helpers/requests' 2import { PeerTubeRequestError } from '@server/helpers/requests'
3import { ActorFetchByUrlType } from '@server/lib/model-loaders' 3import { ActorLoadByUrlType } from '@server/lib/model-loaders'
4import { ActorModel } from '@server/models/actor/actor' 4import { ActorModel } from '@server/models/actor/actor'
5import { MActorAccountChannelId, MActorFull } from '@server/types/models' 5import { MActorAccountChannelId, MActorFull } from '@server/types/models'
6import { HttpStatusCode } from '@shared/core-utils' 6import { HttpStatusCode } from '@shared/core-utils'
@@ -10,7 +10,7 @@ import { getUrlFromWebfinger } from './webfinger'
10 10
11async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannelId> ( 11async function refreshActorIfNeeded <T extends MActorFull | MActorAccountChannelId> (
12 actorArg: T, 12 actorArg: T,
13 fetchedType: ActorFetchByUrlType 13 fetchedType: ActorLoadByUrlType
14): Promise<{ actor: T | MActorFull, refreshed: boolean }> { 14): Promise<{ actor: T | MActorFull, refreshed: boolean }> {
15 if (!actorArg.isOutdated()) return { actor: actorArg, refreshed: false } 15 if (!actorArg.isOutdated()) return { actor: actorArg, refreshed: false }
16 16
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 @@
1import { getAPId } from '@server/helpers/activitypub' 1import { getAPId } from '@server/helpers/activitypub'
2import { retryTransactionWrapper } from '@server/helpers/database-utils' 2import { retryTransactionWrapper } from '@server/helpers/database-utils'
3import { JobQueue } from '@server/lib/job-queue' 3import { JobQueue } from '@server/lib/job-queue'
4import { fetchVideoByUrl, VideoFetchByUrlType } from '@server/lib/model-loaders' 4import { loadVideoByUrl, VideoLoadByUrlType } from '@server/lib/model-loaders'
5import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models' 5import { MVideoAccountLightBlacklistAllFiles, MVideoImmutable, MVideoThumbnail } from '@server/types/models'
6import { refreshVideoIfNeeded } from './refresh' 6import { refreshVideoIfNeeded } from './refresh'
7import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared' 7import { APVideoCreator, fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
@@ -47,7 +47,7 @@ async function getOrCreateAPVideo (
47 47
48 // Get video url 48 // Get video url
49 const videoUrl = getAPId(options.videoObject) 49 const videoUrl = getAPId(options.videoObject)
50 let videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) 50 let videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType)
51 51
52 if (videoFromDatabase) { 52 if (videoFromDatabase) {
53 if (allowRefresh === true) { 53 if (allowRefresh === true) {
@@ -71,7 +71,7 @@ async function getOrCreateAPVideo (
71 } catch (err) { 71 } catch (err) {
72 // Maybe a concurrent getOrCreateAPVideo call created this video 72 // Maybe a concurrent getOrCreateAPVideo call created this video
73 if (err.name === 'SequelizeUniqueConstraintError') { 73 if (err.name === 'SequelizeUniqueConstraintError') {
74 const alreadyCreatedVideo = await fetchVideoByUrl(videoUrl, fetchType) 74 const alreadyCreatedVideo = await loadVideoByUrl(videoUrl, fetchType)
75 if (alreadyCreatedVideo) return { video: alreadyCreatedVideo, created: false } 75 if (alreadyCreatedVideo) return { video: alreadyCreatedVideo, created: false }
76 } 76 }
77 77
@@ -87,7 +87,7 @@ export {
87 87
88// --------------------------------------------------------------------------- 88// ---------------------------------------------------------------------------
89 89
90async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoFetchByUrlType, syncParam: SyncParam) { 90async function scheduleRefresh (video: MVideoThumbnail, fetchType: VideoLoadByUrlType, syncParam: SyncParam) {
91 if (!video.isOutdated()) return video 91 if (!video.isOutdated()) return video
92 92
93 const refreshOptions = { 93 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 @@
1import { logger, loggerTagsFactory } from '@server/helpers/logger' 1import { logger, loggerTagsFactory } from '@server/helpers/logger'
2import { PeerTubeRequestError } from '@server/helpers/requests' 2import { PeerTubeRequestError } from '@server/helpers/requests'
3import { ActorFollowScoreCache } from '@server/lib/files-cache' 3import { ActorFollowScoreCache } from '@server/lib/files-cache'
4import { VideoFetchByUrlType } from '@server/lib/model-loaders' 4import { VideoLoadByUrlType } from '@server/lib/model-loaders'
5import { VideoModel } from '@server/models/video/video' 5import { VideoModel } from '@server/models/video/video'
6import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models' 6import { MVideoAccountLightBlacklistAllFiles, MVideoThumbnail } from '@server/types/models'
7import { HttpStatusCode } from '@shared/core-utils' 7import { HttpStatusCode } from '@shared/core-utils'
@@ -10,7 +10,7 @@ import { APVideoUpdater } from './updater'
10 10
11async function refreshVideoIfNeeded (options: { 11async function refreshVideoIfNeeded (options: {
12 video: MVideoThumbnail 12 video: MVideoThumbnail
13 fetchedType: VideoFetchByUrlType 13 fetchedType: VideoLoadByUrlType
14 syncParam: SyncParam 14 syncParam: SyncParam
15}): Promise<MVideoThumbnail> { 15}): Promise<MVideoThumbnail> {
16 if (!options.video.isOutdated()) return options.video 16 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 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists' 2import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlists'
3import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos' 3import { refreshVideoIfNeeded } from '@server/lib/activitypub/videos'
4import { fetchVideoByUrl } from '@server/lib/model-loaders' 4import { loadVideoByUrl } from '@server/lib/model-loaders'
5import { RefreshPayload } from '@shared/models' 5import { RefreshPayload } from '@shared/models'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
7import { ActorModel } from '../../../models/actor/actor' 7import { ActorModel } from '../../../models/actor/actor'
@@ -30,7 +30,7 @@ async function refreshVideo (videoUrl: string) {
30 const fetchType = 'all' as 'all' 30 const fetchType = 'all' as 'all'
31 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true } 31 const syncParam = { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true }
32 32
33 const videoFromDatabase = await fetchVideoByUrl(videoUrl, fetchType) 33 const videoFromDatabase = await loadVideoByUrl(videoUrl, fetchType)
34 if (videoFromDatabase) { 34 if (videoFromDatabase) {
35 const refreshOptions = { 35 const refreshOptions = {
36 video: videoFromDatabase, 36 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 @@
2import { ActorModel } from '../../models/actor/actor' 2import { ActorModel } from '../../models/actor/actor'
3import { MActorAccountChannelId, MActorFull } from '../../types/models' 3import { MActorAccountChannelId, MActorFull } from '../../types/models'
4 4
5type ActorFetchByUrlType = 'all' | 'association-ids' 5type ActorLoadByUrlType = 'all' | 'association-ids'
6 6
7function fetchActorByUrl (url: string, fetchType: ActorFetchByUrlType): Promise<MActorFull | MActorAccountChannelId> { 7function loadActorByUrl (url: string, fetchType: ActorLoadByUrlType): Promise<MActorFull | MActorAccountChannelId> {
8 if (fetchType === 'all') return ActorModel.loadByUrlAndPopulateAccountAndChannel(url) 8 if (fetchType === 'all') return ActorModel.loadByUrlAndPopulateAccountAndChannel(url)
9 9
10 if (fetchType === 'association-ids') return ActorModel.loadByUrl(url) 10 if (fetchType === 'association-ids') return ActorModel.loadByUrl(url)
11} 11}
12 12
13export { 13export {
14 ActorFetchByUrlType, 14 ActorLoadByUrlType,
15 fetchActorByUrl 15
16 loadActorByUrl
16} 17}
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 {
8 MVideoWithRights 8 MVideoWithRights
9} from '@server/types/models' 9} from '@server/types/models'
10 10
11type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' 11type VideoLoadType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
12 12
13function fetchVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight> 13function loadVideo (id: number | string, fetchType: 'all', userId?: number): Promise<MVideoFullLight>
14function fetchVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> 14function loadVideo (id: number | string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
15function fetchVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail> 15function loadVideo (id: number | string, fetchType: 'only-video', userId?: number): Promise<MVideoThumbnail>
16function fetchVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights> 16function loadVideo (id: number | string, fetchType: 'only-video-with-rights', userId?: number): Promise<MVideoWithRights>
17function fetchVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail> 17function loadVideo (id: number | string, fetchType: 'id' | 'none', userId?: number): Promise<MVideoIdThumbnail>
18function fetchVideo ( 18function loadVideo (
19 id: number | string, 19 id: number | string,
20 fetchType: VideoFetchType, 20 fetchType: VideoLoadType,
21 userId?: number 21 userId?: number
22): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> 22): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable>
23function fetchVideo ( 23function loadVideo (
24 id: number | string, 24 id: number | string,
25 fetchType: VideoFetchType, 25 fetchType: VideoLoadType,
26 userId?: number 26 userId?: number
27): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> { 27): Promise<MVideoFullLight | MVideoThumbnail | MVideoWithRights | MVideoIdThumbnail | MVideoImmutable> {
28 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId) 28 if (fetchType === 'all') return VideoModel.loadAndPopulateAccountAndServerAndTags(id, undefined, userId)
@@ -36,18 +36,18 @@ function fetchVideo (
36 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id) 36 if (fetchType === 'id' || fetchType === 'none') return VideoModel.loadOnlyId(id)
37} 37}
38 38
39type VideoFetchByUrlType = 'all' | 'only-video' | 'only-immutable-attributes' 39type VideoLoadByUrlType = 'all' | 'only-video' | 'only-immutable-attributes'
40 40
41function fetchVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles> 41function loadVideoByUrl (url: string, fetchType: 'all'): Promise<MVideoAccountLightBlacklistAllFiles>
42function fetchVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable> 42function loadVideoByUrl (url: string, fetchType: 'only-immutable-attributes'): Promise<MVideoImmutable>
43function fetchVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail> 43function loadVideoByUrl (url: string, fetchType: 'only-video'): Promise<MVideoThumbnail>
44function fetchVideoByUrl ( 44function loadVideoByUrl (
45 url: string, 45 url: string,
46 fetchType: VideoFetchByUrlType 46 fetchType: VideoLoadByUrlType
47): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> 47): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable>
48function fetchVideoByUrl ( 48function loadVideoByUrl (
49 url: string, 49 url: string,
50 fetchType: VideoFetchByUrlType 50 fetchType: VideoLoadByUrlType
51): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> { 51): Promise<MVideoAccountLightBlacklistAllFiles | MVideoThumbnail | MVideoImmutable> {
52 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url) 52 if (fetchType === 'all') return VideoModel.loadByUrlAndPopulateAccount(url)
53 53
@@ -57,8 +57,9 @@ function fetchVideoByUrl (
57} 57}
58 58
59export { 59export {
60 VideoFetchType, 60 VideoLoadType,
61 VideoFetchByUrlType, 61 VideoLoadByUrlType,
62 fetchVideo, 62
63 fetchVideoByUrl 63 loadVideo,
64 loadVideoByUrl
64} 65}
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator' 2import { query } from 'express-validator'
3import { join } from 'path' 3import { join } from 'path'
4import { fetchVideo } from '@server/lib/model-loaders' 4import { loadVideo } from '@server/lib/model-loaders'
5import { VideoPlaylistModel } from '@server/models/video/video-playlist' 5import { VideoPlaylistModel } from '@server/models/video/video-playlist'
6import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' 6import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
@@ -85,7 +85,7 @@ const oembedValidator = [
85 } 85 }
86 86
87 if (isVideo) { 87 if (isVideo) {
88 const video = await fetchVideo(elementId, 'all') 88 const video = await loadVideo(elementId, 'all')
89 89
90 if (!video) { 90 if (!video) {
91 return res.fail({ 91 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 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { fetchVideo, VideoFetchType } from '@server/lib/model-loaders' 2import { loadVideo, VideoLoadType } from '@server/lib/model-loaders'
3import { VideoChannelModel } from '@server/models/video/video-channel' 3import { VideoChannelModel } from '@server/models/video/video-channel'
4import { VideoFileModel } from '@server/models/video/video-file' 4import { VideoFileModel } from '@server/models/video/video-file'
5import { 5import {
@@ -15,10 +15,10 @@ import {
15import { HttpStatusCode } from '@shared/core-utils' 15import { HttpStatusCode } from '@shared/core-utils'
16import { UserRight } from '@shared/models' 16import { UserRight } from '@shared/models'
17 17
18async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { 18async function doesVideoExist (id: number | string, res: Response, fetchType: VideoLoadType = 'all') {
19 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined 19 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
20 20
21 const video = await fetchVideo(id, fetchType, userId) 21 const video = await loadVideo(id, fetchType, userId)
22 22
23 if (video === null) { 23 if (video === null) {
24 res.fail({ 24 res.fail({