diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/lib/plugins/plugin-helpers-builder.ts | 5 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-four/main.js | 7 | ||||
-rw-r--r-- | server/tests/plugins/plugin-helpers.ts | 17 | ||||
-rw-r--r-- | server/types/plugins/register-server-option.model.ts | 2 |
4 files changed, 31 insertions, 0 deletions
diff --git a/server/lib/plugins/plugin-helpers-builder.ts b/server/lib/plugins/plugin-helpers-builder.ts index bea0f8959..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' |
@@ -88,6 +89,10 @@ function buildVideosHelpers () { | |||
88 | }) | 89 | }) |
89 | }, | 90 | }, |
90 | 91 | ||
92 | ffprobe: (path: string) => { | ||
93 | return ffprobePromise(path) | ||
94 | }, | ||
95 | |||
91 | getFiles: async (id: number | string) => { | 96 | getFiles: async (id: number | string) => { |
92 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id) | 97 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id) |
93 | if (!video) return undefined | 98 | if (!video) return undefined |
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js index edbb883e2..bff42ff40 100644 --- a/server/tests/fixtures/peertube-plugin-test-four/main.js +++ b/server/tests/fixtures/peertube-plugin-test-four/main.js | |||
@@ -111,6 +111,13 @@ async function register ({ | |||
111 | 111 | ||
112 | return res.json(details) | 112 | return res.json(details) |
113 | }) | 113 | }) |
114 | |||
115 | router.get('/ffprobe', async (req, res) => { | ||
116 | const result = await peertubeHelpers.videos.ffprobe(req.query.path) | ||
117 | if (!result) return res.sendStatus(404) | ||
118 | |||
119 | return res.json(result) | ||
120 | }) | ||
114 | } | 121 | } |
115 | 122 | ||
116 | } | 123 | } |
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 26f66b0b1..da84658bb 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts | |||
@@ -224,6 +224,7 @@ describe('Test plugin helpers', function () { | |||
224 | 224 | ||
225 | describe('Videos', function () { | 225 | describe('Videos', function () { |
226 | let videoUUID: string | 226 | let videoUUID: string |
227 | let videoPath: string | ||
227 | 228 | ||
228 | before(async () => { | 229 | before(async () => { |
229 | this.timeout(240000) | 230 | this.timeout(240000) |
@@ -260,6 +261,8 @@ describe('Test plugin helpers', function () { | |||
260 | await makeRawRequest(file.url, HttpStatusCode.OK_200) | 261 | await makeRawRequest(file.url, HttpStatusCode.OK_200) |
261 | } | 262 | } |
262 | } | 263 | } |
264 | |||
265 | videoPath = body.webtorrent.videoFiles[0].path | ||
263 | } | 266 | } |
264 | 267 | ||
265 | // Thumbnails check | 268 | // Thumbnails check |
@@ -278,6 +281,20 @@ describe('Test plugin helpers', function () { | |||
278 | } | 281 | } |
279 | }) | 282 | }) |
280 | 283 | ||
284 | it('Should probe a file', async function () { | ||
285 | const { body } = await makeGetRequest({ | ||
286 | url: servers[0].url, | ||
287 | path: '/plugins/test-four/router/ffprobe', | ||
288 | query: { | ||
289 | path: videoPath | ||
290 | }, | ||
291 | expectedStatus: HttpStatusCode.OK_200 | ||
292 | }) | ||
293 | |||
294 | expect(body.streams).to.be.an('array') | ||
295 | expect(body.streams).to.have.lengthOf(2) | ||
296 | }) | ||
297 | |||
281 | it('Should remove a video after a view', async function () { | 298 | it('Should remove a video after a view', async function () { |
282 | this.timeout(40000) | 299 | this.timeout(40000) |
283 | 300 | ||
diff --git a/server/types/plugins/register-server-option.model.ts b/server/types/plugins/register-server-option.model.ts index 473990eb6..9f472d900 100644 --- a/server/types/plugins/register-server-option.model.ts +++ b/server/types/plugins/register-server-option.model.ts | |||
@@ -37,6 +37,8 @@ export type PeerTubeHelpers = { | |||
37 | 37 | ||
38 | removeVideo: (videoId: number) => Promise<void> | 38 | removeVideo: (videoId: number) => Promise<void> |
39 | 39 | ||
40 | ffprobe: (path: string) => Promise<any> | ||
41 | |||
40 | getFiles: (id: number | string) => Promise<{ | 42 | getFiles: (id: number | string) => Promise<{ |
41 | webtorrent: { | 43 | webtorrent: { |
42 | videoFiles: { | 44 | videoFiles: { |