aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/peertube-crypto.ts8
-rw-r--r--server/helpers/utils.ts13
-rw-r--r--server/helpers/video.ts42
-rw-r--r--server/helpers/webtorrent.ts2
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'
5import { logger } from './logger' 5import { logger } from './logger'
6import { cloneDeep } from 'lodash' 6import { cloneDeep } from 'lodash'
7import { createSign, createVerify } from 'crypto' 7import { createSign, createVerify } from 'crypto'
8import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils'
9import * as bcrypt from 'bcrypt' 8import * as bcrypt from 'bcrypt'
10import { MActor } from '../typings/models' 9import { 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
106function 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
109export { 114export {
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 @@
1import { ResultList } from '../../shared' 1import { ResultList } from '../../shared'
2import { ApplicationModel } from '../models/application/application'
3import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils' 2import { execPromise, execPromise2, randomBytesPromise, sha256 } from './core-utils'
4import { logger } from './logger' 3import { logger } from './logger'
5import { join } from 'path' 4import { join } from 'path'
6import { Instance as ParseTorrent } from 'parse-torrent' 5import { Instance as ParseTorrent } from 'parse-torrent'
7import { remove } from 'fs-extra' 6import { remove } from 'fs-extra'
8import * as memoizee from 'memoizee'
9import { CONFIG } from '../initializers/config' 7import { CONFIG } from '../initializers/config'
10import { isVideoFileExtnameValid } from './custom-validators/videos' 8import { 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
36const 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
46function generateVideoImportTmpPath (target: string | ParseTorrent, extensionArg?: string) { 34function 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 @@
1import { VideoModel } from '../models/video/video' 1import { VideoModel } from '../models/video/video'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { 3import {
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'
11import { Response } from 'express' 15import { Response } from 'express'
16import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
17import { JobQueue } from '@server/lib/job-queue'
18import { VideoTranscodingPayload } from '@shared/models'
12 19
13type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes' 20type 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
72function 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
93function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
94 return isStreamingPlaylist(videoOrPlaylist)
95 ? videoOrPlaylist.Video
96 : videoOrPlaylist
97}
98
65export { 99export {
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'
13import * as parseTorrent from 'parse-torrent' 13import * as parseTorrent from 'parse-torrent'
14import * as magnetUtil from 'magnet-uri' 14import * as magnetUtil from 'magnet-uri'
15import { isArray } from '@server/helpers/custom-validators/misc' 15import { isArray } from '@server/helpers/custom-validators/misc'
16import { extractVideo } from '@server/lib/videos'
17import { getTorrentFileName, getVideoFilePath } from '@server/lib/video-paths' 16import { getTorrentFileName, getVideoFilePath } from '@server/lib/video-paths'
17import { extractVideo } from '@server/helpers/video'
18 18
19const createTorrentPromise = promisify2<string, any, any>(createTorrent) 19const createTorrentPromise = promisify2<string, any, any>(createTorrent)
20 20