diff options
Diffstat (limited to 'server/lib/plugins/plugin-helpers-builder.ts')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index e26776f45..78e4a28ad 100644 --- a/server/lib/plugins/plugin-helpers-builder.ts +++ b/server/lib/plugins/plugin-helpers-builder.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { ffprobePromise } from '@server/helpers/ffprobe-utils' | ||
3 | import { buildLogger } from '@server/helpers/logger' | 4 | import { buildLogger } from '@server/helpers/logger' |
4 | import { CONFIG } from '@server/initializers/config' | 5 | import { CONFIG } from '@server/initializers/config' |
5 | import { WEBSERVER } from '@server/initializers/constants' | 6 | import { WEBSERVER } from '@server/initializers/constants' |
@@ -9,15 +10,16 @@ import { AccountBlocklistModel } from '@server/models/account/account-blocklist' | |||
9 | import { getServerActor } from '@server/models/application/application' | 10 | import { getServerActor } from '@server/models/application/application' |
10 | import { ServerModel } from '@server/models/server/server' | 11 | import { ServerModel } from '@server/models/server/server' |
11 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' | 12 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' |
13 | import { UserModel } from '@server/models/user/user' | ||
12 | import { VideoModel } from '@server/models/video/video' | 14 | import { VideoModel } from '@server/models/video/video' |
13 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' | 15 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' |
14 | import { MPlugin } from '@server/types/models' | 16 | import { MPlugin } from '@server/types/models' |
15 | import { PeerTubeHelpers } from '@server/types/plugins' | 17 | import { PeerTubeHelpers } from '@server/types/plugins' |
16 | import { VideoBlacklistCreate } from '@shared/models' | 18 | import { VideoBlacklistCreate, VideoStorage } from '@shared/models' |
17 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' | 19 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' |
18 | import { ServerConfigManager } from '../server-config-manager' | 20 | import { ServerConfigManager } from '../server-config-manager' |
19 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' | 21 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' |
20 | import { UserModel } from '@server/models/user/user' | 22 | import { VideoPathManager } from '../video-path-manager' |
21 | 23 | ||
22 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { | 24 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { |
23 | const logger = buildPluginLogger(npmName) | 25 | const logger = buildPluginLogger(npmName) |
@@ -85,6 +87,60 @@ function buildVideosHelpers () { | |||
85 | 87 | ||
86 | await video.destroy({ transaction: t }) | 88 | await video.destroy({ transaction: t }) |
87 | }) | 89 | }) |
90 | }, | ||
91 | |||
92 | ffprobe: (path: string) => { | ||
93 | return ffprobePromise(path) | ||
94 | }, | ||
95 | |||
96 | getFiles: async (id: number | string) => { | ||
97 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id) | ||
98 | if (!video) return undefined | ||
99 | |||
100 | const webtorrentVideoFiles = (video.VideoFiles || []).map(f => ({ | ||
101 | path: f.storage === VideoStorage.FILE_SYSTEM | ||
102 | ? VideoPathManager.Instance.getFSVideoFileOutputPath(video, f) | ||
103 | : null, | ||
104 | url: f.getFileUrl(video), | ||
105 | |||
106 | resolution: f.resolution, | ||
107 | size: f.size, | ||
108 | fps: f.fps | ||
109 | })) | ||
110 | |||
111 | const hls = video.getHLSPlaylist() | ||
112 | |||
113 | const hlsVideoFiles = hls | ||
114 | ? (video.getHLSPlaylist().VideoFiles || []).map(f => { | ||
115 | return { | ||
116 | path: f.storage === VideoStorage.FILE_SYSTEM | ||
117 | ? VideoPathManager.Instance.getFSVideoFileOutputPath(hls, f) | ||
118 | : null, | ||
119 | url: f.getFileUrl(video), | ||
120 | resolution: f.resolution, | ||
121 | size: f.size, | ||
122 | fps: f.fps | ||
123 | } | ||
124 | }) | ||
125 | : [] | ||
126 | |||
127 | const thumbnails = video.Thumbnails.map(t => ({ | ||
128 | type: t.type, | ||
129 | url: t.getFileUrl(video), | ||
130 | path: t.getPath() | ||
131 | })) | ||
132 | |||
133 | return { | ||
134 | webtorrent: { | ||
135 | videoFiles: webtorrentVideoFiles | ||
136 | }, | ||
137 | |||
138 | hls: { | ||
139 | videoFiles: hlsVideoFiles | ||
140 | }, | ||
141 | |||
142 | thumbnails | ||
143 | } | ||
88 | } | 144 | } |
89 | } | 145 | } |
90 | } | 146 | } |