aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins/plugin-helpers-builder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/plugins/plugin-helpers-builder.ts')
-rw-r--r--server/lib/plugins/plugin-helpers-builder.ts60
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 @@
1import express from 'express' 1import express from 'express'
2import { join } from 'path' 2import { join } from 'path'
3import { ffprobePromise } from '@server/helpers/ffprobe-utils'
3import { buildLogger } from '@server/helpers/logger' 4import { buildLogger } from '@server/helpers/logger'
4import { CONFIG } from '@server/initializers/config' 5import { CONFIG } from '@server/initializers/config'
5import { WEBSERVER } from '@server/initializers/constants' 6import { WEBSERVER } from '@server/initializers/constants'
@@ -9,15 +10,16 @@ import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
9import { getServerActor } from '@server/models/application/application' 10import { getServerActor } from '@server/models/application/application'
10import { ServerModel } from '@server/models/server/server' 11import { ServerModel } from '@server/models/server/server'
11import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 12import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
13import { UserModel } from '@server/models/user/user'
12import { VideoModel } from '@server/models/video/video' 14import { VideoModel } from '@server/models/video/video'
13import { VideoBlacklistModel } from '@server/models/video/video-blacklist' 15import { VideoBlacklistModel } from '@server/models/video/video-blacklist'
14import { MPlugin } from '@server/types/models' 16import { MPlugin } from '@server/types/models'
15import { PeerTubeHelpers } from '@server/types/plugins' 17import { PeerTubeHelpers } from '@server/types/plugins'
16import { VideoBlacklistCreate } from '@shared/models' 18import { VideoBlacklistCreate, VideoStorage } from '@shared/models'
17import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' 19import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist'
18import { ServerConfigManager } from '../server-config-manager' 20import { ServerConfigManager } from '../server-config-manager'
19import { blacklistVideo, unblacklistVideo } from '../video-blacklist' 21import { blacklistVideo, unblacklistVideo } from '../video-blacklist'
20import { UserModel } from '@server/models/user/user' 22import { VideoPathManager } from '../video-path-manager'
21 23
22function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { 24function 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}