dsh-ustc-quota 1.1.26 → 1.1.28
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/client.js +83 -4
- package/index.js +41 -2
- 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.
|
|
14
|
+
const CLIENT_VERSION = '1.1.28';
|
|
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;
|
|
@@ -1156,7 +1173,19 @@ window.__ModuleLoader__.load({
|
|
|
1156
1173
|
if (columnWidth - (width + DOCK_GAP * 2) < DOCK_TRANSCRIPT_FLOOR) {
|
|
1157
1174
|
width = Math.max(DOCK_FLOOR_WIDTH, columnWidth - DOCK_TRANSCRIPT_FLOOR - DOCK_GAP * 2);
|
|
1158
1175
|
}
|
|
1159
|
-
|
|
1176
|
+
// A collapsed right sidebar keeps a narrow icon rail at the column's right edge;
|
|
1177
|
+
// the dock must stop before it, or it covers those native buttons.
|
|
1178
|
+
let railInset = 0;
|
|
1179
|
+
for (const button of document.querySelectorAll('button[aria-label]')) {
|
|
1180
|
+
const label = button.getAttribute('aria-label') || '';
|
|
1181
|
+
if (!/右侧边栏/.test(label)) continue;
|
|
1182
|
+
const rect = button.getBoundingClientRect();
|
|
1183
|
+
if (rect.width <= 0 || rect.height <= 0) continue;
|
|
1184
|
+
const inset = Math.round(columnRect.right - rect.left);
|
|
1185
|
+
if (inset > 0 && inset < Math.round(columnRect.width * 0.3)) railInset = Math.max(railInset, inset);
|
|
1186
|
+
}
|
|
1187
|
+
width = Math.max(DOCK_FLOOR_WIDTH, width - railInset);
|
|
1188
|
+
const reserve = width + railInset + DOCK_GAP * 2;
|
|
1160
1189
|
|
|
1161
1190
|
// Vertical bound: never cross or touch the separator under the tab strip.
|
|
1162
1191
|
let contentTop = Math.round(columnRect.top) + DOCK_GAP;
|
|
@@ -1169,10 +1198,46 @@ window.__ModuleLoader__.load({
|
|
|
1169
1198
|
}
|
|
1170
1199
|
}
|
|
1171
1200
|
|
|
1201
|
+
const rectOf = (el) => {
|
|
1202
|
+
if (!el) return null;
|
|
1203
|
+
const r = el.getBoundingClientRect();
|
|
1204
|
+
return { x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) };
|
|
1205
|
+
};
|
|
1206
|
+
const chain = [];
|
|
1207
|
+
let node = document.querySelector('[data-slot="conversation.chat.flow"]');
|
|
1208
|
+
while (node && chain.length < 8) {
|
|
1209
|
+
chain.push({ tag: node.tagName, cls: String(node.className || '').slice(0, 60), r: rectOf(node), pad: getComputedStyle(node).paddingRight });
|
|
1210
|
+
if (node === column) break;
|
|
1211
|
+
node = node.parentElement;
|
|
1212
|
+
}
|
|
1213
|
+
reportDiag({
|
|
1214
|
+
at: new Date().toISOString(),
|
|
1215
|
+
column: rectOf(column),
|
|
1216
|
+
columnPad: getComputedStyle(column).paddingRight,
|
|
1217
|
+
columnInlinePad: column.style.getPropertyValue('padding-right'),
|
|
1218
|
+
flowChain: chain,
|
|
1219
|
+
handles: [...document.querySelectorAll('[class*="widthHandle"]')].map((el) => ({ side: el.getAttribute('data-side'), r: rectOf(el) })),
|
|
1220
|
+
nav: (() => {
|
|
1221
|
+
let min = null;
|
|
1222
|
+
let count = 0;
|
|
1223
|
+
for (const b of document.querySelectorAll('button[aria-label]')) {
|
|
1224
|
+
const l = b.getAttribute('aria-label') || '';
|
|
1225
|
+
if (!/turnNavigation|轮次|跳转/i.test(l)) continue;
|
|
1226
|
+
const r = b.getBoundingClientRect();
|
|
1227
|
+
if (r.width <= 0) continue;
|
|
1228
|
+
count += 1;
|
|
1229
|
+
min = min === null ? r.left : Math.min(min, r.left);
|
|
1230
|
+
}
|
|
1231
|
+
return { count, left: min === null ? null : Math.round(min) };
|
|
1232
|
+
})(),
|
|
1233
|
+
dock: { width, reserve, top: contentTop, railInset },
|
|
1234
|
+
viewport: window.innerWidth,
|
|
1235
|
+
});
|
|
1172
1236
|
return {
|
|
1173
1237
|
top: contentTop,
|
|
1174
1238
|
width,
|
|
1175
1239
|
reserve,
|
|
1240
|
+
railInset,
|
|
1176
1241
|
maxHeight: Math.max(120, Math.round(columnRect.bottom) - contentTop - DOCK_GAP),
|
|
1177
1242
|
};
|
|
1178
1243
|
}
|
|
@@ -1218,8 +1283,22 @@ window.__ModuleLoader__.load({
|
|
|
1218
1283
|
if (!column) return undefined;
|
|
1219
1284
|
const saved = column.style.getPropertyValue('padding-right');
|
|
1220
1285
|
const priority = column.style.getPropertyPriority('padding-right');
|
|
1221
|
-
|
|
1286
|
+
const wanted = reserve + 'px';
|
|
1287
|
+
const apply = () => {
|
|
1288
|
+
if (column.style.getPropertyValue('padding-right') !== wanted) {
|
|
1289
|
+
column.style.setProperty('padding-right', wanted, 'important');
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
apply();
|
|
1293
|
+
// DSH re-renders the column and rewrites its style attribute, so watch it.
|
|
1294
|
+
const observer = typeof MutationObserver === 'function'
|
|
1295
|
+
? new MutationObserver(apply)
|
|
1296
|
+
: null;
|
|
1297
|
+
if (observer) observer.observe(column, { attributes: true, attributeFilter: ['style'] });
|
|
1298
|
+
const timer = window.setInterval(apply, 1000);
|
|
1222
1299
|
return () => {
|
|
1300
|
+
if (observer) observer.disconnect();
|
|
1301
|
+
window.clearInterval(timer);
|
|
1223
1302
|
if (saved) column.style.setProperty('padding-right', saved, priority);
|
|
1224
1303
|
else column.style.removeProperty('padding-right');
|
|
1225
1304
|
};
|
|
@@ -1230,7 +1309,7 @@ window.__ModuleLoader__.load({
|
|
|
1230
1309
|
style: {
|
|
1231
1310
|
position: 'fixed',
|
|
1232
1311
|
top: box ? box.top : 0,
|
|
1233
|
-
right: DOCK_GAP,
|
|
1312
|
+
right: DOCK_GAP + (box ? box.railInset : 0),
|
|
1234
1313
|
width: box ? box.width : DOCK_MIN_WIDTH,
|
|
1235
1314
|
maxHeight: box ? box.maxHeight : 0,
|
|
1236
1315
|
overflow: 'visible',
|
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.
|
|
28
|
+
const PLUGIN_VERSION = '1.1.28';
|
|
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