dsh-shlr-bilitoolkit 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/dsh.d.ts +1 -0
- package/dist/dsh.js +21 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,9 +74,10 @@ const [ups, _] = await client.space.videos(574115689, 1, 10);
|
|
|
74
74
|
- 读取:`bili_recommend` / `bili_video_detail` / `bili_video_subtitle` / `bili_search_video` / `bili_search_user` / `bili_space_info` / `bili_space_videos` / `bili_article_view` / `bili_article_list` / `bili_dynamic_feed` / `bili_dynamic_space` / `bili_comment_list` / `bili_relation_followings` / `bili_relation_followers` / `bili_notify_unread` / `bili_notify_replies` / `bili_fav_folders` / `bili_video_pagelist` / `bili_video_subtitles` / `bili_video_playurl` / `bili_video_status` / `bili_space_collections` / `bili_space_collection` / `bili_fav_folder_videos` / `bili_dynamic_detail` / `bili_notify_ats` / `bili_notify_likes` / `bili_message_unread` / `bili_message_history` / `bili_relation_stat` / `bili_user_following` / `bili_profile_info` / `bili_comment_replies`
|
|
75
75
|
- 写操作:`bili_like` / `bili_follow` / `bili_favorite` / `bili_send_comment` / `bili_send_message` / `bili_triple` / `bili_dynamic_publish` / `bili_dynamic_repost` / `bili_coin` / `bili_unfavorite` / `bili_fav_folder_create` / `bili_fav_folder_delete` / `bili_dynamic_like` / `bili_dynamic_delete` / `bili_comment_send` / `bili_comment_reply` / `bili_comment_delete` / `bili_message_recall` / `bili_profile_update_sign` / `bili_profile_update`(均会真实修改账号状态,需登录)
|
|
76
76
|
- 辅助:`bili_login_status`(查登录态)/ `bili_gen_qr`(生成扫码登录二维码)/ `bili_cache_clear`(清空本地缓存)
|
|
77
|
-
- 工具读取 `BILI_COOKIE_FILE`(默认 `bili_cookies.json`)作为登录态。
|
|
78
|
-
-
|
|
79
|
-
-
|
|
77
|
+
- 工具读取 `BILI_COOKIE_FILE`(默认 `bili_data/bili_cookies.json`)作为登录态。
|
|
78
|
+
- **数据目录**:Cookie / 缓存 / 二维码统一放在一个目录里,默认 `bili_data/`(相对 dsh 工作目录),避免散落污染工作目录。可用 `BILI_DATA_DIR` 改目录;`BILI_COOKIE_FILE` / `BILI_CACHE_FILE` / `BILI_QR_FILE` 可精确指定单个文件。兼容旧版:若新目录还没有 Cookie、而旧位置(`./bili_cookies.json`)有,会继续沿用旧的。
|
|
79
|
+
- **扫码登录(独立获取 Cookie)**:运行 `npm run login`,终端会打印 ASCII 二维码,用「哔哩哔哩」App 扫码并确认后,Cookie 自动写入 `bili_data/bili_cookies.json`。也可在对话里先调 `bili_login_status` 查登录态、调 `bili_gen_qr` 拿二维码链接与可直接展示的 `ascii` 二维码。写操作(点赞 / 收藏 / 投币 / 关注 / 评论 / 私信 / 三连)都依赖该 Cookie 中的 `SESSDATA` / `bili_jct`。
|
|
80
|
+
- **缓存持久化**:除 Cookie 外,客户端还会把 WBI 签名密钥(`B 站每天轮换`)、`bvid→aid` 映射这类稳定 / 带 TTL 的数据写入本地 JSON 缓存(`BILI_CACHE_FILE`,默认 `bili_data/bili_cache.json`),用临时文件 + 原子替换落盘、文件损坏会自动自愈。冷启动或跨进程时直接复用,避免每次都请求 `nav` 接口;密钥过期或失效时 `refresh()` 会重新拉取并覆盖缓存。若签名反复报 `-403/-352`,可调用 `bili_cache_clear` 强制清空缓存后重试(不影响 Cookie / 登录态)。
|
|
80
81
|
|
|
81
82
|
安装到 dsh(任选其一,取决于你的发行方式):
|
|
82
83
|
|
package/dist/dsh.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { BiliClient } from "./client.js";
|
|
|
13
13
|
import { Collection, Page, PlayInfo, Subtitle, User, Video } from "./models.js";
|
|
14
14
|
export declare const name = "bili-toolkit";
|
|
15
15
|
export declare const inject: string[];
|
|
16
|
+
export declare function dataDir(): string;
|
|
16
17
|
export interface DshTool {
|
|
17
18
|
id: string;
|
|
18
19
|
description: string;
|
package/dist/dsh.js
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
13
13
|
import QRCode from "qrcode";
|
|
14
|
-
import { writeFileSync } from "node:fs";
|
|
15
|
-
import { resolve } from "node:path";
|
|
14
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { dirname, resolve } from "node:path";
|
|
16
16
|
import { pathToFileURL } from "node:url";
|
|
17
17
|
import { BiliClient } from "./client.js";
|
|
18
18
|
import { Collection, Page, PlayInfo, Subtitle, User, Video } from "./models.js";
|
|
@@ -23,10 +23,26 @@ export const inject = ["tools"];
|
|
|
23
23
|
let cached = null;
|
|
24
24
|
// 最近一次生成、等待扫码确认的二维码 key(登录完成链路用)
|
|
25
25
|
let pendingQrKey = null;
|
|
26
|
+
// 统一的数据目录:Cookie / 缓存 / 二维码都放这里,避免散落在工作目录里。
|
|
27
|
+
// BILI_DATA_DIR 可改目录;BILI_COOKIE_FILE / BILI_CACHE_FILE / BILI_QR_FILE 可精确指定单个文件。
|
|
28
|
+
export function dataDir() {
|
|
29
|
+
return process.env.BILI_DATA_DIR ?? "bili_data";
|
|
30
|
+
}
|
|
31
|
+
function resolveCookieFile() {
|
|
32
|
+
if (process.env.BILI_COOKIE_FILE)
|
|
33
|
+
return process.env.BILI_COOKIE_FILE;
|
|
34
|
+
const primary = resolve(dataDir(), "bili_cookies.json");
|
|
35
|
+
const legacy = resolve("bili_cookies.json");
|
|
36
|
+
// 兼容旧版:新目录还没有 cookie、但旧位置有,就继续用旧的
|
|
37
|
+
if (!existsSync(primary) && existsSync(legacy))
|
|
38
|
+
return legacy;
|
|
39
|
+
return primary;
|
|
40
|
+
}
|
|
26
41
|
async function getClient() {
|
|
27
42
|
if (!cached) {
|
|
28
43
|
cached = new BiliClient({
|
|
29
|
-
cookieFile:
|
|
44
|
+
cookieFile: resolveCookieFile(),
|
|
45
|
+
cacheFile: process.env.BILI_CACHE_FILE ?? resolve(dataDir(), "bili_cache.json"),
|
|
30
46
|
});
|
|
31
47
|
// 没有 Cookie 文件(或为空 / 损坏)= 未登录(匿名)。
|
|
32
48
|
// 不能因此让所有工具崩掉——公开接口、以及最关键的扫码登录入口都依赖这里。
|
|
@@ -1011,7 +1027,8 @@ export const TOOLS = [
|
|
|
1011
1027
|
width: 320,
|
|
1012
1028
|
});
|
|
1013
1029
|
qrDataUrl = `data:image/png;base64,${png.toString("base64")}`;
|
|
1014
|
-
qrImagePath = resolve(process.
|
|
1030
|
+
qrImagePath = resolve(process.env.BILI_QR_FILE ?? resolve(dataDir(), "bili_qrcode.png"));
|
|
1031
|
+
mkdirSync(dirname(qrImagePath), { recursive: true });
|
|
1015
1032
|
writeFileSync(qrImagePath, png);
|
|
1016
1033
|
}
|
|
1017
1034
|
catch {
|