aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-12-16 16:49:43 +0100
committerChocobozzz <me@florianbigard.com>2021-12-16 16:49:43 +0100
commit2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481 (patch)
tree9003b67f56f13267aa373e0d0314c9893ad38fb6 /server/lib/plugins
parent2b6af10e9f37ccd104a9cc179e32c530a6655964 (diff)
downloadPeerTube-2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481.tar.gz
PeerTube-2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481.tar.zst
PeerTube-2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481.zip
Add videos.getFiles plugin helper
Diffstat (limited to 'server/lib/plugins')
-rw-r--r--server/lib/plugins/plugin-helpers-builder.ts55
1 files changed, 53 insertions, 2 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts
index e26776f45..bea0f8959 100644
--- a/server/lib/plugins/plugin-helpers-builder.ts
+++ b/server/lib/plugins/plugin-helpers-builder.ts
@@ -9,15 +9,16 @@ import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
9import { getServerActor } from '@server/models/application/application' 9import { getServerActor } from '@server/models/application/application'
10import { ServerModel } from '@server/models/server/server' 10import { ServerModel } from '@server/models/server/server'
11import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 11import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
12import { UserModel } from '@server/models/user/user'
12import { VideoModel } from '@server/models/video/video' 13import { VideoModel } from '@server/models/video/video'
13import { VideoBlacklistModel } from '@server/models/video/video-blacklist' 14import { VideoBlacklistModel } from '@server/models/video/video-blacklist'
14import { MPlugin } from '@server/types/models' 15import { MPlugin } from '@server/types/models'
15import { PeerTubeHelpers } from '@server/types/plugins' 16import { PeerTubeHelpers } from '@server/types/plugins'
16import { VideoBlacklistCreate } from '@shared/models' 17import { VideoBlacklistCreate, VideoStorage } from '@shared/models'
17import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' 18import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist'
18import { ServerConfigManager } from '../server-config-manager' 19import { ServerConfigManager } from '../server-config-manager'
19import { blacklistVideo, unblacklistVideo } from '../video-blacklist' 20import { blacklistVideo, unblacklistVideo } from '../video-blacklist'
20import { UserModel } from '@server/models/user/user' 21import { VideoPathManager } from '../video-path-manager'
21 22
22function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { 23function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers {
23 const logger = buildPluginLogger(npmName) 24 const logger = buildPluginLogger(npmName)
@@ -85,6 +86,56 @@ function buildVideosHelpers () {
85 86
86 await video.destroy({ transaction: t }) 87 await video.destroy({ transaction: t })
87 }) 88 })
89 },
90
91 getFiles: async (id: number | string) => {
92 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
93 if (!video) return undefined
94
95 const webtorrentVideoFiles = (video.VideoFiles || []).map(f => ({
96 path: f.storage === VideoStorage.FILE_SYSTEM
97 ? VideoPathManager.Instance.getFSVideoFileOutputPath(video, f)
98 : null,
99 url: f.getFileUrl(video),
100
101 resolution: f.resolution,
102 size: f.size,
103 fps: f.fps
104 }))
105
106 const hls = video.getHLSPlaylist()
107
108 const hlsVideoFiles = hls
109 ? (video.getHLSPlaylist().VideoFiles || []).map(f => {
110 return {
111 path: f.storage === VideoStorage.FILE_SYSTEM
112 ? VideoPathManager.Instance.getFSVideoFileOutputPath(hls, f)
113 : null,
114 url: f.getFileUrl(video),
115 resolution: f.resolution,
116 size: f.size,
117 fps: f.fps
118 }
119 })
120 : []
121
122 const thumbnails = video.Thumbnails.map(t => ({
123 type: t.type,
124 url: t.getFileUrl(video),
125 path: t.getPath()
126 }))
127
128 return {
129 webtorrent: {
130 videoFiles: webtorrentVideoFiles
131 },
132
133 hls: {
134 videoFiles: hlsVideoFiles
135 },
136
137 thumbnails
138 }
88 } 139 }
89 } 140 }
90} 141}