2021-09-07 08:16:26 -05:00
|
|
|
import { expect } from 'chai'
|
2021-12-17 06:58:07 -06:00
|
|
|
import { sha1 } from '@shared/extra-utils'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { makeGetRequest } from '@shared/server-commands'
|
2021-09-07 08:16:26 -05:00
|
|
|
|
|
|
|
async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) {
|
|
|
|
const path = '/tracker/announce'
|
|
|
|
|
|
|
|
const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`)
|
|
|
|
|
|
|
|
// From bittorrent-tracker
|
|
|
|
const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) {
|
|
|
|
return '%' + char.charCodeAt(0).toString(16).toUpperCase()
|
|
|
|
})
|
|
|
|
|
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: serverUrl,
|
|
|
|
path,
|
|
|
|
rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`,
|
|
|
|
expectedStatus: 200
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(res.text).to.not.contain('failure')
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
hlsInfohashExist
|
|
|
|
}
|