@ctrl/transmission

中文文档
8.0.1发布于 2026/10/05MITTypeScriptES Module构建来源已验证近 30 天下载 6126

TypeScript api wrapper for transmission using ofetch

原始使用文档
文档目录6 节
  1. Install
  2. Use
  3. API
  4. Normalized API
  5. See Also
  6. Start a test docker container

transmission npm

TypeScript api wrapper for Transmission using ofetch

Install

npm install @ctrl/transmission

Requires Node.js 24 or newer.

Use

import { Transmission } from '@ctrl/transmission';

const client = new Transmission({
  baseUrl: 'http://localhost:9091/',
  password: '',
});

async function main() {
  const res = await client.getAllData();
  console.log(res);
}

API

Docs: https://transmission.ep.workers.dev
API Docs: https://github.com/transmission/transmission/blob/main/docs/rpc-spec.md

Things that work differently from the other clients:

  • label is the first of Transmission's labels, normalizedAddTorrent sets labels: [label]
  • Transmission ignores unknown ids, pause, resume, queue and remove don't throw for them
  • totalSeeds/totalPeers come from tracker scrapes and are 0 until a tracker responds

Normalized API

These functions are normalized through @ctrl/shared-torrent, which makes it easier to support multiple torrent clients. See below for alternative supported torrent clients.

getAllData

Returns all torrent data and an array of label objects. Data has been normalized and does not match the output of native listTorrents().

const data = await client.getAllData();
console.log(data.torrents);
getTorrent

Returns one torrent data from torrent hash

const data = await client.getTorrent('torrent-hash');
console.log(data);
pauseTorrent and resumeTorrent

Pause or resume one or more torrents

await client.pauseTorrent('torrent-hash');
await client.resumeTorrent(['torrent-hash', 'other-torrent-hash']);
removeTorrent

Remove one or more torrents. Does not remove data on disk by default.

// does not remove data on disk
await client.removeTorrent('torrent-hash', false);

// remove data on disk
await client.removeTorrent(['torrent-hash', 'other-torrent-hash'], true);
queueUp and queueDown

Move a torrent up or down the queue

await client.queueUp('torrent-hash');
await client.queueDown('torrent-hash');
addTorrent

Add a torrent from a magnet link or torrent file, has client specific options. Also see normalizedAddTorrent

import { readFileSync } from 'node:fs';

const result = await client.addTorrent(new Uint8Array(readFileSync('./linux.torrent')));
console.log(result);
normalizedAddTorrent

Add a torrent and return normalized torrent data, can start a torrent paused and add label

const result = await client.normalizedAddTorrent('magnet:?xt=urn:btih:...', {
  startPaused: false,
  label: 'linux',
});
console.log(result);
Errors

Failed requests throw a TorrentClientError from @ctrl/shared-torrent with a code of torrent_not_found, unauthorized, request_failed or client_error, the http status when there is one and the original error as the cause.

import { TorrentClientError } from '@ctrl/transmission';

try {
  await client.getTorrent('torrent-hash');
} catch (error) {
  if (error instanceof TorrentClientError && error.code === 'torrent_not_found') {
    // not in the client
  }
}
export and create from state

If you're shutting down the server often (serverless?) you can export the state

const state = client.exportState();
const restored = Transmission.createFromState(config, state);

See Also

All of the following npm modules provide the same normalized functions along with supporting the unique apis for each client.

Usenet clients with the same normalized approach:

Start a test docker container

docker run -d \
  --name=transmission \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Etc/UTC \
  -p 9091:9091 \
  -p 51413:51413 \
  -p 51413:51413/udp \
  -v ~/Documents/transmission/config:/config \
  -v ~/Documents/transmission/downloads:/downloads \
  -v ~/Documents/transmission/watch:/watch \
  --restart unless-stopped \
  lscr.io/linuxserver/transmission:latest

版本与发布记录

@ctrl/transmission 共发布 43 个版本,首次发布于 2019/03/04;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.1latest2026/10/051 个月前
8.0.02026/10/051 个月前
7.4.02025/09/161.1 年前
7.3.12025/09/161.2 年前
7.3.02025/09/011.2 年前
7.2.02024/12/251.9 年前

关于 @ctrl/transmission 的常见问题

@ctrl/transmission 是什么?

TypeScript api wrapper for transmission using ofetch

如何安装 @ctrl/transmission?

在项目目录运行 npm install @ctrl/transmission,或使用 pnpm add / yarn add / bun add。

@ctrl/transmission 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ctrl/transmission 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ctrl/transmission 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ctrl/transmission 可以商用吗?

@ctrl/transmission 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ctrl/transmission 的下载量有多少?

根据 npm 官方下载统计,@ctrl/transmission 在 2026/10/11 – 2026/11/09 这 30 天内被下载 6,126 次,日均约 204 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ctrl/transmission 还在维护吗?

最新版本 8.0.1 发布于 2026/10/05(1 个月前);至今共发布 43 个版本,其中过去 12 个月发布了 2 个;首次发布于 2019/03/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。