diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-16 16:49:43 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-16 16:49:43 +0100 |
commit | 2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481 (patch) | |
tree | 9003b67f56f13267aa373e0d0314c9893ad38fb6 /server/lib | |
parent | 2b6af10e9f37ccd104a9cc179e32c530a6655964 (diff) | |
download | PeerTube-2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481.tar.gz PeerTube-2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481.tar.zst PeerTube-2e9c7877eb3a3c5d64cc5c3383f0a7c0b51f5481.zip |
Add videos.getFiles plugin helper
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 55 |
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' | |||
9 | import { getServerActor } from '@server/models/application/application' | 9 | import { getServerActor } from '@server/models/application/application' |
10 | import { ServerModel } from '@server/models/server/server' | 10 | import { ServerModel } from '@server/models/server/server' |
11 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' | 11 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' |
12 | import { UserModel } from '@server/models/user/user' | ||
12 | import { VideoModel } from '@server/models/video/video' | 13 | import { VideoModel } from '@server/models/video/video' |
13 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' | 14 | import { VideoBlacklistModel } from '@server/models/video/video-blacklist' |
14 | import { MPlugin } from '@server/types/models' | 15 | import { MPlugin } from '@server/types/models' |
15 | import { PeerTubeHelpers } from '@server/types/plugins' | 16 | import { PeerTubeHelpers } from '@server/types/plugins' |
16 | import { VideoBlacklistCreate } from '@shared/models' | 17 | import { VideoBlacklistCreate, VideoStorage } from '@shared/models' |
17 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' | 18 | import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist' |
18 | import { ServerConfigManager } from '../server-config-manager' | 19 | import { ServerConfigManager } from '../server-config-manager' |
19 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' | 20 | import { blacklistVideo, unblacklistVideo } from '../video-blacklist' |
20 | import { UserModel } from '@server/models/user/user' | 21 | import { VideoPathManager } from '../video-path-manager' |
21 | 22 | ||
22 | function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers { | 23 | function 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 | } |