dsh-workbench-danmaku 0.3.0 → 0.3.2
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/lib/client.js +85 -1063
- package/lib/index.js +3 -4
- package/package.json +5 -8
- package/lib/actions/data.js +0 -174
package/lib/index.js
CHANGED
|
@@ -21,7 +21,6 @@ import { createPlayer } from "./player.js";
|
|
|
21
21
|
import { createSupervisor } from "./desktop/supervisor.js";
|
|
22
22
|
import { registerManageActions } from "./actions/manage.js";
|
|
23
23
|
import { registerConfigActions } from "./actions/config.js";
|
|
24
|
-
import { registerDataActions } from "./actions/data.js";
|
|
25
24
|
import { registerSchemaAction, trackActions } from "./actions/schema.js";
|
|
26
25
|
|
|
27
26
|
export const inject = ["workbench"];
|
|
@@ -74,7 +73,6 @@ export function setup(api) {
|
|
|
74
73
|
const actionDefs = trackActions(api);
|
|
75
74
|
registerManageActions(api, deps);
|
|
76
75
|
registerConfigActions(api, deps);
|
|
77
|
-
registerDataActions(api);
|
|
78
76
|
registerSchemaAction(api, actionDefs, DOMAIN);
|
|
79
77
|
|
|
80
78
|
// 按当前配置启动调度器;桌面层只在 surface 需要时起步,失败也不影响界面层。
|
|
@@ -155,8 +153,10 @@ export function apply(ctx) {
|
|
|
155
153
|
id: DOMAIN,
|
|
156
154
|
title: "弹幕",
|
|
157
155
|
description:
|
|
158
|
-
"把自建弹幕轮播在整个 DSH 界面,并可叠加到整个桌面;单一宿主调度、SSE 与 Electron helper
|
|
156
|
+
"把自建弹幕轮播在整个 DSH 界面,并可叠加到整个桌面;单一宿主调度、SSE 与 Electron helper 双投递,含弹幕库/配置/Action 三个视图",
|
|
159
157
|
version: ADDON_VERSION,
|
|
158
|
+
// 更新来源:宿主「插件」页按它查新版本并安装(只认官方 npm registry)。
|
|
159
|
+
update: { source: "npm", package: "dsh-workbench-danmaku" },
|
|
160
160
|
category: "comm",
|
|
161
161
|
tables: TABLES,
|
|
162
162
|
// 只同步配置方案表,业务数据仍只在本机。
|
|
@@ -166,7 +166,6 @@ export function apply(ctx) {
|
|
|
166
166
|
views: [
|
|
167
167
|
{ id: "library", title: { zh: "弹幕库", en: "Library" } },
|
|
168
168
|
{ id: "config", title: { zh: "配置", en: "Config" } },
|
|
169
|
-
{ id: "data", title: { zh: "数据", en: "Data" } },
|
|
170
169
|
{ id: "actions", title: { zh: "Action", en: "Actions" } },
|
|
171
170
|
],
|
|
172
171
|
capability: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-workbench-danmaku",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "个人工作台弹幕插件:把自建弹幕轮播在整个 DSH 界面,并可叠加到整个桌面",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"addon": {
|
|
17
17
|
"id": "wb-addon-danmaku",
|
|
18
18
|
"title": "弹幕",
|
|
19
|
-
"description": "在整个 DSH
|
|
20
|
-
"version": "0.3.
|
|
19
|
+
"description": "在整个 DSH 界面(含工作台业务页与宿主弹窗之外的所有区域)与桌面透明层轮播自建弹幕;含弹幕库、配置与 Action 三个视图",
|
|
20
|
+
"version": "0.3.2",
|
|
21
21
|
"minShell": "0.8.0",
|
|
22
22
|
"tables": [
|
|
23
23
|
"danmaku"
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"views": [
|
|
26
26
|
"library",
|
|
27
27
|
"config",
|
|
28
|
-
"data",
|
|
29
28
|
"actions"
|
|
30
29
|
],
|
|
31
30
|
"toolActions": [
|
|
@@ -40,9 +39,7 @@
|
|
|
40
39
|
"danmaku.configReset",
|
|
41
40
|
"danmaku.theme",
|
|
42
41
|
"danmaku.desktop",
|
|
43
|
-
"danmaku.status"
|
|
44
|
-
"danmaku.dataTables",
|
|
45
|
-
"danmaku.dataQuery"
|
|
42
|
+
"danmaku.status"
|
|
46
43
|
],
|
|
47
44
|
"client": "lib/client.js"
|
|
48
45
|
}
|
|
@@ -53,7 +50,7 @@
|
|
|
53
50
|
"./package.json": "./package.json"
|
|
54
51
|
},
|
|
55
52
|
"dependencies": {
|
|
56
|
-
"dsh-workbench-host": "^0.
|
|
53
|
+
"dsh-workbench-host": "^0.17.6"
|
|
57
54
|
},
|
|
58
55
|
"dsh": {
|
|
59
56
|
"bundle": {
|
package/lib/actions/data.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// 数据页的两个只读 action:表清单与分页查询,表名/列名全走白名单。
|
|
3
|
-
|
|
4
|
-
import { DOMAIN } from "../config.js";
|
|
5
|
-
|
|
6
|
-
const TABLES = [{ name: "danmaku", zh: "弹幕", en: "Danmaku" }];
|
|
7
|
-
|
|
8
|
-
const COLUMN_LABELS = {
|
|
9
|
-
id: { zh: "ID", en: "ID" },
|
|
10
|
-
body: { zh: "内容", en: "Body" },
|
|
11
|
-
tone: { zh: "颜色", en: "Tone" },
|
|
12
|
-
enabled: { zh: "启用", en: "Enabled" },
|
|
13
|
-
card: { zh: "卡片背景", en: "Card" },
|
|
14
|
-
font_size: { zh: "字号", en: "Font size" },
|
|
15
|
-
speed: { zh: "速度", en: "Speed" },
|
|
16
|
-
opacity: { zh: "不透明度", en: "Opacity" },
|
|
17
|
-
font_weight: { zh: "字重", en: "Weight" },
|
|
18
|
-
font_family: { zh: "字体", en: "Typeface" },
|
|
19
|
-
band: { zh: "泳道区域", en: "Lane area" },
|
|
20
|
-
prefix: { zh: "前缀", en: "Prefix" },
|
|
21
|
-
chance: { zh: "权重", en: "Chance" },
|
|
22
|
-
sort_order: { zh: "顺序", en: "Sort order" },
|
|
23
|
-
created_at: { zh: "创建时间", en: "Created at" },
|
|
24
|
-
updated_at: { zh: "更新时间", en: "Updated at" },
|
|
25
|
-
deleted_at: { zh: "删除时间", en: "Deleted at" },
|
|
26
|
-
rev: { zh: "版本号", en: "Rev" },
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const SYSTEM_COLUMNS = new Set(["rev", "created_at", "updated_at", "deleted_at"]);
|
|
30
|
-
const PAGE_SIZES = [10, 25, 50, 100, 200];
|
|
31
|
-
const MAX_TEXT = 100;
|
|
32
|
-
|
|
33
|
-
function labelOf(name) {
|
|
34
|
-
const hit = COLUMN_LABELS[name];
|
|
35
|
-
return hit ? { zh: hit.zh, en: hit.en } : { zh: name, en: name };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function kindOf(name, declared) {
|
|
39
|
-
const type = String(declared || "").toUpperCase();
|
|
40
|
-
if (name === "id" || name.endsWith("_id")) return "id";
|
|
41
|
-
if (name.endsWith("_at") && type === "INTEGER") return "timestamp";
|
|
42
|
-
if (name === "card" || name === "enabled") return "bool";
|
|
43
|
-
if (type === "INTEGER" || type === "REAL") return "number";
|
|
44
|
-
return "text";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function pickPageSize(raw) {
|
|
48
|
-
const n = Math.floor(Number(raw));
|
|
49
|
-
if (!Number.isFinite(n) || n <= 0) return 50;
|
|
50
|
-
let best = PAGE_SIZES[0];
|
|
51
|
-
for (const size of PAGE_SIZES) if (Math.abs(size - n) < Math.abs(best - n)) best = size;
|
|
52
|
-
return best;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function likeEscape(text) {
|
|
56
|
-
return String(text).slice(0, MAX_TEXT).replace(/[\\%_]/g, (match) => "\\" + match);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function toPlain(row) {
|
|
60
|
-
const out = {};
|
|
61
|
-
for (const key of Object.keys(row)) out[key] = typeof row[key] === "bigint" ? Number(row[key]) : row[key];
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function registerDataActions(api) {
|
|
66
|
-
const db = api.db;
|
|
67
|
-
|
|
68
|
-
function columnList(table) {
|
|
69
|
-
try {
|
|
70
|
-
return db.prepare("PRAGMA table_info(" + table + ")").all().map((column) => ({
|
|
71
|
-
name: column.name,
|
|
72
|
-
type: String(column.type || ""),
|
|
73
|
-
kind: kindOf(column.name, column.type),
|
|
74
|
-
label: labelOf(column.name),
|
|
75
|
-
system: SYSTEM_COLUMNS.has(column.name),
|
|
76
|
-
pk: Boolean(column.pk),
|
|
77
|
-
}));
|
|
78
|
-
} catch (error) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function tableMeta() {
|
|
84
|
-
return TABLES.map((def) => {
|
|
85
|
-
const columns = columnList(def.name);
|
|
86
|
-
let count = 0;
|
|
87
|
-
let deletedCount = 0;
|
|
88
|
-
try {
|
|
89
|
-
const row = db
|
|
90
|
-
.prepare("SELECT COUNT(*) AS total, SUM(CASE WHEN deleted_at IS NULL THEN 1 ELSE 0 END) AS live FROM " + def.name)
|
|
91
|
-
.get();
|
|
92
|
-
count = Number(row && row.live) || 0;
|
|
93
|
-
deletedCount = Math.max(0, (Number(row && row.total) || 0) - count);
|
|
94
|
-
} catch (error) {
|
|
95
|
-
count = 0;
|
|
96
|
-
}
|
|
97
|
-
return { name: def.name, label: { zh: def.zh, en: def.en }, columns, count, deletedCount };
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
api.action("danmaku.dataTables", {
|
|
102
|
-
description: "只读:弹幕插件负责的表清单、列元信息与行数",
|
|
103
|
-
input: { type: "object", properties: {}, additionalProperties: false },
|
|
104
|
-
execute: () => ({ domain: DOMAIN, tables: tableMeta() }),
|
|
105
|
-
render: (r) => `弹幕数据表 ${r.tables.map((t) => t.name + "(" + t.count + ")").join("、")}`,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
api.action("danmaku.dataQuery", {
|
|
109
|
-
description: "只读:分页查询弹幕表;表名、排序列、筛选列都走白名单",
|
|
110
|
-
input: {
|
|
111
|
-
type: "object",
|
|
112
|
-
properties: {
|
|
113
|
-
table: { type: "string", description: "表名,目前只有 danmaku" },
|
|
114
|
-
page: { type: "number", description: "页码,从 1 开始,默认 1" },
|
|
115
|
-
pageSize: { type: "number", description: "每页数量,取 10/25/50/100/200 中最近的值,默认 50" },
|
|
116
|
-
sort: { type: "string", description: "排序列名(必须是真实列)" },
|
|
117
|
-
order: { type: "string", enum: ["asc", "desc"], description: "排序方向,默认 desc" },
|
|
118
|
-
search: { type: "string", description: "按弹幕内容模糊搜索" },
|
|
119
|
-
filters: { type: "object", description: "逐列包含筛选:{列名: 值}" },
|
|
120
|
-
includeDeleted: { type: "boolean", description: "包含已软删的行" },
|
|
121
|
-
},
|
|
122
|
-
required: ["table"],
|
|
123
|
-
additionalProperties: false,
|
|
124
|
-
},
|
|
125
|
-
execute: (args) => {
|
|
126
|
-
const def = TABLES.find((row) => row.name === String(args.table || ""));
|
|
127
|
-
if (!def) throw new Error("未知数据表:" + String(args.table || ""));
|
|
128
|
-
const columns = columnList(def.name);
|
|
129
|
-
const names = columns.map((column) => column.name);
|
|
130
|
-
const pageSize = pickPageSize(args.pageSize === undefined ? 50 : args.pageSize);
|
|
131
|
-
const page = Math.max(1, Number(args.page) || 1);
|
|
132
|
-
const order = args.order === "asc" ? "asc" : "desc";
|
|
133
|
-
const sort = args.sort && names.indexOf(String(args.sort)) >= 0 ? String(args.sort) : "created_at";
|
|
134
|
-
const where = [];
|
|
135
|
-
const params = [];
|
|
136
|
-
if (args.includeDeleted !== true) where.push("deleted_at IS NULL");
|
|
137
|
-
const search = String(args.search || "").trim().slice(0, MAX_TEXT);
|
|
138
|
-
if (search) {
|
|
139
|
-
where.push("instr(lower(body), lower(?)) > 0");
|
|
140
|
-
params.push(search);
|
|
141
|
-
}
|
|
142
|
-
const filters = args.filters && typeof args.filters === "object" && !Array.isArray(args.filters) ? args.filters : {};
|
|
143
|
-
for (const key of Object.keys(filters)) {
|
|
144
|
-
if (names.indexOf(key) < 0) throw new Error("未知筛选列:" + key);
|
|
145
|
-
const value = filters[key];
|
|
146
|
-
if (value === undefined || value === null) continue;
|
|
147
|
-
const text = String(value).trim().slice(0, MAX_TEXT);
|
|
148
|
-
if (!text) continue;
|
|
149
|
-
where.push("CAST(" + key + " AS TEXT) LIKE ? ESCAPE '\\'");
|
|
150
|
-
params.push("%" + likeEscape(text) + "%");
|
|
151
|
-
}
|
|
152
|
-
const whereSql = where.length ? where.join(" AND ") : "1=1";
|
|
153
|
-
const total = Number(db.prepare("SELECT COUNT(*) AS n FROM " + def.name + " WHERE " + whereSql).get(...params).n);
|
|
154
|
-
const rows = db
|
|
155
|
-
.prepare(
|
|
156
|
-
"SELECT * FROM " + def.name + " WHERE " + whereSql + " ORDER BY " + sort + " " + order + ", id " + order + " LIMIT ? OFFSET ?",
|
|
157
|
-
)
|
|
158
|
-
.all(...params, pageSize, (page - 1) * pageSize)
|
|
159
|
-
.map(toPlain);
|
|
160
|
-
return {
|
|
161
|
-
table: def.name,
|
|
162
|
-
columns,
|
|
163
|
-
rows,
|
|
164
|
-
total,
|
|
165
|
-
page,
|
|
166
|
-
pageSize,
|
|
167
|
-
pages: Math.max(1, Math.ceil(total / pageSize)),
|
|
168
|
-
sort,
|
|
169
|
-
order,
|
|
170
|
-
};
|
|
171
|
-
},
|
|
172
|
-
render: (r) => `表 ${r.table} 共 ${r.total} 行,第 ${r.page}/${r.pages} 页返回 ${r.rows.length} 行`,
|
|
173
|
-
});
|
|
174
|
-
}
|