@ikenxuan/amagi
使用指南

工具集

amagi 提供的各平台工具函数

工具集

amagi 为各平台提供了丰富的工具函数,包括签名算法、URL 拼接器、格式转换等。

平台工具集

import {  } from '@ikenxuan/amagi'

// AV/BV 转换
const bv = ..(170001)
const bv: `BV1${string}`
const av = ..('BV17x411w7KC')
const av: number

签名算法

// WBI 签名
const  = await ..(
  'https://api.bilibili.com/x/web-interface/view?bvid=BV1xx', 
  'your_cookie'
)

弹幕解析

// 解析 protobuf 格式的弹幕数据
const  = ..(buffer)
import {  } from '@ikenxuan/amagi'

// 生成 msToken
const msToken = ..(128)
const msToken: string

签名算法

// 生成 a_bogus 签名
const  = ..(url, userAgent)

// 生成 X-Bogus 签名
const  = ..(url, userAgent)

// 验证指纹管理器
const  = ..()
import {  } from '@ikenxuan/amagi'

// 获取拼接好的 API URL 和请求体
const { ,  } = ..getWorkInfo({ 
  : '3xqxxxxxx' 
})
import {  } from '@ikenxuan/amagi'

// 生成 X-T 时间戳
const xt = ..()
const xt: number
// 生成 X-B3-Traceid const traceid = ..()
const traceid: string
// 从 Cookie 中提取 a1 const a1 = ..('a1=xxx; webId=yyy')
const a1: string
// 生成搜索 ID const searchId = ..()
const searchId: string

X-S 签名

// 生成 X-S 签名 (GET 请求)
const  = ..(path, a1Cookie, clientType, params)

// 生成 X-S 签名 (POST 请求)
const  = ..(path, a1Cookie, clientType, body)

// 通用 X-S 签名生成
const  = ..generateXS(url, body, ua, method, a1Cookie)

// 生成 X-S-Common
const  = ..()

通用工具

错误处理

import {  } from '@ikenxuan/amagi'

// 创建成功响应
const success = ({ : 'test' }, '获取成功', 200)
const success: SuccessResult<{
    title: string;
}>

方法名映射

import {  } from '@ikenxuan/amagi'

// 中文 -> 英文
const eng = ('bilibili', '单个视频作品数据')
const eng: string | undefined

On this page