diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/peertube-crypto.ts | 8 | ||||
-rw-r--r-- | server/helpers/utils.ts | 13 | ||||
-rw-r--r-- | server/helpers/video.ts | 42 | ||||
-rw-r--r-- | server/helpers/webtorrent.ts | 2 |
4 files changed, 47 insertions, 18 deletions
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 89c0ab151..394e97fd5 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -5,7 +5,6 @@ import { jsonld } from './custom-jsonld-signature' | |||
5 | import { logger } from './logger' | 5 | import { logger } from './logger' |
6 | import { cloneDeep } from 'lodash' | 6 | import { cloneDeep } from 'lodash' |
7 | import { createSign, createVerify } from 'crypto' | 7 | import { createSign, createVerify } from 'crypto' |
8 | import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils' | ||
9 | import * as bcrypt from 'bcrypt' | 8 | import * as bcrypt from 'bcrypt' |
10 | import { MActor } from '../typings/models' | 9 | import { MActor } from '../typings/models' |
11 | 10 | ||
@@ -104,12 +103,19 @@ async function signJsonLDObject (byActor: MActor, data: any) { | |||
104 | return Object.assign(data, { signature }) | 103 | return Object.assign(data, { signature }) |
105 | } | 104 | } |
106 | 105 | ||
106 | function buildDigest (body: any) { | ||
107 | const rawBody = typeof body === 'string' ? body : JSON.stringify(body) | ||
108 | |||
109 | return 'SHA-256=' + sha256(rawBody, 'base64') | ||
110 | } | ||
111 | |||
107 | // --------------------------------------------------------------------------- | 112 | // --------------------------------------------------------------------------- |
108 | 113 | ||
109 | export { | 114 | export { |
110 | isHTTPSignatureDigestValid, | 115 | isHTTPSignatureDigestValid, |
111 | parseHTTPSignature, | 116 | parseHTTPSignature, |
112 | isHTTPSignatureVerified, | 117 | isHTTPSignatureVerified, |
118 | buildDigest, | ||
113 | isJsonLDSignatureVerified, | 119 | isJsonLDSignatureVerified, |
114 | comparePassword, | 120 | comparePassword, |
115 | createPrivateAndPublicKeys, | 121 | createPrivateAndPublicKeys, |
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 11c118292..ad3b7949e 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -1,11 +1,9 @@ | |||
1 | import { ResultList } from '../../shared' | 1 | import { ResultList } from '../../shared' |
2 | import { ApplicationModel } from '../models/application/application' | ||
3 | import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils' | 2 | import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils' |
4 | import { logger } from './logger' | 3 | import { logger } from './logger' |
5 | import { join } from 'path' | 4 | import { join } from 'path' |
6 | import { Instance as ParseTorrent } from 'parse-torrent' | 5 | import { Instance as ParseTorrent } from 'parse-torrent' |
7 | import { remove } from 'fs-extra' | 6 | import { remove } from 'fs-extra' |
8 | import * as memoizee from 'memoizee' | ||
9 | import { CONFIG } from '../initializers/config' | 7 | import { CONFIG } from '../initializers/config' |
10 | import { isVideoFileExtnameValid } from './custom-validators/videos' | 8 | import { isVideoFileExtnameValid } from './custom-validators/videos' |
11 | 9 | ||
@@ -33,16 +31,6 @@ function getFormattedObjects<U, V, T extends FormattableToJSON<U, V>> (objects: | |||
33 | } as ResultList<V> | 31 | } as ResultList<V> |
34 | } | 32 | } |
35 | 33 | ||
36 | const getServerActor = memoizee(async function () { | ||
37 | const application = await ApplicationModel.load() | ||
38 | if (!application) throw Error('Could not load Application from database.') | ||
39 | |||
40 | const actor = application.Account.Actor | ||
41 | actor.Account = application.Account | ||
42 | |||
43 | return actor | ||
44 | }, { promise: true }) | ||
45 | |||
46 | function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) { | 34 | function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) { |
47 | const id = typeof target === 'string' | 35 | const id = typeof target === 'string' |
48 | ? target | 36 | ? target |
@@ -105,7 +93,6 @@ export { | |||
105 | generateRandomString, | 93 | generateRandomString, |
106 | getFormattedObjects, | 94 | getFormattedObjects, |
107 | getSecureTorrentName, | 95 | getSecureTorrentName, |
108 | getServerActor, | ||
109 | getServerCommit, | 96 | getServerCommit, |
110 | generateVideoImportTmpPath, | 97 | generateVideoImportTmpPath, |
111 | getUUIDFromFilename | 98 | getUUIDFromFilename |
diff --git a/server/helpers/video.ts b/server/helpers/video.ts index 4fe2a60f0..6f76cbdfc 100644 --- a/server/helpers/video.ts +++ b/server/helpers/video.ts | |||
@@ -1,14 +1,21 @@ | |||
1 | import { VideoModel } from '../models/video/video' | 1 | import { VideoModel } from '../models/video/video' |
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | import { | 3 | import { |
4 | isStreamingPlaylist, | ||
5 | MStreamingPlaylistVideo, | ||
6 | MVideo, | ||
4 | MVideoAccountLightBlacklistAllFiles, | 7 | MVideoAccountLightBlacklistAllFiles, |
8 | MVideoFile, | ||
5 | MVideoFullLight, | 9 | MVideoFullLight, |
6 | MVideoIdThumbnail, | 10 | MVideoIdThumbnail, |
11 | MVideoImmutable, | ||
7 | MVideoThumbnail, | 12 | MVideoThumbnail, |
8 | MVideoWithRights, | 13 | MVideoWithRights |
9 | MVideoImmutable | ||
10 | } from '@server/typings/models' | 14 | } from '@server/typings/models' |
11 | import { Response } from 'express' | 15 | import { Response } from 'express' |
16 | import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants' | ||
17 | import { JobQueue } from '@server/lib/job-queue' | ||
18 | import { VideoTranscodingPayload } from '@shared/models' | ||
12 | 19 | ||
13 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' | 20 | type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' |
14 | 21 | ||
@@ -62,10 +69,39 @@ function getVideoWithAttributes (res: Response) { | |||
62 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights | 69 | return res.locals.videoAll || res.locals.onlyVideo || res.locals.onlyVideoWithRights |
63 | } | 70 | } |
64 | 71 | ||
72 | function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) { | ||
73 | let dataInput: VideoTranscodingPayload | ||
74 | |||
75 | if (videoFile.isAudio()) { | ||
76 | dataInput = { | ||
77 | type: 'merge-audio' as 'merge-audio', | ||
78 | resolution: DEFAULT_AUDIO_RESOLUTION, | ||
79 | videoUUID: video.uuid, | ||
80 | isNewVideo: true | ||
81 | } | ||
82 | } else { | ||
83 | dataInput = { | ||
84 | type: 'optimize' as 'optimize', | ||
85 | videoUUID: video.uuid, | ||
86 | isNewVideo: true | ||
87 | } | ||
88 | } | ||
89 | |||
90 | return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput }) | ||
91 | } | ||
92 | |||
93 | function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) { | ||
94 | return isStreamingPlaylist(videoOrPlaylist) | ||
95 | ? videoOrPlaylist.Video | ||
96 | : videoOrPlaylist | ||
97 | } | ||
98 | |||
65 | export { | 99 | export { |
66 | VideoFetchType, | 100 | VideoFetchType, |
67 | VideoFetchByUrlType, | 101 | VideoFetchByUrlType, |
68 | fetchVideo, | 102 | fetchVideo, |
69 | getVideoWithAttributes, | 103 | getVideoWithAttributes, |
70 | fetchVideoByUrl | 104 | fetchVideoByUrl, |
105 | addOptimizeOrMergeAudioJob, | ||
106 | extractVideo | ||
71 | } | 107 | } |
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index b25e44fcd..7cd76d708 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -13,8 +13,8 @@ import { WEBSERVER } from '@server/initializers/constants' | |||
13 | import * as parseTorrent from 'parse-torrent' | 13 | import * as parseTorrent from 'parse-torrent' |
14 | import * as magnetUtil from 'magnet-uri' | 14 | import * as magnetUtil from 'magnet-uri' |
15 | import { isArray } from '@server/helpers/custom-validators/misc' | 15 | import { isArray } from '@server/helpers/custom-validators/misc' |
16 | import { extractVideo } from '@server/lib/videos' | ||
17 | import { getTorrentFileName, getVideoFilePath } from '@server/lib/video-paths' | 16 | import { getTorrentFileName, getVideoFilePath } from '@server/lib/video-paths' |
17 | import { extractVideo } from '@server/helpers/video' | ||
18 | 18 | ||
19 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 19 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
20 | 20 | ||