aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/actor.ts2
-rw-r--r--server/lib/activitypub/follow.ts2
-rw-r--r--server/lib/activitypub/index.ts9
-rw-r--r--server/lib/activitypub/process/process-follow.ts2
-rw-r--r--server/lib/activitypub/send/send-create.ts2
-rw-r--r--server/lib/activitypub/send/send-delete.ts2
-rw-r--r--server/lib/activitypub/send/send-update.ts2
-rw-r--r--server/lib/activitypub/send/utils.ts2
-rw-r--r--server/lib/activitypub/share.ts2
-rw-r--r--server/lib/activitypub/videos.ts3
-rw-r--r--server/lib/avatar.ts2
-rw-r--r--server/lib/emailer.ts14
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts9
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-broadcast.ts9
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-fetcher.ts13
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-unicast.ts9
-rw-r--r--server/lib/job-queue/handlers/activitypub-refresher.ts10
-rw-r--r--server/lib/job-queue/handlers/email.ts5
-rw-r--r--server/lib/job-queue/handlers/utils/activitypub-http-utils.ts11
-rw-r--r--server/lib/job-queue/handlers/video-file-import.ts6
-rw-r--r--server/lib/job-queue/handlers/video-import.ts23
-rw-r--r--server/lib/job-queue/handlers/video-redundancy.ts5
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts42
-rw-r--r--server/lib/job-queue/handlers/video-views.ts2
-rw-r--r--server/lib/job-queue/job-queue.ts28
-rw-r--r--server/lib/notifier.ts2
-rw-r--r--server/lib/redundancy.ts2
-rw-r--r--server/lib/schedulers/auto-follow-index-instances.ts2
-rw-r--r--server/lib/schedulers/update-videos-scheduler.ts2
-rw-r--r--server/lib/schedulers/videos-redundancy-scheduler.ts4
-rw-r--r--server/lib/video-comment.ts2
-rw-r--r--server/lib/video-paths.ts2
-rw-r--r--server/lib/video-playlist.ts2
-rw-r--r--server/lib/videos.ts36
34 files changed, 65 insertions, 205 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index 8132ac135..c743dcf3f 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -19,7 +19,6 @@ import { AvatarModel } from '../../models/avatar/avatar'
19import { ServerModel } from '../../models/server/server' 19import { ServerModel } from '../../models/server/server'
20import { VideoChannelModel } from '../../models/video/video-channel' 20import { VideoChannelModel } from '../../models/video/video-channel'
21import { JobQueue } from '../job-queue' 21import { JobQueue } from '../job-queue'
22import { getServerActor } from '../../helpers/utils'
23import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor' 22import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor'
24import { sequelizeTypescript } from '../../initializers/database' 23import { sequelizeTypescript } from '../../initializers/database'
25import { 24import {
@@ -36,6 +35,7 @@ import {
36 MChannel 35 MChannel
37} from '../../typings/models' 36} from '../../typings/models'
38import { extname } from 'path' 37import { extname } from 'path'
38import { getServerActor } from '@server/models/application/application'
39 39
40// Set account keys, this could be long so process after the account creation and do not block the client 40// Set account keys, this could be long so process after the account creation and do not block the client
41function setAsyncActorKeys <T extends MActor> (actor: T) { 41function setAsyncActorKeys <T extends MActor> (actor: T) {
diff --git a/server/lib/activitypub/follow.ts b/server/lib/activitypub/follow.ts
index a1c95504e..3b5ad47c9 100644
--- a/server/lib/activitypub/follow.ts
+++ b/server/lib/activitypub/follow.ts
@@ -3,8 +3,8 @@ import { CONFIG } from '../../initializers/config'
3import { SERVER_ACTOR_NAME } from '../../initializers/constants' 3import { SERVER_ACTOR_NAME } from '../../initializers/constants'
4import { JobQueue } from '../job-queue' 4import { JobQueue } from '../job-queue'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { getServerActor } from '../../helpers/utils'
7import { ServerModel } from '../../models/server/server' 6import { ServerModel } from '../../models/server/server'
7import { getServerActor } from '@server/models/application/application'
8 8
9async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) { 9async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) {
10 if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return 10 if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return
diff --git a/server/lib/activitypub/index.ts b/server/lib/activitypub/index.ts
deleted file mode 100644
index d8c7d83b7..000000000
--- a/server/lib/activitypub/index.ts
+++ /dev/null
@@ -1,9 +0,0 @@
1export * from './process'
2export * from './send'
3export * from './actor'
4export * from './share'
5export * from './playlist'
6export * from './videos'
7export * from './video-comments'
8export * from './video-rates'
9export * from './url'
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index db7fb8568..8f7828e41 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -7,11 +7,11 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
7import { sendAccept, sendReject } from '../send' 7import { sendAccept, sendReject } from '../send'
8import { Notifier } from '../../notifier' 8import { Notifier } from '../../notifier'
9import { getAPId } from '../../../helpers/activitypub' 9import { getAPId } from '../../../helpers/activitypub'
10import { getServerActor } from '../../../helpers/utils'
11import { CONFIG } from '../../../initializers/config' 10import { CONFIG } from '../../../initializers/config'
12import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 11import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
13import { MActorFollowActors, MActorSignature } from '../../../typings/models' 12import { MActorFollowActors, MActorSignature } from '../../../typings/models'
14import { autoFollowBackIfNeeded } from '../follow' 13import { autoFollowBackIfNeeded } from '../follow'
14import { getServerActor } from '@server/models/application/application'
15 15
16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { 16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) {
17 const { activity, byActor } = options 17 const { activity, byActor } = options
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index e2fa061e8..0635c7b66 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -6,7 +6,6 @@ import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unic
6import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience' 6import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience'
7import { logger } from '../../../helpers/logger' 7import { logger } from '../../../helpers/logger'
8import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 8import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
9import { getServerActor } from '../../../helpers/utils'
10import { 9import {
11 MActorLight, 10 MActorLight,
12 MCommentOwnerVideo, 11 MCommentOwnerVideo,
@@ -17,6 +16,7 @@ import {
17 MVideoRedundancyStreamingPlaylistVideo 16 MVideoRedundancyStreamingPlaylistVideo
18} from '../../../typings/models' 17} from '../../../typings/models'
19import { ContextType } from '@server/helpers/activitypub' 18import { ContextType } from '@server/helpers/activitypub'
19import { getServerActor } from '@server/models/application/application'
20 20
21async function sendCreateVideo (video: MVideoAP, t: Transaction) { 21async function sendCreateVideo (video: MVideoAP, t: Transaction) {
22 if (!video.hasPrivacyForFederation()) return undefined 22 if (!video.hasPrivacyForFederation()) return undefined
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index 3225ebf32..fd3f06dec 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -7,9 +7,9 @@ import { getDeleteActivityPubUrl } from '../url'
7import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' 7import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
8import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' 8import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
9import { logger } from '../../../helpers/logger' 9import { logger } from '../../../helpers/logger'
10import { getServerActor } from '../../../helpers/utils'
11import { MCommentOwnerVideoReply, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video' 10import { MCommentOwnerVideoReply, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video'
12import { MActorUrl } from '../../../typings/models' 11import { MActorUrl } from '../../../typings/models'
12import { getServerActor } from '@server/models/application/application'
13 13
14async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) { 14async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
15 logger.info('Creating job to broadcast delete of video %s.', video.url) 15 logger.info('Creating job to broadcast delete of video %s.', video.url)
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index 2b01ca5e7..7a4cf3f56 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -9,7 +9,6 @@ import { broadcastToFollowers, sendVideoRelatedActivity } from './utils'
9import { audiencify, getActorsInvolvedInVideo, getAudience } from '../audience' 9import { audiencify, getActorsInvolvedInVideo, getAudience } from '../audience'
10import { logger } from '../../../helpers/logger' 10import { logger } from '../../../helpers/logger'
11import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 11import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
12import { getServerActor } from '../../../helpers/utils'
13import { 12import {
14 MAccountDefault, 13 MAccountDefault,
15 MActor, 14 MActor,
@@ -20,6 +19,7 @@ import {
20 MVideoPlaylistFull, 19 MVideoPlaylistFull,
21 MVideoRedundancyVideo 20 MVideoRedundancyVideo
22} from '../../../typings/models' 21} from '../../../typings/models'
22import { getServerActor } from '@server/models/application/application'
23 23
24async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) { 24async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, t: Transaction, overrodeByActor?: MActor) {
25 const video = videoArg as MVideoAP 25 const video = videoArg as MVideoAP
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts
index 6fd53d71b..0dfcc51be 100644
--- a/server/lib/activitypub/send/utils.ts
+++ b/server/lib/activitypub/send/utils.ts
@@ -5,10 +5,10 @@ import { ActorModel } from '../../../models/activitypub/actor'
5import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 5import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6import { JobQueue } from '../../job-queue' 6import { JobQueue } from '../../job-queue'
7import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' 7import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
8import { getServerActor } from '../../../helpers/utils'
9import { afterCommitIfTransaction } from '../../../helpers/database-utils' 8import { afterCommitIfTransaction } from '../../../helpers/database-utils'
10import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../typings/models' 9import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../typings/models'
11import { ContextType } from '@server/helpers/activitypub' 10import { ContextType } from '@server/helpers/activitypub'
11import { getServerActor } from '@server/models/application/application'
12 12
13async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { 13async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
14 byActor: MActorLight 14 byActor: MActorLight
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index a7c645062..d2cbc59a8 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -1,5 +1,4 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { getServerActor } from '../../helpers/utils'
3import { VideoShareModel } from '../../models/video/video-share' 2import { VideoShareModel } from '../../models/video/video-share'
4import { sendUndoAnnounce, sendVideoAnnounce } from './send' 3import { sendUndoAnnounce, sendVideoAnnounce } from './send'
5import { getVideoAnnounceActivityPubUrl } from './url' 4import { getVideoAnnounceActivityPubUrl } from './url'
@@ -10,6 +9,7 @@ import { logger } from '../../helpers/logger'
10import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' 9import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
11import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' 10import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
12import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../typings/models/video' 11import { MChannelActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../typings/models/video'
12import { getServerActor } from '@server/models/application/application'
13 13
14async function shareVideoByServerAndChannel (video: MVideoAccountLight, t: Transaction) { 14async function shareVideoByServerAndChannel (video: MVideoAccountLight, t: Transaction) {
15 if (!video.hasPrivacyForFederation()) return undefined 15 if (!video.hasPrivacyForFederation()) return undefined
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 62f589272..7d16bd390 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -6,7 +6,7 @@ import {
6 ActivityHashTagObject, 6 ActivityHashTagObject,
7 ActivityMagnetUrlObject, 7 ActivityMagnetUrlObject,
8 ActivityPlaylistSegmentHashesObject, 8 ActivityPlaylistSegmentHashesObject,
9 ActivityPlaylistUrlObject, 9 ActivityPlaylistUrlObject, ActivitypubHttpFetcherPayload,
10 ActivityTagObject, 10 ActivityTagObject,
11 ActivityUrlObject, 11 ActivityUrlObject,
12 ActivityVideoUrlObject, 12 ActivityVideoUrlObject,
@@ -38,7 +38,6 @@ import { sendCreateVideo, sendUpdateVideo } from './send'
38import { isArray } from '../../helpers/custom-validators/misc' 38import { isArray } from '../../helpers/custom-validators/misc'
39import { VideoCaptionModel } from '../../models/video/video-caption' 39import { VideoCaptionModel } from '../../models/video/video-caption'
40import { JobQueue } from '../job-queue' 40import { JobQueue } from '../job-queue'
41import { ActivitypubHttpFetcherPayload } from '../job-queue/handlers/activitypub-http-fetcher'
42import { createRates } from './video-rates' 41import { createRates } from './video-rates'
43import { addVideoShares, shareVideoByServerAndChannel } from './share' 42import { addVideoShares, shareVideoByServerAndChannel } from './share'
44import { fetchVideoByUrl, VideoFetchByUrlType } from '../../helpers/video' 43import { fetchVideoByUrl, VideoFetchByUrlType } from '../../helpers/video'
diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts
index 3de45dd19..282d834a2 100644
--- a/server/lib/avatar.ts
+++ b/server/lib/avatar.ts
@@ -1,7 +1,7 @@
1import 'multer' 1import 'multer'
2import { sendUpdateActor } from './activitypub/send' 2import { sendUpdateActor } from './activitypub/send'
3import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants' 3import { AVATARS_SIZE, LRU_CACHE, QUEUE_CONCURRENCY } from '../initializers/constants'
4import { updateActorAvatarInstance } from './activitypub' 4import { updateActorAvatarInstance } from './activitypub/actor'
5import { processImage } from '../helpers/image-utils' 5import { processImage } from '../helpers/image-utils'
6import { extname, join } from 'path' 6import { extname, join } from 'path'
7import { retryTransactionWrapper } from '../helpers/database-utils' 7import { retryTransactionWrapper } from '../helpers/database-utils'
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 5a99edc7f..45d57fd28 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -3,7 +3,6 @@ import { isTestInstance } from '../helpers/core-utils'
3import { bunyanLogger, logger } from '../helpers/logger' 3import { bunyanLogger, logger } from '../helpers/logger'
4import { CONFIG, isEmailEnabled } from '../initializers/config' 4import { CONFIG, isEmailEnabled } from '../initializers/config'
5import { JobQueue } from './job-queue' 5import { JobQueue } from './job-queue'
6import { EmailPayload } from './job-queue/handlers/email'
7import { readFileSync } from 'fs-extra' 6import { readFileSync } from 'fs-extra'
8import { WEBSERVER } from '../initializers/constants' 7import { WEBSERVER } from '../initializers/constants'
9import { 8import {
@@ -16,15 +15,7 @@ import {
16} from '../typings/models/video' 15} from '../typings/models/video'
17import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models' 16import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models'
18import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' 17import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
19 18import { EmailPayload } from '@shared/models'
20type SendEmailOptions = {
21 to: string[]
22 subject: string
23 text: string
24
25 fromDisplayName?: string
26 replyTo?: string
27}
28 19
29class Emailer { 20class Emailer {
30 21
@@ -507,6 +498,5 @@ class Emailer {
507// --------------------------------------------------------------------------- 498// ---------------------------------------------------------------------------
508 499
509export { 500export {
510 Emailer, 501 Emailer
511 SendEmailOptions
512} 502}
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index e467c5b1b..7034c10d0 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -11,14 +11,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
11import { Notifier } from '../../notifier' 11import { Notifier } from '../../notifier'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { MActor, MActorFollowActors, MActorFull } from '../../../typings/models' 13import { MActor, MActorFollowActors, MActorFull } from '../../../typings/models'
14 14import { ActivitypubFollowPayload } from '@shared/models'
15export type ActivitypubFollowPayload = {
16 followerActorId: number
17 name: string
18 host: string
19 isAutoFollow?: boolean
20 assertIsChannel?: boolean
21}
22 15
23async function processActivityPubFollow (job: Bull.Job) { 16async function processActivityPubFollow (job: Bull.Job) {
24 const payload = job.data as ActivitypubFollowPayload 17 const payload = job.data as ActivitypubFollowPayload
diff --git a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
index 7d9dd61e9..e4d3dbbff 100644
--- a/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-broadcast.ts
@@ -5,14 +5,7 @@ import { doRequest } from '../../../helpers/requests'
5import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 5import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
6import { BROADCAST_CONCURRENCY, JOB_REQUEST_TIMEOUT } from '../../../initializers/constants' 6import { BROADCAST_CONCURRENCY, JOB_REQUEST_TIMEOUT } from '../../../initializers/constants'
7import { ActorFollowScoreCache } from '../../files-cache' 7import { ActorFollowScoreCache } from '../../files-cache'
8import { ContextType } from '@server/helpers/activitypub' 8import { ActivitypubHttpBroadcastPayload } from '@shared/models'
9
10export type ActivitypubHttpBroadcastPayload = {
11 uris: string[]
12 signatureActorId?: number
13 body: any
14 contextType?: ContextType
15}
16 9
17async function processActivityPubHttpBroadcast (job: Bull.Job) { 10async function processActivityPubHttpBroadcast (job: Bull.Job) {
18 logger.info('Processing ActivityPub broadcast in job %d.', job.id) 11 logger.info('Processing ActivityPub broadcast in job %d.', job.id)
diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts
index 0182c5169..524aadc27 100644
--- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts
@@ -5,22 +5,15 @@ import { processActivities } from '../../activitypub/process'
5import { addVideoComments } from '../../activitypub/video-comments' 5import { addVideoComments } from '../../activitypub/video-comments'
6import { crawlCollectionPage } from '../../activitypub/crawl' 6import { crawlCollectionPage } from '../../activitypub/crawl'
7import { VideoModel } from '../../../models/video/video' 7import { VideoModel } from '../../../models/video/video'
8import { addVideoShares, createRates } from '../../activitypub' 8import { addVideoShares } from '../../activitypub/share'
9import { createRates } from '../../activitypub/video-rates'
9import { createAccountPlaylists } from '../../activitypub/playlist' 10import { createAccountPlaylists } from '../../activitypub/playlist'
10import { AccountModel } from '../../../models/account/account' 11import { AccountModel } from '../../../models/account/account'
11import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 12import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
12import { VideoShareModel } from '../../../models/video/video-share' 13import { VideoShareModel } from '../../../models/video/video-share'
13import { VideoCommentModel } from '../../../models/video/video-comment' 14import { VideoCommentModel } from '../../../models/video/video-comment'
14import { MAccountDefault, MVideoFullLight } from '../../../typings/models' 15import { MAccountDefault, MVideoFullLight } from '../../../typings/models'
15 16import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models'
16type FetchType = 'activity' | 'video-likes' | 'video-dislikes' | 'video-shares' | 'video-comments' | 'account-playlists'
17
18export type ActivitypubHttpFetcherPayload = {
19 uri: string
20 type: FetchType
21 videoId?: number
22 accountId?: number
23}
24 17
25async function processActivityPubHttpFetcher (job: Bull.Job) { 18async function processActivityPubHttpFetcher (job: Bull.Job) {
26 logger.info('Processing ActivityPub fetcher in job %d.', job.id) 19 logger.info('Processing ActivityPub fetcher in job %d.', job.id)
diff --git a/server/lib/job-queue/handlers/activitypub-http-unicast.ts b/server/lib/job-queue/handlers/activitypub-http-unicast.ts
index 6b71e2891..b65eeb677 100644
--- a/server/lib/job-queue/handlers/activitypub-http-unicast.ts
+++ b/server/lib/job-queue/handlers/activitypub-http-unicast.ts
@@ -4,14 +4,7 @@ import { doRequest } from '../../../helpers/requests'
4import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' 4import { buildGlobalHeaders, buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
5import { JOB_REQUEST_TIMEOUT } from '../../../initializers/constants' 5import { JOB_REQUEST_TIMEOUT } from '../../../initializers/constants'
6import { ActorFollowScoreCache } from '../../files-cache' 6import { ActorFollowScoreCache } from '../../files-cache'
7import { ContextType } from '@server/helpers/activitypub' 7import { ActivitypubHttpUnicastPayload } from '@shared/models'
8
9export type ActivitypubHttpUnicastPayload = {
10 uri: string
11 signatureActorId?: number
12 body: any
13 contextType?: ContextType
14}
15 8
16async function processActivityPubHttpUnicast (job: Bull.Job) { 9async function processActivityPubHttpUnicast (job: Bull.Job) {
17 logger.info('Processing ActivityPub unicast in job %d.', job.id) 10 logger.info('Processing ActivityPub unicast in job %d.', job.id)
diff --git a/server/lib/job-queue/handlers/activitypub-refresher.ts b/server/lib/job-queue/handlers/activitypub-refresher.ts
index 4d6c38cfa..666e56868 100644
--- a/server/lib/job-queue/handlers/activitypub-refresher.ts
+++ b/server/lib/job-queue/handlers/activitypub-refresher.ts
@@ -1,14 +1,12 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { fetchVideoByUrl } from '../../../helpers/video' 3import { fetchVideoByUrl } from '../../../helpers/video'
4import { refreshActorIfNeeded, refreshVideoIfNeeded, refreshVideoPlaylistIfNeeded } from '../../activitypub' 4import { refreshActorIfNeeded } from '../../activitypub/actor'
5import { refreshVideoIfNeeded } from '../../activitypub/videos'
5import { ActorModel } from '../../../models/activitypub/actor' 6import { ActorModel } from '../../../models/activitypub/actor'
6import { VideoPlaylistModel } from '../../../models/video/video-playlist' 7import { VideoPlaylistModel } from '../../../models/video/video-playlist'
7 8import { RefreshPayload } from '@shared/models'
8export type RefreshPayload = { 9import { refreshVideoPlaylistIfNeeded } from '@server/lib/activitypub/playlist'
9 type: 'video' | 'video-playlist' | 'actor'
10 url: string
11}
12 10
13async function refreshAPObject (job: Bull.Job) { 11async function refreshAPObject (job: Bull.Job) {
14 const payload = job.data as RefreshPayload 12 const payload = job.data as RefreshPayload
diff --git a/server/lib/job-queue/handlers/email.ts b/server/lib/job-queue/handlers/email.ts
index 62701222c..3157731e2 100644
--- a/server/lib/job-queue/handlers/email.ts
+++ b/server/lib/job-queue/handlers/email.ts
@@ -1,8 +1,7 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { Emailer, SendEmailOptions } from '../../emailer' 3import { Emailer } from '../../emailer'
4 4import { EmailPayload } from '@shared/models'
5export type EmailPayload = SendEmailOptions
6 5
7async function processEmail (job: Bull.Job) { 6async function processEmail (job: Bull.Job) {
8 const payload = job.data as EmailPayload 7 const payload = job.data as EmailPayload
diff --git a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
index 258ffabee..437ea06fc 100644
--- a/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
+++ b/server/lib/job-queue/handlers/utils/activitypub-http-utils.ts
@@ -1,9 +1,9 @@
1import { buildSignedActivity, ContextType } from '../../../../helpers/activitypub' 1import { buildSignedActivity, ContextType } from '../../../../helpers/activitypub'
2import { getServerActor } from '../../../../helpers/utils'
3import { ActorModel } from '../../../../models/activitypub/actor' 2import { ActorModel } from '../../../../models/activitypub/actor'
4import { sha256 } from '../../../../helpers/core-utils'
5import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants' 3import { ACTIVITY_PUB, HTTP_SIGNATURE } from '../../../../initializers/constants'
6import { MActor } from '../../../../typings/models' 4import { MActor } from '../../../../typings/models'
5import { getServerActor } from '@server/models/application/application'
6import { buildDigest } from '@server/helpers/peertube-crypto'
7 7
8type Payload = { body: any, contextType?: ContextType, signatureActorId?: number } 8type Payload = { body: any, contextType?: ContextType, signatureActorId?: number }
9 9
@@ -48,14 +48,7 @@ function buildGlobalHeaders (body: any) {
48 } 48 }
49} 49}
50 50
51function buildDigest (body: any) {
52 const rawBody = typeof body === 'string' ? body : JSON.stringify(body)
53
54 return 'SHA-256=' + sha256(rawBody, 'base64')
55}
56
57export { 51export {
58 buildDigest,
59 buildGlobalHeaders, 52 buildGlobalHeaders,
60 computeBody, 53 computeBody,
61 buildSignedRequestOptions 54 buildSignedRequestOptions
diff --git a/server/lib/job-queue/handlers/video-file-import.ts b/server/lib/job-queue/handlers/video-file-import.ts
index be9e7d181..ae11f1de3 100644
--- a/server/lib/job-queue/handlers/video-file-import.ts
+++ b/server/lib/job-queue/handlers/video-file-import.ts
@@ -9,11 +9,7 @@ import { extname } from 'path'
9import { MVideoFile, MVideoWithFile } from '@server/typings/models' 9import { MVideoFile, MVideoWithFile } from '@server/typings/models'
10import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 10import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
11import { getVideoFilePath } from '@server/lib/video-paths' 11import { getVideoFilePath } from '@server/lib/video-paths'
12 12import { VideoFileImportPayload } from '@shared/models'
13export type VideoFileImportPayload = {
14 videoUUID: string
15 filePath: string
16}
17 13
18async function processVideoFileImport (job: Bull.Job) { 14async function processVideoFileImport (job: Bull.Job) {
19 const payload = job.data as VideoFileImportPayload 15 const payload = job.data as VideoFileImportPayload
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 6cdae5b03..ad549c6fc 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -7,8 +7,8 @@ import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } fro
7import { extname } from 'path' 7import { extname } from 'path'
8import { VideoFileModel } from '../../../models/video/video-file' 8import { VideoFileModel } from '../../../models/video/video-file'
9import { VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants' 9import { VIDEO_IMPORT_TIMEOUT } from '../../../initializers/constants'
10import { VideoState } from '../../../../shared' 10import { VideoImportPayload, VideoImportTorrentPayload, VideoImportYoutubeDLPayload, VideoState } from '../../../../shared'
11import { federateVideoIfNeeded } from '../../activitypub' 11import { federateVideoIfNeeded } from '../../activitypub/videos'
12import { VideoModel } from '../../../models/video/video' 12import { VideoModel } from '../../../models/video/video'
13import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent' 13import { createTorrentAndSetInfoHash, downloadWebTorrentVideo } from '../../../helpers/webtorrent'
14import { getSecureTorrentName } from '../../../helpers/utils' 14import { getSecureTorrentName } from '../../../helpers/utils'
@@ -21,24 +21,7 @@ import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
21import { MThumbnail } from '../../../typings/models/video/thumbnail' 21import { MThumbnail } from '../../../typings/models/video/thumbnail'
22import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import' 22import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import'
23import { getVideoFilePath } from '@server/lib/video-paths' 23import { getVideoFilePath } from '@server/lib/video-paths'
24import { addOptimizeOrMergeAudioJob } from '@server/lib/videos' 24import { addOptimizeOrMergeAudioJob } from '@server/helpers/video'
25
26type VideoImportYoutubeDLPayload = {
27 type: 'youtube-dl'
28 videoImportId: number
29
30 generateThumbnail: boolean
31 generatePreview: boolean
32
33 fileExt?: string
34}
35
36type VideoImportTorrentPayload = {
37 type: 'magnet-uri' | 'torrent-file'
38 videoImportId: number
39}
40
41export type VideoImportPayload = VideoImportYoutubeDLPayload | VideoImportTorrentPayload
42 25
43async function processVideoImport (job: Bull.Job) { 26async function processVideoImport (job: Bull.Job) {
44 const payload = job.data as VideoImportPayload 27 const payload = job.data as VideoImportPayload
diff --git a/server/lib/job-queue/handlers/video-redundancy.ts b/server/lib/job-queue/handlers/video-redundancy.ts
index 319d7090e..6296dab05 100644
--- a/server/lib/job-queue/handlers/video-redundancy.ts
+++ b/server/lib/job-queue/handlers/video-redundancy.ts
@@ -1,10 +1,7 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { VideosRedundancyScheduler } from '@server/lib/schedulers/videos-redundancy-scheduler' 3import { VideosRedundancyScheduler } from '@server/lib/schedulers/videos-redundancy-scheduler'
4 4import { VideoRedundancyPayload } from '@shared/models'
5export type VideoRedundancyPayload = {
6 videoId: number
7}
8 5
9async function processVideoRedundancy (job: Bull.Job) { 6async function processVideoRedundancy (job: Bull.Job) {
10 const payload = job.data as VideoRedundancyPayload 7 const payload = job.data as VideoRedundancyPayload
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index c020057c9..46add57d4 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -1,9 +1,14 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { VideoResolution } from '../../../../shared' 2import {
3 MergeAudioTranscodingPayload,
4 NewResolutionTranscodingPayload,
5 OptimizeTranscodingPayload,
6 VideoTranscodingPayload
7} from '../../../../shared'
3import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
4import { VideoModel } from '../../../models/video/video' 9import { VideoModel } from '../../../models/video/video'
5import { JobQueue } from '../job-queue' 10import { JobQueue } from '../job-queue'
6import { federateVideoIfNeeded } from '../../activitypub' 11import { federateVideoIfNeeded } from '../../activitypub/videos'
7import { retryTransactionWrapper } from '../../../helpers/database-utils' 12import { retryTransactionWrapper } from '../../../helpers/database-utils'
8import { sequelizeTypescript } from '../../../initializers' 13import { sequelizeTypescript } from '../../../initializers'
9import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' 14import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
@@ -12,39 +17,6 @@ import { Notifier } from '../../notifier'
12import { CONFIG } from '../../../initializers/config' 17import { CONFIG } from '../../../initializers/config'
13import { MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/typings/models' 18import { MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/typings/models'
14 19
15interface BaseTranscodingPayload {
16 videoUUID: string
17 isNewVideo?: boolean
18}
19
20interface HLSTranscodingPayload extends BaseTranscodingPayload {
21 type: 'hls'
22 isPortraitMode?: boolean
23 resolution: VideoResolution
24 copyCodecs: boolean
25}
26
27interface NewResolutionTranscodingPayload extends BaseTranscodingPayload {
28 type: 'new-resolution'
29 isPortraitMode?: boolean
30 resolution: VideoResolution
31}
32
33interface MergeAudioTranscodingPayload extends BaseTranscodingPayload {
34 type: 'merge-audio'
35 resolution: VideoResolution
36}
37
38interface OptimizeTranscodingPayload extends BaseTranscodingPayload {
39 type: 'optimize'
40}
41
42export type VideoTranscodingPayload =
43 HLSTranscodingPayload
44 | NewResolutionTranscodingPayload
45 | OptimizeTranscodingPayload
46 | MergeAudioTranscodingPayload
47
48async function processVideoTranscoding (job: Bull.Job) { 20async function processVideoTranscoding (job: Bull.Job) {
49 const payload = job.data as VideoTranscodingPayload 21 const payload = job.data as VideoTranscodingPayload
50 logger.info('Processing video file in job %d.', job.id) 22 logger.info('Processing video file in job %d.', job.id)
diff --git a/server/lib/job-queue/handlers/video-views.ts b/server/lib/job-queue/handlers/video-views.ts
index 2258cd029..7211df237 100644
--- a/server/lib/job-queue/handlers/video-views.ts
+++ b/server/lib/job-queue/handlers/video-views.ts
@@ -3,7 +3,7 @@ import { logger } from '../../../helpers/logger'
3import { VideoModel } from '../../../models/video/video' 3import { VideoModel } from '../../../models/video/video'
4import { VideoViewModel } from '../../../models/video/video-views' 4import { VideoViewModel } from '../../../models/video/video-views'
5import { isTestInstance } from '../../../helpers/core-utils' 5import { isTestInstance } from '../../../helpers/core-utils'
6import { federateVideoIfNeeded } from '../../activitypub' 6import { federateVideoIfNeeded } from '../../activitypub/videos'
7 7
8async function processVideosViews () { 8async function processVideosViews () {
9 const lastHour = new Date() 9 const lastHour = new Date()
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index 14acace7d..d8d64caaf 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -1,19 +1,25 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { JobState, JobType } from '../../../shared/models' 2import {
3 ActivitypubFollowPayload,
4 ActivitypubHttpBroadcastPayload,
5 ActivitypubHttpFetcherPayload, ActivitypubHttpUnicastPayload, EmailPayload,
6 JobState,
7 JobType, RefreshPayload, VideoFileImportPayload, VideoImportPayload, VideoRedundancyPayload, VideoTranscodingPayload
8} from '../../../shared/models'
3import { logger } from '../../helpers/logger' 9import { logger } from '../../helpers/logger'
4import { Redis } from '../redis' 10import { Redis } from '../redis'
5import { JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers/constants' 11import { JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers/constants'
6import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' 12import { processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast'
7import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' 13import { processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'
8import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' 14import { processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast'
9import { EmailPayload, processEmail } from './handlers/email' 15import { processEmail } from './handlers/email'
10import { processVideoTranscoding, VideoTranscodingPayload } from './handlers/video-transcoding' 16import { processVideoTranscoding} from './handlers/video-transcoding'
11import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow' 17import { processActivityPubFollow } from './handlers/activitypub-follow'
12import { processVideoImport, VideoImportPayload } from './handlers/video-import' 18import { processVideoImport} from './handlers/video-import'
13import { processVideosViews } from './handlers/video-views' 19import { processVideosViews } from './handlers/video-views'
14import { refreshAPObject, RefreshPayload } from './handlers/activitypub-refresher' 20import { refreshAPObject} from './handlers/activitypub-refresher'
15import { processVideoFileImport, VideoFileImportPayload } from './handlers/video-file-import' 21import { processVideoFileImport} from './handlers/video-file-import'
16import { processVideoRedundancy, VideoRedundancyPayload } from '@server/lib/job-queue/handlers/video-redundancy' 22import { processVideoRedundancy} from '@server/lib/job-queue/handlers/video-redundancy'
17 23
18type CreateJobArgument = 24type CreateJobArgument =
19 { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | 25 { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index 63197eee1..710c2d30f 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -26,7 +26,7 @@ import {
26import { MAccountDefault, MActorFollowFull } from '../typings/models' 26import { MAccountDefault, MActorFollowFull } from '../typings/models'
27import { MVideoImportVideo } from '@server/typings/models/video/video-import' 27import { MVideoImportVideo } from '@server/typings/models/video/video-import'
28import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 28import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
29import { getServerActor } from '@server/helpers/utils' 29import { getServerActor } from '@server/models/application/application'
30 30
31class Notifier { 31class Notifier {
32 32
diff --git a/server/lib/redundancy.ts b/server/lib/redundancy.ts
index aa0e37478..361b401a5 100644
--- a/server/lib/redundancy.ts
+++ b/server/lib/redundancy.ts
@@ -1,12 +1,12 @@
1import { VideoRedundancyModel } from '../models/redundancy/video-redundancy' 1import { VideoRedundancyModel } from '../models/redundancy/video-redundancy'
2import { sendUndoCacheFile } from './activitypub/send' 2import { sendUndoCacheFile } from './activitypub/send'
3import { Transaction } from 'sequelize' 3import { Transaction } from 'sequelize'
4import { getServerActor } from '../helpers/utils'
5import { MActorSignature, MVideoRedundancyVideo } from '@server/typings/models' 4import { MActorSignature, MVideoRedundancyVideo } from '@server/typings/models'
6import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
7import { logger } from '@server/helpers/logger' 6import { logger } from '@server/helpers/logger'
8import { ActorFollowModel } from '@server/models/activitypub/actor-follow' 7import { ActorFollowModel } from '@server/models/activitypub/actor-follow'
9import { Activity } from '@shared/models' 8import { Activity } from '@shared/models'
9import { getServerActor } from '@server/models/application/application'
10 10
11async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) { 11async function removeVideoRedundancy (videoRedundancy: MVideoRedundancyVideo, t?: Transaction) {
12 const serverActor = await getServerActor() 12 const serverActor = await getServerActor()
diff --git a/server/lib/schedulers/auto-follow-index-instances.ts b/server/lib/schedulers/auto-follow-index-instances.ts
index a1f5e4a91..e852c7fc6 100644
--- a/server/lib/schedulers/auto-follow-index-instances.ts
+++ b/server/lib/schedulers/auto-follow-index-instances.ts
@@ -6,7 +6,7 @@ import { chunk } from 'lodash'
6import { doRequest } from '@server/helpers/requests' 6import { doRequest } from '@server/helpers/requests'
7import { ActorFollowModel } from '@server/models/activitypub/actor-follow' 7import { ActorFollowModel } from '@server/models/activitypub/actor-follow'
8import { JobQueue } from '@server/lib/job-queue' 8import { JobQueue } from '@server/lib/job-queue'
9import { getServerActor } from '@server/helpers/utils' 9import { getServerActor } from '@server/models/application/application'
10 10
11export class AutoFollowIndexInstances extends AbstractScheduler { 11export class AutoFollowIndexInstances extends AbstractScheduler {
12 12
diff --git a/server/lib/schedulers/update-videos-scheduler.ts b/server/lib/schedulers/update-videos-scheduler.ts
index 956780a77..d32c1c068 100644
--- a/server/lib/schedulers/update-videos-scheduler.ts
+++ b/server/lib/schedulers/update-videos-scheduler.ts
@@ -2,7 +2,7 @@ import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler' 2import { AbstractScheduler } from './abstract-scheduler'
3import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update' 3import { ScheduleVideoUpdateModel } from '../../models/video/schedule-video-update'
4import { retryTransactionWrapper } from '../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../helpers/database-utils'
5import { federateVideoIfNeeded } from '../activitypub' 5import { federateVideoIfNeeded } from '../activitypub/videos'
6import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' 6import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
7import { Notifier } from '../notifier' 7import { Notifier } from '../notifier'
8import { sequelizeTypescript } from '../../initializers/database' 8import { sequelizeTypescript } from '../../initializers/database'
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts
index e33a4133a..8da9d52b5 100644
--- a/server/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/lib/schedulers/videos-redundancy-scheduler.ts
@@ -6,11 +6,10 @@ import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
6import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent' 6import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent'
7import { join } from 'path' 7import { join } from 'path'
8import { move } from 'fs-extra' 8import { move } from 'fs-extra'
9import { getServerActor } from '../../helpers/utils'
10import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' 9import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
11import { getVideoCacheFileActivityPubUrl, getVideoCacheStreamingPlaylistActivityPubUrl } from '../activitypub/url' 10import { getVideoCacheFileActivityPubUrl, getVideoCacheStreamingPlaylistActivityPubUrl } from '../activitypub/url'
12import { removeVideoRedundancy } from '../redundancy' 11import { removeVideoRedundancy } from '../redundancy'
13import { getOrCreateVideoAndAccountAndChannel } from '../activitypub' 12import { getOrCreateVideoAndAccountAndChannel } from '../activitypub/videos'
14import { downloadPlaylistSegments } from '../hls' 13import { downloadPlaylistSegments } from '../hls'
15import { CONFIG } from '../../initializers/config' 14import { CONFIG } from '../../initializers/config'
16import { 15import {
@@ -26,6 +25,7 @@ import {
26} from '@server/typings/models' 25} from '@server/typings/models'
27import { getVideoFilename } from '../video-paths' 26import { getVideoFilename } from '../video-paths'
28import { VideoModel } from '@server/models/video/video' 27import { VideoModel } from '@server/models/video/video'
28import { getServerActor } from '@server/models/application/application'
29 29
30type CandidateToDuplicate = { 30type CandidateToDuplicate = {
31 redundancy: VideosRedundancyStrategy 31 redundancy: VideosRedundancyStrategy
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts
index fe83d23e7..516c912a9 100644
--- a/server/lib/video-comment.ts
+++ b/server/lib/video-comment.ts
@@ -2,7 +2,7 @@ import * as Sequelize from 'sequelize'
2import { ResultList } from '../../shared/models' 2import { ResultList } from '../../shared/models'
3import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' 3import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model'
4import { VideoCommentModel } from '../models/video/video-comment' 4import { VideoCommentModel } from '../models/video/video-comment'
5import { getVideoCommentActivityPubUrl } from './activitypub' 5import { getVideoCommentActivityPubUrl } from './activitypub/url'
6import { sendCreateVideoComment } from './activitypub/send' 6import { sendCreateVideoComment } from './activitypub/send'
7import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight } from '../typings/models' 7import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight } from '../typings/models'
8 8
diff --git a/server/lib/video-paths.ts b/server/lib/video-paths.ts
index fe0a004e4..05aaca8af 100644
--- a/server/lib/video-paths.ts
+++ b/server/lib/video-paths.ts
@@ -1,8 +1,8 @@
1import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/typings/models' 1import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/typings/models'
2import { extractVideo } from './videos'
3import { join } from 'path' 2import { join } from 'path'
4import { CONFIG } from '@server/initializers/config' 3import { CONFIG } from '@server/initializers/config'
5import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' 4import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants'
5import { extractVideo } from '@server/helpers/video'
6 6
7// ################## Video file name ################## 7// ################## Video file name ##################
8 8
diff --git a/server/lib/video-playlist.ts b/server/lib/video-playlist.ts
index 29b70cfda..75fbd6896 100644
--- a/server/lib/video-playlist.ts
+++ b/server/lib/video-playlist.ts
@@ -1,7 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { VideoPlaylistModel } from '../models/video/video-playlist' 2import { VideoPlaylistModel } from '../models/video/video-playlist'
3import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' 3import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
4import { getVideoPlaylistActivityPubUrl } from './activitypub' 4import { getVideoPlaylistActivityPubUrl } from './activitypub/url'
5import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' 5import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
6import { MAccount } from '../typings/models' 6import { MAccount } from '../typings/models'
7import { MVideoPlaylistOwner } from '../typings/models/video/video-playlist' 7import { MVideoPlaylistOwner } from '../typings/models/video/video-playlist'
diff --git a/server/lib/videos.ts b/server/lib/videos.ts
deleted file mode 100644
index 96bdd42e9..000000000
--- a/server/lib/videos.ts
+++ /dev/null
@@ -1,36 +0,0 @@
1import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models'
2import { VideoTranscodingPayload } from '@server/lib/job-queue/handlers/video-transcoding'
3import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
4import { JobQueue } from '@server/lib/job-queue'
5
6function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
7 return isStreamingPlaylist(videoOrPlaylist)
8 ? videoOrPlaylist.Video
9 : videoOrPlaylist
10}
11
12function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) {
13 let dataInput: VideoTranscodingPayload
14
15 if (videoFile.isAudio()) {
16 dataInput = {
17 type: 'merge-audio' as 'merge-audio',
18 resolution: DEFAULT_AUDIO_RESOLUTION,
19 videoUUID: video.uuid,
20 isNewVideo: true
21 }
22 } else {
23 dataInput = {
24 type: 'optimize' as 'optimize',
25 videoUUID: video.uuid,
26 isNewVideo: true
27 }
28 }
29
30 return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput })
31}
32
33export {
34 addOptimizeOrMergeAudioJob,
35 extractVideo
36}