urlscheme

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 21 Imported by: 0 modules, 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 urlscheme 负责 pixiv:// URL scheme 的平台安装、回调分发与远程登录 hand-off。

包的组成:HandleCallback 分派系统回调,StartRemoteLogin 与 RemoteCallbackSession 管理远程 relay,Install 和 EnsurePersistentIfNeeded 维护桌面 handler。回调与 relay 的私有状态只留在本包;登录命令的上层流程在 internal/cli/auth,远程中继的 HTTP 协议在 internal/loginrelay。

Index

Constants

View Source
const CallbackCommand = "_callback"

CallbackCommand 供 desktop protocol handler 调回当前 CLI binary; 它只由本包生成的系统关联使用,不是公开 CLI 命令。

Variables

This section is empty.

Functions

func AutomaticPersistentHandlerSupported

func AutomaticPersistentHandlerSupported() bool

AutomaticPersistentHandlerSupported 仅对计划中的 desktop client 平台启用启动期 注册。desktop Linux 仍由官方 installer/正常 browser login 处理,headless Linux server 不会因任意命令尝试建立 XDG 关联。

func ClearRemoteLoginHandoff

func ClearRemoteLoginHandoff(start RemoteLoginStart) error

ClearRemoteLoginHandoff 仅在本地 active state 仍然对应 start 时删除它。handler 成功领取 URL 后若浏览器无法启动,应调用此函数;随后 Pixiv callback 会回到此前 的系统 handler,而不会转发给已无法使用的会话。

func EnsurePersistentIfNeeded

func EnsurePersistentIfNeeded(ctx context.Context) error

EnsurePersistentIfNeeded 先以私有 manifest 判断当前 binary 是否已注册;相同 binary 不重复写系统关联。外部修改 association 时,官方 installer 或 browser login 仍会显式重新注册,避免在无关命令中覆盖用户后来选择的默认应用。

func Install

func Install(ctx context.Context, callbackRelayURL string) (func(), error)

Install 在桌面 Linux 上只为当前 auth login 注册 pixiv:// handler。

func StartRemoteLogin

func StartRemoteLogin(ctx context.Context, start RemoteLoginStart) (string, error)

StartRemoteLogin 向明确选中的一次性会话领取 OAuth URL,并只保存本次 callback 转发所需的最小私有状态。新的 handoff 会原子替换旧状态。

Types

type CallbackHandlingResult

type CallbackHandlingResult struct {
	// LocalRelayURL 会把本次 Pixiv callback 放进 fragment,可能包含授权码;
	// 只有 bridge 的基础地址可以记录,完整值按敏感数据处理。
	LocalRelayURL string
	// RemoteCallback 携带远程 relay 返回的一次性结果会话;与 LocalRelayURL 至多一个非零。
	RemoteCallback *RemoteCallbackSession
	// RemoteLoginStart 只在收到 pixiv://remote-login 链接时填写,交由桌面端继续远程登录。
	RemoteLoginStart *RemoteLoginStart
}

CallbackHandlingResult 只携带不含授权码或 token 的本地 bridge URL,或 remote relay 返回的一次性最终页 session。callback 本身绝不写入 stdout/stderr。

func HandleCallback

func HandleCallback(ctx context.Context, rawURL string) (CallbackHandlingResult, error)

HandleCallback 处理系统协议关联的全部回调。正在进行的本地 login 始终优先; 只有没有本地 endpoint 时才尝试由 remote-login 显式建立的一次性 handoff。 非白名单 URL 定向交回先前 handler,不会成为任意 pixiv:// URL 的转发器。

type RemoteCallbackSession

type RemoteCallbackSession struct {
	ResultURL string
	// contains filtered or unexported fields
}

RemoteCallbackSession 代表已被 server 接收、但尚未完成 OAuth exchange 的一次 callback。ResultURL 只显示固定成功/失败页面;它从不包含 Pixiv code 或 token。

func (*RemoteCallbackSession) Abort

func (s *RemoteCallbackSession) Abort()

Abort 仅在浏览器无法打开最终页时释放仍在 server 上等待的 callback 请求。

func (*RemoteCallbackSession) Complete

func (s *RemoteCallbackSession) Complete() error

Complete 等待 server 完成 OAuth exchange。调用方应先打开 ResultURL,再调用它; 这样浏览器可以持续显示“Completing login”,最终得到与 server 一致的结果。

type RemoteLoginStart

type RemoteLoginStart struct {
	Origin    string
	SessionID string
	Proof     string
}

RemoteLoginStart 承载 session page 交给 desktop handler 的一次性请求, 不含 OAuth URL、token 或任何持久设备身份;proof 只绑定这次会话。

Jump to

Keyboard shortcuts

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