diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-10 14:25:29 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-08-11 07:57:20 +0200 |
commit | 30bc55c88b3b7416c2224925e88639694fd32746 (patch) | |
tree | aebe3b1b8657198e432080f7d15a5694f19a8389 /server/lib | |
parent | 560605026bfadab711cf6d34e9c7ea865887816a (diff) | |
download | PeerTube-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.ts | 60 |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import * as sequelize from 'sequelize' | 2 | import { maxBy, minBy } from 'lodash' |
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import { join } from 'path' | ||
4 | import * as request from 'request' | 5 | import * as request from 'request' |
6 | import * as sequelize from 'sequelize' | ||
5 | import { | 7 | import { |
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' |
15 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 18 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
16 | import { VideoPrivacy } from '../../../shared/models/videos' | 19 | import { VideoPrivacy } from '../../../shared/models/videos' |
20 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | ||
21 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | ||
22 | import { buildRemoteVideoBaseUrl, checkUrlsSameHost, getAPId } from '../../helpers/activitypub' | ||
17 | import { isAPVideoFileMetadataObject, sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos' | 23 | import { isAPVideoFileMetadataObject, sanitizeAndCheckVideoTorrentObject } from '../../helpers/custom-validators/activitypub/videos' |
24 | import { isArray } from '../../helpers/custom-validators/misc' | ||
18 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' | 25 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' |
19 | import { deleteNonExistingModels, resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' | 26 | import { deleteNonExistingModels, resetSequelizeInstance, retryTransactionWrapper } from '../../helpers/database-utils' |
20 | import { logger } from '../../helpers/logger' | 27 | import { logger } from '../../helpers/logger' |
21 | import { doRequest } from '../../helpers/requests' | 28 | import { doRequest } from '../../helpers/requests' |
29 | import { fetchVideoByUrl, getExtFromMimetype, VideoFetchByUrlType } from '../../helpers/video' | ||
22 | import { | 30 | import { |
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' |
39 | import { sequelizeTypescript } from '../../initializers/database' | ||
40 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | ||
31 | import { TagModel } from '../../models/video/tag' | 41 | import { TagModel } from '../../models/video/tag' |
32 | import { VideoModel } from '../../models/video/video' | 42 | import { VideoModel } from '../../models/video/video' |
33 | import { VideoFileModel } from '../../models/video/video-file' | ||
34 | import { getOrCreateActorAndServerAndModel } from './actor' | ||
35 | import { addVideoComments } from './video-comments' | ||
36 | import { crawlCollectionPage } from './crawl' | ||
37 | import { sendCreateVideo, sendUpdateVideo } from './send' | ||
38 | import { isArray } from '../../helpers/custom-validators/misc' | ||
39 | import { VideoCaptionModel } from '../../models/video/video-caption' | 43 | import { VideoCaptionModel } from '../../models/video/video-caption' |
40 | import { JobQueue } from '../job-queue' | ||
41 | import { createRates } from './video-rates' | ||
42 | import { addVideoShares, shareVideoByServerAndChannel } from './share' | ||
43 | import { fetchVideoByUrl, VideoFetchByUrlType } from '../../helpers/video' | ||
44 | import { buildRemoteVideoBaseUrl, checkUrlsSameHost, getAPId } from '../../helpers/activitypub' | ||
45 | import { Notifier } from '../notifier' | ||
46 | import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' | ||
47 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | ||
48 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | ||
49 | import { VideoShareModel } from '../../models/video/video-share' | ||
50 | import { VideoCommentModel } from '../../models/video/video-comment' | 44 | import { VideoCommentModel } from '../../models/video/video-comment' |
51 | import { sequelizeTypescript } from '../../initializers/database' | 45 | import { VideoFileModel } from '../../models/video/video-file' |
52 | import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail' | 46 | import { VideoShareModel } from '../../models/video/video-share' |
53 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 47 | import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' |
54 | import { join } from 'path' | ||
55 | import { FilteredModelAttributes } from '../../types/sequelize' | ||
56 | import { autoBlacklistVideoIfNeeded } from '../video-blacklist' | ||
57 | import { ActorFollowScoreCache } from '../files-cache' | ||
58 | import { | 48 | import { |
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' |
75 | import { MThumbnail } from '../../types/models/video/thumbnail' | 65 | import { MThumbnail } from '../../types/models/video/thumbnail' |
76 | import { maxBy, minBy } from 'lodash' | 66 | import { FilteredModelAttributes } from '../../types/sequelize' |
67 | import { ActorFollowScoreCache } from '../files-cache' | ||
68 | import { JobQueue } from '../job-queue' | ||
69 | import { Notifier } from '../notifier' | ||
70 | import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail' | ||
71 | import { autoBlacklistVideoIfNeeded } from '../video-blacklist' | ||
72 | import { getOrCreateActorAndServerAndModel } from './actor' | ||
73 | import { crawlCollectionPage } from './crawl' | ||
74 | import { sendCreateVideo, sendUpdateVideo } from './send' | ||
75 | import { addVideoShares, shareVideoByServerAndChannel } from './share' | ||
76 | import { addVideoComments } from './video-comments' | ||
77 | import { createRates } from './video-rates' | ||
77 | 78 | ||
78 | async function federateVideoIfNeeded (videoArg: MVideoAPWithoutCaption, isNewVideo: boolean, transaction?: sequelize.Transaction) { | 79 | async 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 | ||
518 | function isAPVideoUrlObject (url: any): url is ActivityVideoUrlObject { | 519 | function 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 | ||
525 | function isAPStreamingPlaylistUrlObject (url: ActivityUrlObject): url is ActivityPlaylistUrlObject { | 525 | function 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, |