diff options
author | Chocobozzz <me@florianbigard.com> | 2021-09-07 15:16:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-09-07 15:16:26 +0200 |
commit | fb72d2e1c24cd4660fd6611ef723c5827c47294c (patch) | |
tree | c2a2991a9e6944cd3d22c87e34de096a47b8db9e | |
parent | 6f9719b568fad75959a1404b6927b7a278061c41 (diff) | |
download | PeerTube-fb72d2e1c24cd4660fd6611ef723c5827c47294c.tar.gz PeerTube-fb72d2e1c24cd4660fd6611ef723c5827c47294c.tar.zst PeerTube-fb72d2e1c24cd4660fd6611ef723c5827c47294c.zip |
Fix infohash with object storage
-rw-r--r-- | server/lib/job-queue/handlers/move-to-object-storage.ts | 4 | ||||
-rw-r--r-- | server/tests/api/videos/video-hls.ts | 7 | ||||
-rw-r--r-- | shared/extra-utils/requests/requests.ts | 5 | ||||
-rw-r--r-- | shared/extra-utils/server/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/server/tracker.ts | 27 |
5 files changed, 43 insertions, 1 deletions
diff --git a/server/lib/job-queue/handlers/move-to-object-storage.ts b/server/lib/job-queue/handlers/move-to-object-storage.ts index 0bebc0fc2..4beca3d75 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts | |||
@@ -4,6 +4,7 @@ import { join } from 'path' | |||
4 | import { logger } from '@server/helpers/logger' | 4 | import { logger } from '@server/helpers/logger' |
5 | import { updateTorrentUrls } from '@server/helpers/webtorrent' | 5 | import { updateTorrentUrls } from '@server/helpers/webtorrent' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' | ||
7 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' | 8 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' |
8 | import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' | 9 | import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' |
9 | import { moveToNextState } from '@server/lib/video-state' | 10 | import { moveToNextState } from '@server/lib/video-state' |
@@ -84,6 +85,9 @@ async function doAfterLastJob (video: MVideoWithAllFiles, isNewVideo: boolean) { | |||
84 | 85 | ||
85 | playlist.storage = VideoStorage.OBJECT_STORAGE | 86 | playlist.storage = VideoStorage.OBJECT_STORAGE |
86 | 87 | ||
88 | playlist.assignP2PMediaLoaderInfoHashes(video, playlist.VideoFiles) | ||
89 | playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION | ||
90 | |||
87 | await playlist.save() | 91 | await playlist.save() |
88 | } | 92 | } |
89 | 93 | ||
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 4685bf3b6..91124725f 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts | |||
@@ -14,6 +14,7 @@ import { | |||
14 | createMultipleServers, | 14 | createMultipleServers, |
15 | doubleFollow, | 15 | doubleFollow, |
16 | expectStartWith, | 16 | expectStartWith, |
17 | hlsInfohashExist, | ||
17 | makeRawRequest, | 18 | makeRawRequest, |
18 | ObjectStorageCommand, | 19 | ObjectStorageCommand, |
19 | PeerTubeServer, | 20 | PeerTubeServer, |
@@ -88,9 +89,15 @@ async function checkHlsPlaylist (options: { | |||
88 | 89 | ||
89 | const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl }) | 90 | const masterPlaylist = await server.streamingPlaylists.get({ url: hlsPlaylist.playlistUrl }) |
90 | 91 | ||
92 | let i = 0 | ||
91 | for (const resolution of resolutions) { | 93 | for (const resolution of resolutions) { |
92 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) | 94 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
93 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) | 95 | expect(masterPlaylist).to.contain(`${resolution}.m3u8`) |
96 | |||
97 | const url = 'http://' + videoDetails.account.host | ||
98 | await hlsInfohashExist(url, hlsPlaylist.playlistUrl, i) | ||
99 | |||
100 | i++ | ||
94 | } | 101 | } |
95 | } | 102 | } |
96 | 103 | ||
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts index 60a08b13c..5bbf7f3bf 100644 --- a/shared/extra-utils/requests/requests.ts +++ b/shared/extra-utils/requests/requests.ts | |||
@@ -29,9 +29,12 @@ function makeRawRequest (url: string, expectedStatus?: HttpStatusCode, range?: s | |||
29 | 29 | ||
30 | function makeGetRequest (options: CommonRequestParams & { | 30 | function makeGetRequest (options: CommonRequestParams & { |
31 | query?: any | 31 | query?: any |
32 | rawQuery?: string | ||
32 | }) { | 33 | }) { |
33 | const req = request(options.url).get(options.path) | 34 | const req = request(options.url).get(options.path) |
34 | .query(options.query) | 35 | |
36 | if (options.query) req.query(options.query) | ||
37 | if (options.rawQuery) req.query(options.rawQuery) | ||
35 | 38 | ||
36 | return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) | 39 | return buildRequest(req, { contentType: 'application/json', expectedStatus: HttpStatusCode.BAD_REQUEST_400, ...options }) |
37 | } | 40 | } |
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index 92ff7a0f9..76a2099da 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -14,3 +14,4 @@ export * from './server' | |||
14 | export * from './servers-command' | 14 | export * from './servers-command' |
15 | export * from './servers' | 15 | export * from './servers' |
16 | export * from './stats-command' | 16 | export * from './stats-command' |
17 | export * from './tracker' | ||
diff --git a/shared/extra-utils/server/tracker.ts b/shared/extra-utils/server/tracker.ts new file mode 100644 index 000000000..f04e8f8a1 --- /dev/null +++ b/shared/extra-utils/server/tracker.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | import { expect } from 'chai' | ||
2 | import { sha1 } from '@server/helpers/core-utils' | ||
3 | import { makeGetRequest } from '../requests' | ||
4 | |||
5 | async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) { | ||
6 | const path = '/tracker/announce' | ||
7 | |||
8 | const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`) | ||
9 | |||
10 | // From bittorrent-tracker | ||
11 | const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) { | ||
12 | return '%' + char.charCodeAt(0).toString(16).toUpperCase() | ||
13 | }) | ||
14 | |||
15 | const res = await makeGetRequest({ | ||
16 | url: serverUrl, | ||
17 | path, | ||
18 | rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`, | ||
19 | expectedStatus: 200 | ||
20 | }) | ||
21 | |||
22 | expect(res.text).to.not.contain('failure') | ||
23 | } | ||
24 | |||
25 | export { | ||
26 | hlsInfohashExist | ||
27 | } | ||