aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-10 14:25:29 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-11 07:57:20 +0200
commit30bc55c88b3b7416c2224925e88639694fd32746 (patch)
treeaebe3b1b8657198e432080f7d15a5694f19a8389 /server/lib
parent560605026bfadab711cf6d34e9c7ea865887816a (diff)
downloadPeerTube-30bc55c88b3b7416c2224925e88639694fd32746.tar.gz
PeerTube-30bc55c88b3b7416c2224925e88639694fd32746.tar.zst
PeerTube-30bc55c88b3b7416c2224925e88639694fd32746.zip
Refactor video extensions logic in server
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/videos.ts60
1 files changed, 30 insertions, 30 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 6c5f7f306..cbbf23be1 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -1,12 +1,15 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as sequelize from 'sequelize' 2import { maxBy, minBy } from 'lodash'
3import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
4import { join } from 'path'
4import * as request from 'request' 5import * as request from 'request'
6import * as sequelize from 'sequelize'
5import { 7import {
6 ActivityHashTagObject, 8 ActivityHashTagObject,
7 ActivityMagnetUrlObject, 9 ActivityMagnetUrlObject,
8 ActivityPlaylistSegmentHashesObject, 10 ActivityPlaylistSegmentHashesObject,
9 ActivityPlaylistUrlObject, ActivitypubHttpFetcherPayload, 11 ActivityPlaylistUrlObject,
12 ActivitypubHttpFetcherPayload,
10 ActivityTagObject, 13 ActivityTagObject,
11 ActivityUrlObject, 14 ActivityUrlObject,
12 ActivityVideoUrlObject, 15 ActivityVideoUrlObject,
@@ -14,11 +17,16 @@ import {
14} from '../../../shared/index' 17} from '../../../shared/index'
15import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 18import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
16import { VideoPrivacy } from '../../../shared/models/videos' 19import { VideoPrivacy } from '../../../shared/models/videos'
20import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
21import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
22import { buildRemoteVideoBaseUrl, checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
17import { isAPVideoFileMetadataObject, sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos' 23import { isAPVideoFileMetadataObject, sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos'
24import { isArray } from '../../helpers/custom-validators/misc'
18import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' 25import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos'
19import { deleteNonExistingModels, resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' 26import { deleteNonExistingModels, resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils'
20import { logger } from '../../helpers/logger' 27import { logger } from '../../helpers/logger'
21import { doRequest } from '../../helpers/requests' 28import { doRequest } from '../../helpers/requests'
29import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video'
22import { 30import {
23 ACTIVITY_PUB, 31 ACTIVITY_PUB,
24 MIMETYPES, 32 MIMETYPES,
@@ -28,33 +36,15 @@ import {
28 STATIC_PATHS, 36 STATIC_PATHS,
29 THUMBNAILS_SIZE 37 THUMBNAILS_SIZE
30} from '../../initializers/constants' 38} from '../../initializers/constants'
39import { sequelizeTypescript } from '../../initializers/database'
40import { AccountVideoRateModel } from '../../models/account/account-video-rate'
31import { TagModel } from '../../models/video/tag' 41import { TagModel } from '../../models/video/tag'
32import { VideoModel } from '../../models/video/video' 42import { VideoModel } from '../../models/video/video'
33import { VideoFileModel } from '../../models/video/video-file'
34import { getOrCreateActorAndServerAndModel } from './actor'
35import { addVideoComments } from './video-comments'
36import { crawlCollectionPage } from './crawl'
37import { sendCreateVideo, sendUpdateVideo } from './send'
38import { isArray } from '../../helpers/custom-validators/misc'
39import { VideoCaptionModel } from '../../models/video/video-caption' 43import { VideoCaptionModel } from '../../models/video/video-caption'
40import { JobQueue } from '../job-queue'
41import { createRates } from './video-rates'
42import { addVideoShares, shareVideoByServerAndChannel } from './share'
43import { fetchVideoByUrl, VideoFetchByUrlType } from '../../helpers/video'
44import { buildRemoteVideoBaseUrl, checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
45import { Notifier } from '../notifier'
46import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
47import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
48import { AccountVideoRateModel } from '../../models/account/account-video-rate'
49import { VideoShareModel } from '../../models/video/video-share'
50import { VideoCommentModel } from '../../models/video/video-comment' 44import { VideoCommentModel } from '../../models/video/video-comment'
51import { sequelizeTypescript } from '../../initializers/database' 45import { VideoFileModel } from '../../models/video/video-file'
52import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail' 46import { VideoShareModel } from '../../models/video/video-share'
53import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 47import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
54import { join } from 'path'
55import { FilteredModelAttributes } from '../../types/sequelize'
56import { autoBlacklistVideoIfNeeded } from '../video-blacklist'
57import { ActorFollowScoreCache } from '../files-cache'
58import { 48import {
59 MAccountIdActor, 49 MAccountIdActor,
60 MChannelAccountLight, 50 MChannelAccountLight,
@@ -73,7 +63,18 @@ import {
73 MVideoThumbnail 63 MVideoThumbnail
74} from '../../types/models' 64} from '../../types/models'
75import { MThumbnail } from '../../types/models/video/thumbnail' 65import { MThumbnail } from '../../types/models/video/thumbnail'
76import { maxBy, minBy } from 'lodash' 66import { FilteredModelAttributes } from '../../types/sequelize'
67import { ActorFollowScoreCache } from '../files-cache'
68import { JobQueue } from '../job-queue'
69import { Notifier } from '../notifier'
70import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail'
71import { autoBlacklistVideoIfNeeded } from '../video-blacklist'
72import { getOrCreateActorAndServerAndModel } from './actor'
73import { crawlCollectionPage } from './crawl'
74import { sendCreateVideo, sendUpdateVideo } from './send'
75import { addVideoShares, shareVideoByServerAndChannel } from './share'
76import { addVideoComments } from './video-comments'
77import { createRates } from './video-rates'
77 78
78async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: sequelize.Transaction) { 79async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: sequelize.Transaction) {
79 const video = videoArg as MVideoAP 80 const video = videoArg as MVideoAP
@@ -516,10 +517,9 @@ export {
516// --------------------------------------------------------------------------- 517// ---------------------------------------------------------------------------
517 518
518function isAPVideoUrlObject (url: any): url is ActivityVideoUrlObject { 519function isAPVideoUrlObject (url: any): url is ActivityVideoUrlObject {
519 const mimeTypes = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT)
520
521 const urlMediaType = url.mediaType 520 const urlMediaType = url.mediaType
522 return mimeTypes.includes(urlMediaType) && urlMediaType.startsWith('video/') 521
522 return MIMETYPES.VIDEO.MIMETYPE_EXT[urlMediaType] && urlMediaType.startsWith('video/')
523} 523}
524 524
525function isAPStreamingPlaylistUrlObject (url: ActivityUrlObject): url is ActivityPlaylistUrlObject { 525function isAPStreamingPlaylistUrlObject (url: ActivityUrlObject): url is ActivityPlaylistUrlObject {
@@ -716,7 +716,7 @@ function videoFileActivityUrlToDBAttributes (
716 716
717 const mediaType = fileUrl.mediaType 717 const mediaType = fileUrl.mediaType
718 const attribute = { 718 const attribute = {
719 extname: MIMETYPES.VIDEO.MIMETYPE_EXT[mediaType], 719 extname: getExtFromMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT, mediaType),
720 infoHash: parsed.infoHash, 720 infoHash: parsed.infoHash,
721 resolution: fileUrl.height, 721 resolution: fileUrl.height,
722 size: fileUrl.size, 722 size: fileUrl.size,