qbitcompat

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 30 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package qbitcompat 是 qB 兼容入口(路线图 M13):在单独的端口上实现 qBittorrent WebUI API v2 的一个子集, 让 MoviePilot、IYUU、autobrr、Sonarr/Radarr 这类只认 qB 的工具把 pt-tools 当成下载器。

登录用有 qbit:compat 权限的 API 令牌当密码,换一个内存里的 SID。读接口转给绑定的真实下载器;写接口默认只动经兼容入口加的种子, 设置里打开完全控制后不限。添加种子一律先拿到种子文件,再经 internal.PushTorrentToDownloader(磁盘空间保护、站点做种容量照常), 链接只认能解析成已启用站点种子编号的,由 pt-tools 自己经站点下载,不去请求客户端给的地址;磁力链接一律拒绝。 回应里 tracker 地址的 passkey 会被遮住。所有写操作记操作审计(通道 qbit_compat)。

Index

Constants

View Source
const (
	// AppVersion、WebAPIVersion 是报给客户端的 qB 版本:客户端按 4.x 的路径(pause/resume)调用,stop/start 也照样接。
	AppVersion    = "v4.6.7"
	WebAPIVersion = "2.9.3"
	// ChannelType 是审计里的通道。
	ChannelType = "qbit_compat"
	// Source 是经兼容入口加的种子记录的来源。
	Source = "qbit_compat"
)
View Source
const OwnerTag = "pt-tools-compat"

OwnerTag 是经兼容入口加的种子在下载器里带的标签(Transmission 是 label)。添加时间只到秒:在兼容入口以外删掉、 又在同一秒里被别处加回来的同一个种子,hash 与添加时间都对得上,靠它分辨(别处加的不带它)。 兼容入口的接口里看不到它,客户端也加不上、去不掉;在下载器里手动去掉它以后,没打开完全控制时兼容入口不再动这个种子。

Variables

View Source
var ErrInvalid = errors.New("参数不对")

ErrInvalid 是设置里的值不对。

Functions

func CleanListenAddr

func CleanListenAddr(s string) (string, error)

CleanListenAddr 检查监听地址:空串(不开),或「地址:端口」,地址是 IP、localhost 或留空(所有地址),端口 1 到 65535。

func LoadSettings

func LoadSettings(ctx context.Context, db *gorm.DB) (models.QbitCompatSetting, error)

LoadSettings 读设置;还没存过时是零值(默认下载器、不开完全控制)。

func SaveSettings

func SaveSettings(ctx context.Context, db *gorm.DB, in Settings) (models.QbitCompatSetting, error)

SaveSettings 存下载器、完全控制开关与监听地址(带了时);分类与标签不动。指定的下载器要存在。

Types

type AuditRecorder

type AuditRecorder interface {
	Record(ctx context.Context, e app.AuditEntry) error
}

AuditRecorder 记一条操作审计(app.AuditService 实现了它)。

type Deps

type Deps struct {
	DB     *gorm.DB
	Tokens TokenStore
	Audit  AuditRecorder
	// Instance 按下载器名字取实例(DownloaderManager.GetDownloaderContext)
	Instance func(ctx context.Context, name string) (downloader.Downloader, error)
	// Push 是推送入口(internal.PushTorrentToDownloader)
	Push func(ctx context.Context, req internal.PushTorrentRequest) (*internal.PushTorrentResult, error)
	// Site 按站点 ID 取已启用站点的实例,没有启用时返回 nil(搜索编排器的 GetSite)
	Site func(id string) v2.Site
	// Resolver 按 tracker 与下载地址认站点
	Resolver *v2.TrackerResolver
	Now      func() time.Time
}

Deps 是兼容入口要的服务,cmd/web.go 里接上。

type LoginRecord

type LoginRecord struct {
	At       time.Time `json:"at"`
	IP       string    `json:"ip"`
	Username string    `json:"username"`
	TokenID  uint      `json:"token_id,omitempty"`
	Result   string    `json:"result"`
}

LoginRecord 是一次登录:时间、客户端的地址、客户端填的用户名、令牌编号(成功时)与结果。 Result 是 ok、bad_credentials(令牌不对)、scope(令牌没有 qB 兼容权限)或 locked(失败太多次,这个地址被锁了)。

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server 是兼容入口。

func New

func New(d Deps) *Server

New 建一个兼容入口。

func (*Server) Addr

func (s *Server) Addr() string

Addr 是监听地址;没在监听时是空的。

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler 是兼容入口的路由:/api/v2/<组>/<方法>。没登录回 403、方法不对回 405、没有的接口回 404(都是 qB 的行为)。

func (*Server) Logins

func (s *Server) Logins() (ok, fail *LoginRecord)

Logins 是最近一次成功与失败的登录(没有时为空)。

func (*Server) Sessions

func (s *Server) Sessions() int

Sessions 是现在登录着的会话数(1 小时没用的不算)。

func (*Server) SetAddr

func (s *Server) SetAddr(addr string)

SetAddr 记下监听地址(Status 用)。

type Settings

type Settings struct {
	DownloaderID uint `json:"downloader_id"`
	FullControl  bool `json:"full_control"`
	// ListenAddr 是监听地址(host:port,空串是不开);不带时不改(见 CleanListenAddr)
	ListenAddr *string `json:"listen_addr,omitempty"`
}

Settings 是兼容入口的设置(网页「qB 兼容入口」页读写的那部分)。

type TokenStore

type TokenStore interface {
	Verify(ctx context.Context, plain string) (apitoken.Token, error)
	Get(ctx context.Context, id uint) (apitoken.Token, error)
}

TokenStore 是登录与复查要用的令牌库(apitoken.Store 实现了它)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL