Skip to content

Commit c955b63

Browse files
committed
feat: ✨push stash
1 parent 683fca8 commit c955b63

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

client.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import queueMicrotask from 'queue-microtask'
77
import { hex2arr, hex2bin, text2arr, arr2hex, arr2text } from 'uint8-util'
88

99
import common from './lib/common.js'
10-
import HTTPTracker from './lib/client/http-tracker.js' // empty object in browser
11-
import UDPTracker from './lib/client/udp-tracker.js' // empty object in browser
10+
import HTTPTracker from './lib/client/http-tracker.js'
11+
import UDPTracker from './lib/client/udp-tracker.js'
1212
import WebSocketTracker from './lib/client/websocket-tracker.js'
1313

1414
const debug = Debug('bittorrent-tracker:client')
@@ -32,7 +32,7 @@ const debug = Debug('bittorrent-tracker:client')
3232
class Client extends EventEmitter {
3333
constructor (opts = {}) {
3434
super()
35-
35+
console.log('CLIENT TRACKER CREATED', opts)
3636
if (!opts.peerId) throw new Error('Option `peerId` is required')
3737
if (!opts.infoHash) throw new Error('Option `infoHash` is required')
3838
if (!opts.announce) throw new Error('Option `announce` is required')

lib/client/http-tracker.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import arrayRemove from 'unordered-array-remove'
22
import bencode from 'bencode'
33
import Debug from 'debug'
4-
import fetch from 'cross-fetch-ponyfill'
4+
import { serverProxyFetch as fetch } from '@fkn/lib'
5+
// import fetch from 'cross-fetch-ponyfill'
56
import { bin2hex, hex2bin, arr2text, text2arr, arr2hex } from 'uint8-util'
67

78
import common from '../common.js'
@@ -28,6 +29,7 @@ function abortTimeout (ms) {
2829
*/
2930
class HTTPTracker extends Tracker {
3031
constructor (client, announceUrl) {
32+
console.log('HTTP TRACKER CREATED', client, announceUrl)
3133
super(client, announceUrl)
3234

3335
debug('new http tracker %s', announceUrl)
@@ -119,7 +121,15 @@ class HTTPTracker extends Tracker {
119121
}
120122

121123
async _request (requestUrl, params, cb) {
122-
const parsedUrl = new URL(requestUrl + (requestUrl.indexOf('?') === -1 ? '?' : '&') + common.querystringStringify(params))
124+
const _parsedUrl = new URL(requestUrl + (requestUrl.indexOf('?') === -1 ? '?' : '&') + common.querystringStringify(params))
125+
const parsedUrl = new URL(_parsedUrl.toString())
126+
parsedUrl.searchParams.set(
127+
'info_hash',
128+
new URLSearchParams({ info_hash: escape(params.info_hash) })
129+
.toString()
130+
.replaceAll('%25', '%')
131+
.replace('info_hash=', '')
132+
)
123133
let agent
124134
if (this.client._proxyOpts) {
125135
agent = parsedUrl.protocol === 'https:' ? this.client._proxyOpts.httpsAgent : this.client._proxyOpts.httpAgent
@@ -142,7 +152,7 @@ class HTTPTracker extends Tracker {
142152
let res
143153
let controller = abortTimeout(common.REQUEST_TIMEOUT)
144154
try {
145-
res = await fetch(parsedUrl.toString(), {
155+
res = await fetch(parsedUrl.toString().replaceAll('%25', '%'), {
146156
agent,
147157
signal: controller.signal,
148158
dispatcher: agent,

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
"bittorrent-tracker": "./bin/cmd.js"
1212
},
1313
"browser": {
14-
"./lib/common-node.js": false,
15-
"./lib/client/http-tracker.js": false,
16-
"./lib/client/udp-tracker.js": false,
1714
"./server.js": false,
1815
"socks": false
1916
},
@@ -27,6 +24,7 @@
2724
},
2825
"type": "module",
2926
"dependencies": {
27+
"@fkn/lib": "file:../../fkn/lib",
3028
"@thaunknown/simple-peer": "^10.0.6",
3129
"@thaunknown/simple-websocket": "^9.1.1",
3230
"bencode": "^4.0.0",

0 commit comments

Comments
 (0)