diff options
17 files changed, 66 insertions, 18 deletions
diff --git a/package.json b/package.json index 5d1d2e747..b9031389f 100644 --- a/package.json +++ b/package.json | |||
@@ -219,7 +219,10 @@ | |||
219 | "eslint-plugin-node": "^11.0.0", | 219 | "eslint-plugin-node": "^11.0.0", |
220 | "eslint-plugin-promise": "^6.0.0", | 220 | "eslint-plugin-promise": "^6.0.0", |
221 | "fast-xml-parser": "^4.0.0-beta.8", | 221 | "fast-xml-parser": "^4.0.0-beta.8", |
222 | "jpeg-js": "^0.4.4", | ||
222 | "mocha": "^10.0.0", | 223 | "mocha": "^10.0.0", |
224 | "pixelmatch": "^5.3.0", | ||
225 | "pngjs": "^7.0.0", | ||
223 | "proxy": "^1.0.2", | 226 | "proxy": "^1.0.2", |
224 | "resolve-tspaths": "^0.8.8", | 227 | "resolve-tspaths": "^0.8.8", |
225 | "socket.io-client": "^4.5.4", | 228 | "socket.io-client": "^4.5.4", |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index f1e170971..1c00f9a93 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { testImage } from '@server/tests/shared' | 4 | import { testImageSize } from '@server/tests/shared' |
5 | import { AbuseState, HttpStatusCode, UserAdminFlag, UserRole, VideoPlaylistType } from '@shared/models' | 5 | import { AbuseState, HttpStatusCode, UserAdminFlag, UserRole, VideoPlaylistType } from '@shared/models' |
6 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | 6 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' |
7 | 7 | ||
@@ -274,7 +274,7 @@ describe('Test users', function () { | |||
274 | 274 | ||
275 | const user = await server.users.getMyInfo({ token: userToken }) | 275 | const user = await server.users.getMyInfo({ token: userToken }) |
276 | for (const avatar of user.account.avatars) { | 276 | for (const avatar of user.account.avatars) { |
277 | await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, '.gif') | 277 | await testImageSize(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, '.gif') |
278 | } | 278 | } |
279 | }) | 279 | }) |
280 | 280 | ||
@@ -286,7 +286,7 @@ describe('Test users', function () { | |||
286 | 286 | ||
287 | const user = await server.users.getMyInfo({ token: userToken }) | 287 | const user = await server.users.getMyInfo({ token: userToken }) |
288 | for (const avatar of user.account.avatars) { | 288 | for (const avatar of user.account.avatars) { |
289 | await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, extension) | 289 | await testImageSize(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, extension) |
290 | } | 290 | } |
291 | } | 291 | } |
292 | }) | 292 | }) |
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 5636de45f..80215f038 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts | |||
@@ -68,6 +68,8 @@ async function checkVideoServer2 (server: PeerTubeServer, id: number | string) { | |||
68 | expect(video.description).to.equal('my super description') | 68 | expect(video.description).to.equal('my super description') |
69 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) | 69 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) |
70 | 70 | ||
71 | await testImage(server.url, 'thumbnail', video.thumbnailPath) | ||
72 | |||
71 | expect(video.files).to.have.lengthOf(1) | 73 | expect(video.files).to.have.lengthOf(1) |
72 | 74 | ||
73 | const bodyCaptions = await server.captions.list({ videoId: id }) | 75 | const bodyCaptions = await server.captions.list({ videoId: id }) |
@@ -254,18 +256,20 @@ describe('Test video imports', function () { | |||
254 | it('Should import a video on server 2 with some fields', async function () { | 256 | it('Should import a video on server 2 with some fields', async function () { |
255 | this.timeout(60_000) | 257 | this.timeout(60_000) |
256 | 258 | ||
257 | const attributes = { | 259 | const { video } = await servers[1].imports.importVideo({ |
258 | targetUrl: FIXTURE_URLS.youtube, | 260 | attributes: { |
259 | channelId: servers[1].store.channel.id, | 261 | targetUrl: FIXTURE_URLS.youtube, |
260 | privacy: VideoPrivacy.PUBLIC, | 262 | channelId: servers[1].store.channel.id, |
261 | category: 10, | 263 | privacy: VideoPrivacy.PUBLIC, |
262 | licence: 7, | 264 | category: 10, |
263 | language: 'en', | 265 | licence: 7, |
264 | name: 'my super name', | 266 | language: 'en', |
265 | description: 'my super description', | 267 | name: 'my super name', |
266 | tags: [ 'supertag1', 'supertag2' ] | 268 | description: 'my super description', |
267 | } | 269 | tags: [ 'supertag1', 'supertag2' ], |
268 | const { video } = await servers[1].imports.importVideo({ attributes }) | 270 | thumbnailfile: 'thumbnail.jpg' |
271 | } | ||
272 | }) | ||
269 | expect(video.name).to.equal('my super name') | 273 | expect(video.name).to.equal('my super name') |
270 | }) | 274 | }) |
271 | 275 | ||
diff --git a/server/tests/fixtures/thumbnail-playlist.jpg b/server/tests/fixtures/thumbnail-playlist.jpg index 62cd77435..12de5817b 100644 --- a/server/tests/fixtures/thumbnail-playlist.jpg +++ b/server/tests/fixtures/thumbnail-playlist.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/thumbnail.jpg b/server/tests/fixtures/thumbnail.jpg index b331aba3b..1e2897fb8 100644 --- a/server/tests/fixtures/thumbnail.jpg +++ b/server/tests/fixtures/thumbnail.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_import_thumbnail_yt_dlp.jpg b/server/tests/fixtures/video_import_thumbnail_yt_dlp.jpg index f672a785a..a10e07207 100644 --- a/server/tests/fixtures/video_import_thumbnail_yt_dlp.jpg +++ b/server/tests/fixtures/video_import_thumbnail_yt_dlp.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short.mp4.jpg b/server/tests/fixtures/video_short.mp4.jpg index 62cd77435..7ac29122c 100644 --- a/server/tests/fixtures/video_short.mp4.jpg +++ b/server/tests/fixtures/video_short.mp4.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short.ogv.jpg b/server/tests/fixtures/video_short.ogv.jpg index 62cd77435..5bc63969b 100644 --- a/server/tests/fixtures/video_short.ogv.jpg +++ b/server/tests/fixtures/video_short.ogv.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short.webm.jpg b/server/tests/fixtures/video_short.webm.jpg index 62cd77435..7ac29122c 100644 --- a/server/tests/fixtures/video_short.webm.jpg +++ b/server/tests/fixtures/video_short.webm.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short1-preview.webm.jpg b/server/tests/fixtures/video_short1-preview.webm.jpg index 1f8bb38be..d65af1f21 100644 --- a/server/tests/fixtures/video_short1-preview.webm.jpg +++ b/server/tests/fixtures/video_short1-preview.webm.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short1.webm.jpg b/server/tests/fixtures/video_short1.webm.jpg index 615cb2a5d..0ab7c58ad 100644 --- a/server/tests/fixtures/video_short1.webm.jpg +++ b/server/tests/fixtures/video_short1.webm.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short2.webm.jpg b/server/tests/fixtures/video_short2.webm.jpg index aa3126381..1e2897fb8 100644 --- a/server/tests/fixtures/video_short2.webm.jpg +++ b/server/tests/fixtures/video_short2.webm.jpg | |||
Binary files differ | |||
diff --git a/server/tests/fixtures/video_short3.webm.jpg b/server/tests/fixtures/video_short3.webm.jpg index 62cd77435..b572f676e 100644 --- a/server/tests/fixtures/video_short3.webm.jpg +++ b/server/tests/fixtures/video_short3.webm.jpg | |||
Binary files differ | |||
diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts index 19a99cba9..530c9bacd 100644 --- a/server/tests/helpers/image.ts +++ b/server/tests/helpers/image.ts | |||
@@ -32,7 +32,7 @@ describe('Image helpers', function () { | |||
32 | const imageDestJPG = join(imageDestDir, 'test.jpg') | 32 | const imageDestJPG = join(imageDestDir, 'test.jpg') |
33 | const imageDestPNG = join(imageDestDir, 'test.png') | 33 | const imageDestPNG = join(imageDestDir, 'test.png') |
34 | 34 | ||
35 | const thumbnailSize = { width: 223, height: 122 } | 35 | const thumbnailSize = { width: 280, height: 157 } |
36 | 36 | ||
37 | it('Should skip processing if the source image is okay', async function () { | 37 | it('Should skip processing if the source image is okay', async function () { |
38 | const input = buildAbsoluteFixturePath('thumbnail.jpg') | 38 | const input = buildAbsoluteFixturePath('thumbnail.jpg') |
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 523d37420..c0098b293 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts | |||
@@ -2,7 +2,10 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { pathExists, readFile } from 'fs-extra' | 4 | import { pathExists, readFile } from 'fs-extra' |
5 | import JPEG from 'jpeg-js' | ||
5 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import pixelmatch from 'pixelmatch' | ||
8 | import { PNG } from 'pngjs' | ||
6 | import { root } from '@shared/core-utils' | 9 | import { root } from '@shared/core-utils' |
7 | import { HttpStatusCode } from '@shared/models' | 10 | import { HttpStatusCode } from '@shared/models' |
8 | import { makeGetRequest, PeerTubeServer } from '@shared/server-commands' | 11 | import { makeGetRequest, PeerTubeServer } from '@shared/server-commands' |
@@ -41,7 +44,7 @@ async function expectLogContain (server: PeerTubeServer, str: string) { | |||
41 | expect(content.toString()).to.contain(str) | 44 | expect(content.toString()).to.contain(str) |
42 | } | 45 | } |
43 | 46 | ||
44 | async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { | 47 | async function testImageSize (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { |
45 | const res = await makeGetRequest({ | 48 | const res = await makeGetRequest({ |
46 | url, | 49 | url, |
47 | path: imageHTTPPath, | 50 | path: imageHTTPPath, |
@@ -58,6 +61,29 @@ async function testImage (url: string, imageName: string, imageHTTPPath: string, | |||
58 | expect(body.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') | 61 | expect(body.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') |
59 | } | 62 | } |
60 | 63 | ||
64 | async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { | ||
65 | const res = await makeGetRequest({ | ||
66 | url, | ||
67 | path: imageHTTPPath, | ||
68 | expectedStatus: HttpStatusCode.OK_200 | ||
69 | }) | ||
70 | |||
71 | const body = res.body | ||
72 | const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) | ||
73 | |||
74 | const img1 = imageHTTPPath.endsWith('.png') | ||
75 | ? PNG.sync.read(body) | ||
76 | : JPEG.decode(body) | ||
77 | |||
78 | const img2 = extension === '.png' | ||
79 | ? PNG.sync.read(data) | ||
80 | : JPEG.decode(data) | ||
81 | |||
82 | const result = pixelmatch(img1.data, img2.data, null, img1.width, img1.height, { threshold: 0.1 }) | ||
83 | |||
84 | expect(result).to.equal(0, `${imageHTTPPath} image is not the same as ${imageName}${extension}`) | ||
85 | } | ||
86 | |||
61 | async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { | 87 | async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { |
62 | const base = server.servers.buildDirectory(directory) | 88 | const base = server.servers.buildDirectory(directory) |
63 | 89 | ||
@@ -104,6 +130,7 @@ function checkBadSortPagination (url: string, path: string, token?: string, quer | |||
104 | 130 | ||
105 | export { | 131 | export { |
106 | dateIsValid, | 132 | dateIsValid, |
133 | testImageSize, | ||
107 | testImage, | 134 | testImage, |
108 | expectLogDoesNotContain, | 135 | expectLogDoesNotContain, |
109 | testFileExistsOrNot, | 136 | testFileExistsOrNot, |
diff --git a/shared/server-commands/videos/imports-command.ts b/shared/server-commands/videos/imports-command.ts index 07d810ec1..e307a79be 100644 --- a/shared/server-commands/videos/imports-command.ts +++ b/shared/server-commands/videos/imports-command.ts | |||
@@ -7,13 +7,15 @@ import { AbstractCommand, OverrideCommandOptions } from '../shared' | |||
7 | export class ImportsCommand extends AbstractCommand { | 7 | export class ImportsCommand extends AbstractCommand { |
8 | 8 | ||
9 | importVideo (options: OverrideCommandOptions & { | 9 | importVideo (options: OverrideCommandOptions & { |
10 | attributes: VideoImportCreate & { torrentfile?: string } | 10 | attributes: (VideoImportCreate | { torrentfile?: string, previewfile?: string, thumbnailfile?: string }) |
11 | }) { | 11 | }) { |
12 | const { attributes } = options | 12 | const { attributes } = options |
13 | const path = '/api/v1/videos/imports' | 13 | const path = '/api/v1/videos/imports' |
14 | 14 | ||
15 | let attaches: any = {} | 15 | let attaches: any = {} |
16 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } | 16 | if (attributes.torrentfile) attaches = { torrentfile: attributes.torrentfile } |
17 | if (attributes.thumbnailfile) attaches = { thumbnailfile: attributes.thumbnailfile } | ||
18 | if (attributes.previewfile) attaches = { previewfile: attributes.previewfile } | ||
17 | 19 | ||
18 | return unwrapBody<VideoImport>(this.postUploadRequest({ | 20 | return unwrapBody<VideoImport>(this.postUploadRequest({ |
19 | ...options, | 21 | ...options, |
@@ -7592,6 +7592,13 @@ pixelmatch@^4.0.2: | |||
7592 | dependencies: | 7592 | dependencies: |
7593 | pngjs "^3.0.0" | 7593 | pngjs "^3.0.0" |
7594 | 7594 | ||
7595 | pixelmatch@^5.3.0: | ||
7596 | version "5.3.0" | ||
7597 | resolved "https://registry.yarnpkg.com/pixelmatch/-/pixelmatch-5.3.0.tgz#5e5321a7abedfb7962d60dbf345deda87cb9560a" | ||
7598 | integrity sha512-o8mkY4E/+LNUf6LzX96ht6k6CEDi65k9G2rjMtBe9Oo+VPKSvl+0GKHuH/AlG+GA5LPG/i5hrekkxUc3s2HU+Q== | ||
7599 | dependencies: | ||
7600 | pngjs "^6.0.0" | ||
7601 | |||
7595 | please-upgrade-node@^3.2.0: | 7602 | please-upgrade-node@^3.2.0: |
7596 | version "3.2.0" | 7603 | version "3.2.0" |
7597 | resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942" | 7604 | resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.2.0.tgz#aeddd3f994c933e4ad98b99d9a556efa0e2fe942" |
@@ -7609,6 +7616,11 @@ pngjs@^6.0.0: | |||
7609 | resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-6.0.0.tgz#ca9e5d2aa48db0228a52c419c3308e87720da821" | 7616 | resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-6.0.0.tgz#ca9e5d2aa48db0228a52c419c3308e87720da821" |
7610 | integrity sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg== | 7617 | integrity sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg== |
7611 | 7618 | ||
7619 | pngjs@^7.0.0: | ||
7620 | version "7.0.0" | ||
7621 | resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-7.0.0.tgz#a8b7446020ebbc6ac739db6c5415a65d17090e26" | ||
7622 | integrity sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow== | ||
7623 | |||
7612 | postcss@^8.1.10, postcss@^8.3.11: | 7624 | postcss@^8.1.10, postcss@^8.3.11: |
7613 | version "8.4.21" | 7625 | version "8.4.21" |
7614 | resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.21.tgz#c639b719a57efc3187b13a1d765675485f4134f4" | 7626 | resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.21.tgz#c639b719a57efc3187b13a1d765675485f4134f4" |