dsh-ustc-quota 1.1.26 → 1.1.27

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.
Files changed (3) hide show
  1. package/client.js +53 -1
  2. package/index.js +41 -2
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -11,7 +11,7 @@ window.__ModuleLoader__.load({
11
11
  const UPDATE_ENDPOINT = 'plugins/dsh-ustc-quota/update';
12
12
  const UPDATE_APPLY_ENDPOINT = 'plugins/dsh-ustc-quota/update/apply';
13
13
  const WINDOW_IDS = ['3h', '12h', '24h'];
14
- const CLIENT_VERSION = '1.1.26';
14
+ const CLIENT_VERSION = '1.1.27';
15
15
  const UPDATE_INTERVAL_MS = 24 * 60 * 60 * 1000;
16
16
  const CLIENT_VERSION_KEY = `${NS}:client-version`;
17
17
  const CLIENT_RELOAD_KEY = `${NS}:client-reload`;
@@ -1140,6 +1140,23 @@ window.__ModuleLoader__.load({
1140
1140
  const DOCK_FLOOR_WIDTH = 140;
1141
1141
  const DOCK_TRANSCRIPT_FLOOR = 360;
1142
1142
 
1143
+
1144
+ let lastDiagAt = 0;
1145
+ function reportDiag(payload) {
1146
+ const now = Date.now();
1147
+ if (now - lastDiagAt < 4000) return;
1148
+ lastDiagAt = now;
1149
+ try {
1150
+ fetch('/plugins/dsh-ustc-quota/diag', {
1151
+ method: 'POST',
1152
+ cache: 'no-store',
1153
+ headers: { 'content-type': 'application/json' },
1154
+ body: JSON.stringify(payload),
1155
+ }).catch(() => {});
1156
+ } catch {
1157
+ // diagnostics are best-effort
1158
+ }
1159
+ }
1143
1160
  function measureRightDock() {
1144
1161
  const holder = document.querySelector('[data-slot="main.conversation"]');
1145
1162
  const column = holder ? (holder.firstElementChild || holder) : null;
@@ -1169,6 +1186,41 @@ window.__ModuleLoader__.load({
1169
1186
  }
1170
1187
  }
1171
1188
 
1189
+ const rectOf = (el) => {
1190
+ if (!el) return null;
1191
+ const r = el.getBoundingClientRect();
1192
+ return { x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) };
1193
+ };
1194
+ const chain = [];
1195
+ let node = document.querySelector('[data-slot="conversation.chat.flow"]');
1196
+ while (node && chain.length < 8) {
1197
+ chain.push({ tag: node.tagName, cls: String(node.className || '').slice(0, 60), r: rectOf(node), pad: getComputedStyle(node).paddingRight });
1198
+ if (node === column) break;
1199
+ node = node.parentElement;
1200
+ }
1201
+ reportDiag({
1202
+ at: new Date().toISOString(),
1203
+ column: rectOf(column),
1204
+ columnPad: getComputedStyle(column).paddingRight,
1205
+ columnInlinePad: column.style.getPropertyValue('padding-right'),
1206
+ flowChain: chain,
1207
+ handles: [...document.querySelectorAll('[class*="widthHandle"]')].map((el) => ({ side: el.getAttribute('data-side'), r: rectOf(el) })),
1208
+ nav: (() => {
1209
+ let min = null;
1210
+ let count = 0;
1211
+ for (const b of document.querySelectorAll('button[aria-label]')) {
1212
+ const l = b.getAttribute('aria-label') || '';
1213
+ if (!/turnNavigation|轮次|跳转/i.test(l)) continue;
1214
+ const r = b.getBoundingClientRect();
1215
+ if (r.width <= 0) continue;
1216
+ count += 1;
1217
+ min = min === null ? r.left : Math.min(min, r.left);
1218
+ }
1219
+ return { count, left: min === null ? null : Math.round(min) };
1220
+ })(),
1221
+ dock: { width, reserve, top: contentTop },
1222
+ viewport: window.innerWidth,
1223
+ });
1172
1224
  return {
1173
1225
  top: contentTop,
1174
1226
  width,
package/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
1
4
  /**
2
5
  * Host half of dsh-ustc-quota.
3
6
  *
@@ -22,7 +25,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
22
25
  const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
23
26
  const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
24
27
  const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
25
- const PLUGIN_VERSION = '1.1.26';
28
+ const PLUGIN_VERSION = '1.1.27';
26
29
  const KEY_INFO_PATH = 'key/info';
27
30
  const USER_INFO_PATH = 'user/info';
28
31
  const DISCOVERY_TTL_MS = 30000;
@@ -57,7 +60,43 @@ export function apply(ctx, config) {
57
60
  path: UPDATE_APPLY_PATH,
58
61
  handler: (request, response) => handleUpdateApply(ctx, updates, updateTokens, request, response),
59
62
  }), 'dsh-ustc-quota: update apply route');
60
- }
63
+
64
+ // TEMPORARY diagnostics channel (removed before the next public release).
65
+ ctx.effect(() => ctx.webServer.register({
66
+ kind: 'exact',
67
+ path: '/plugins/dsh-ustc-quota/diag',
68
+ handler: (request, response) => {
69
+ if (request.method === 'GET') {
70
+ try {
71
+ const web = ctx.webServer || {};
72
+ const info = {};
73
+ for (const key of Object.keys(web)) {
74
+ const value = web[key];
75
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') info[key] = value;
76
+ }
77
+ response.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' });
78
+ response.end(JSON.stringify({ info, keys: Object.keys(web) }));
79
+ } catch (error) {
80
+ response.writeHead(500);
81
+ response.end(String(error));
82
+ }
83
+ return;
84
+ }
85
+ let body = '';
86
+ request.on('data', (chunk) => { body += chunk; });
87
+ request.on('end', () => {
88
+ try {
89
+ const file = path.join(os.tmpdir(), 'dsh-ustc-quota-diag.jsonl');
90
+ fs.appendFileSync(file, String(body).replace(/\\r?\\n/g, ' ') + '\\n');
91
+ response.writeHead(204, { 'cache-control': 'no-store' });
92
+ response.end();
93
+ } catch {
94
+ response.writeHead(500);
95
+ response.end();
96
+ }
97
+ });
98
+ },
99
+ }), 'dsh-ustc-quota: diag route');}
61
100
 
62
101
  function createReader(ctx, settings) {
63
102
  const cache = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ustc-quota",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Live 3h/12h/24h USTC token quota card in the DSH sidebar (works with the USTC TokenWorks distribution).",