fix: add testing-torrents params

This commit is contained in:
2025-04-05 09:20:51 +08:00
parent ecb56013a5
commit 3dfcf2a536
10 changed files with 2617 additions and 1603 deletions

View File

@@ -8,11 +8,14 @@ FROM nodebt AS deps
RUN mkdir -p /app/workspace
WORKDIR /app
COPY package.json /app/
RUN pnpm approve-builds utf-8-validate node-datachannel utp-native
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --no-frozen-lockfile
FROM deps AS app
COPY main.ts /app/
EXPOSE 6080
EXPOSE 6081
EXPOSE 6082
CMD [ "npm", "start" ]

View File

@@ -1,5 +1,11 @@
# Konobangu Testing Torrents Container
## Development
```bash
pnpm install --ignore-workspace
```
## Build
```bash
@@ -17,4 +23,4 @@ docker run --network_mode=host --name konobangu-testing-torrents konobangu-testi
```bash
docker tag konobangu-testing-torrents:latest ghcr.io/dumtruck/konobangu-testing-torrents:latest
docker push ghcr.io/dumtruck/konobangu-testing-torrents:latest
```
```

View File

@@ -1,5 +1,8 @@
services:
konobangu-testing-torrents:
build: .
network_mode: host
container_name: konobangu-testing-torrents
konobangu-testing-torrents:
build: .
ports:
- 6080:6080
- 6081:6081
- 6082:6082
container_name: konobangu-testing-torrents

View File

@@ -29,9 +29,9 @@ app.register(fastifyStatic, {
});
const tracker = new TrackerServer({
udp: true, // enable udp server? [default=true]
udp: false, // enable udp server? [default=true]
http: true, // enable http server? [default=true]
ws: true, // enable websocket server? [default=true]
ws: false, // enable websocket server? [default=true]
stats: true, // enable web-based statistics? [default=true]
trustProxy: true, // enable trusting x-forwarded-for header for remote IP [default=false]
});
@@ -50,12 +50,13 @@ interface RequestSchema {
interface ResponseSchema {
torrentUrl: string;
magnetUrl: string;
hash: string;
}
// Start local Tracker
async function startTracker(): Promise<void> {
return new Promise<void>((resolve, reject) => {
tracker.listen(TRACKER_PORT, 'localhost', () => {
tracker.listen(TRACKER_PORT, '0.0.0.0', () => {
console.log(`Tracker listening on port ${TRACKER_PORT}`);
resolve();
});
@@ -85,6 +86,7 @@ async function generateMockFile(filePath: string, size: number) {
await fsp.mkdir(dir, { recursive: true });
}
await fsp.writeFile(filePath, Buffer.alloc(0));
await fsp.truncate(filePath, size);
}
@@ -162,6 +164,7 @@ app.post<{ Body: RequestSchema }>('/api/torrents/mock', async (req, _reply) => {
return {
torrentUrl: `${API_BASE_URL}${id}.torrent`,
magnetUrl,
hash: torrent.infoHash,
} as ResponseSchema;
});
@@ -169,7 +172,8 @@ app.post<{ Body: RequestSchema }>('/api/torrents/mock', async (req, _reply) => {
async function main() {
try {
await startTracker();
await app.listen({ port: API_PORT, host: LOCAL_IP });
const address = await app.listen({ port: API_PORT, host: '0.0.0.0' });
console.log('Listening on:', address);
} catch (err) {
console.error('Startup error:', err);
webTorrent.destroy();

View File

@@ -18,5 +18,14 @@
"devDependencies": {
"@types/create-torrent": "^5.0.2",
"@types/webtorrent": "^0.110.0"
},
"pnpm": {
"onlyBuiltDependencies": [
"bufferutil",
"esbuild",
"node-datachannel",
"utf-8-validate",
"utp-native"
]
}
}

2461
packages/testing-torrents/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff