dsh-ustc-quota 1.1.30 → 1.1.32
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 +12 -96
- package/index.js +2 -41
- 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.32';
|
|
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`;
|
|
@@ -1141,52 +1141,6 @@ window.__ModuleLoader__.load({
|
|
|
1141
1141
|
const DOCK_TRANSCRIPT_FLOOR = 360;
|
|
1142
1142
|
|
|
1143
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
|
-
}
|
|
1160
|
-
let reservedColumn = null;
|
|
1161
|
-
let reservedSaved = null;
|
|
1162
|
-
let reservedSavedPriority = '';
|
|
1163
|
-
|
|
1164
|
-
function applyReservedPadding(reserve) {
|
|
1165
|
-
const holder = document.querySelector('[data-slot="main.conversation"]');
|
|
1166
|
-
const column = holder ? (holder.firstElementChild || holder) : null;
|
|
1167
|
-
if (!column) return false;
|
|
1168
|
-
if (reservedColumn !== column) {
|
|
1169
|
-
releaseReservedPadding();
|
|
1170
|
-
reservedColumn = column;
|
|
1171
|
-
reservedSaved = column.style.getPropertyValue('padding-right');
|
|
1172
|
-
reservedSavedPriority = column.style.getPropertyPriority('padding-right');
|
|
1173
|
-
}
|
|
1174
|
-
const wanted = reserve + 'px';
|
|
1175
|
-
if (column.style.getPropertyValue('padding-right') !== wanted) {
|
|
1176
|
-
column.style.setProperty('padding-right', wanted, 'important');
|
|
1177
|
-
}
|
|
1178
|
-
return true;
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
function releaseReservedPadding() {
|
|
1182
|
-
if (!reservedColumn) return;
|
|
1183
|
-
if (reservedSaved) reservedColumn.style.setProperty('padding-right', reservedSaved, reservedSavedPriority);
|
|
1184
|
-
else reservedColumn.style.removeProperty('padding-right');
|
|
1185
|
-
reservedColumn = null;
|
|
1186
|
-
reservedSaved = null;
|
|
1187
|
-
reservedSavedPriority = '';
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
1144
|
function measureRightDock() {
|
|
1191
1145
|
const holder = document.querySelector('[data-slot="main.conversation"]');
|
|
1192
1146
|
const column = holder ? (holder.firstElementChild || holder) : null;
|
|
@@ -1203,19 +1157,26 @@ window.__ModuleLoader__.load({
|
|
|
1203
1157
|
if (columnWidth - (width + DOCK_GAP * 2) < DOCK_TRANSCRIPT_FLOOR) {
|
|
1204
1158
|
width = Math.max(DOCK_FLOOR_WIDTH, columnWidth - DOCK_TRANSCRIPT_FLOOR - DOCK_GAP * 2);
|
|
1205
1159
|
}
|
|
1206
|
-
// A collapsed right sidebar keeps a narrow icon rail at the column's right
|
|
1207
|
-
//
|
|
1160
|
+
// A collapsed right sidebar keeps a narrow icon rail at the column's right
|
|
1161
|
+
// edge. Only a small inset counts as that rail: a wide one means the sidebar is
|
|
1162
|
+
// open and the dock must not try to dodge a whole panel.
|
|
1208
1163
|
let railInset = 0;
|
|
1209
1164
|
for (const button of document.querySelectorAll('button[aria-label]')) {
|
|
1210
1165
|
const label = button.getAttribute('aria-label') || '';
|
|
1211
1166
|
if (!/右侧边栏/.test(label)) continue;
|
|
1212
1167
|
const rect = button.getBoundingClientRect();
|
|
1213
1168
|
if (rect.width <= 0 || rect.height <= 0) continue;
|
|
1169
|
+
if (rect.left < columnRect.left || rect.left > columnRect.right) continue;
|
|
1214
1170
|
const inset = Math.round(columnRect.right - rect.left);
|
|
1215
|
-
if (inset > 0 && inset
|
|
1171
|
+
if (inset > 0 && inset <= 72) railInset = Math.max(railInset, inset);
|
|
1216
1172
|
}
|
|
1217
1173
|
width = Math.max(DOCK_FLOOR_WIDTH, width - railInset);
|
|
1218
|
-
|
|
1174
|
+
let reserve = width + railInset + DOCK_GAP * 2;
|
|
1175
|
+
const reserveCap = Math.round(columnRect.width * 0.34);
|
|
1176
|
+
if (reserve > reserveCap) {
|
|
1177
|
+
reserve = Math.max(DOCK_FLOOR_WIDTH + DOCK_GAP * 2, reserveCap);
|
|
1178
|
+
width = Math.max(DOCK_FLOOR_WIDTH, reserve - railInset - DOCK_GAP * 2);
|
|
1179
|
+
}
|
|
1219
1180
|
|
|
1220
1181
|
// Vertical bound: never cross or touch the separator under the tab strip.
|
|
1221
1182
|
let contentTop = Math.round(columnRect.top) + DOCK_GAP;
|
|
@@ -1228,51 +1189,6 @@ window.__ModuleLoader__.load({
|
|
|
1228
1189
|
}
|
|
1229
1190
|
}
|
|
1230
1191
|
|
|
1231
|
-
const rectOf = (el) => {
|
|
1232
|
-
if (!el) return null;
|
|
1233
|
-
const r = el.getBoundingClientRect();
|
|
1234
|
-
return { x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) };
|
|
1235
|
-
};
|
|
1236
|
-
const chain = [];
|
|
1237
|
-
let node = document.querySelector('[data-slot="conversation.chat.flow"]');
|
|
1238
|
-
while (node && chain.length < 8) {
|
|
1239
|
-
chain.push({ tag: node.tagName, cls: String(node.className || '').slice(0, 60), r: rectOf(node), pad: getComputedStyle(node).paddingRight });
|
|
1240
|
-
if (node === column) break;
|
|
1241
|
-
node = node.parentElement;
|
|
1242
|
-
}
|
|
1243
|
-
reportDiag({
|
|
1244
|
-
at: new Date().toISOString(),
|
|
1245
|
-
column: rectOf(column),
|
|
1246
|
-
columnPad: getComputedStyle(column).paddingRight,
|
|
1247
|
-
columnInlinePad: column.style.getPropertyValue('padding-right'),
|
|
1248
|
-
flowChain: chain,
|
|
1249
|
-
handles: [...document.querySelectorAll('[class*="widthHandle"]')].map((el) => ({ side: el.getAttribute('data-side'), r: rectOf(el) })),
|
|
1250
|
-
nav: (() => {
|
|
1251
|
-
let min = null;
|
|
1252
|
-
let count = 0;
|
|
1253
|
-
for (const b of document.querySelectorAll('button[aria-label]')) {
|
|
1254
|
-
const l = b.getAttribute('aria-label') || '';
|
|
1255
|
-
if (!/turnNavigation|轮次|跳转/i.test(l)) continue;
|
|
1256
|
-
const r = b.getBoundingClientRect();
|
|
1257
|
-
if (r.width <= 0) continue;
|
|
1258
|
-
count += 1;
|
|
1259
|
-
min = min === null ? r.left : Math.min(min, r.left);
|
|
1260
|
-
}
|
|
1261
|
-
return { count, left: min === null ? null : Math.round(min) };
|
|
1262
|
-
})(),
|
|
1263
|
-
dock: { width, reserve, top: contentTop, railInset },
|
|
1264
|
-
position: (() => { try { return window.localStorage.getItem(POSITION_KEY); } catch { return null; } })(),
|
|
1265
|
-
dockRect: (() => {
|
|
1266
|
-
const el = document.querySelector('[data-ustc-quota-dock]');
|
|
1267
|
-
if (!el) return null;
|
|
1268
|
-
const r = el.getBoundingClientRect();
|
|
1269
|
-
return { x: Math.round(r.left), w: Math.round(r.width), display: getComputedStyle(el).display };
|
|
1270
|
-
})(),
|
|
1271
|
-
railButtons: [...document.querySelectorAll('button[aria-label]')]
|
|
1272
|
-
.filter((b) => /右侧边栏/.test(b.getAttribute('aria-label') || ''))
|
|
1273
|
-
.map((b) => ({ label: b.getAttribute('aria-label'), r: rectOf(b) })),
|
|
1274
|
-
viewport: window.innerWidth,
|
|
1275
|
-
});
|
|
1276
1192
|
return {
|
|
1277
1193
|
top: contentTop,
|
|
1278
1194
|
width,
|
package/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
1
|
/**
|
|
5
2
|
* Host half of dsh-ustc-quota.
|
|
6
3
|
*
|
|
@@ -25,7 +22,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
|
|
|
25
22
|
const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
|
|
26
23
|
const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
|
|
27
24
|
const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
|
|
28
|
-
const PLUGIN_VERSION = '1.1.
|
|
25
|
+
const PLUGIN_VERSION = '1.1.32';
|
|
29
26
|
const KEY_INFO_PATH = 'key/info';
|
|
30
27
|
const USER_INFO_PATH = 'user/info';
|
|
31
28
|
const DISCOVERY_TTL_MS = 30000;
|
|
@@ -60,43 +57,7 @@ export function apply(ctx, config) {
|
|
|
60
57
|
path: UPDATE_APPLY_PATH,
|
|
61
58
|
handler: (request, response) => handleUpdateApply(ctx, updates, updateTokens, request, response),
|
|
62
59
|
}), 'dsh-ustc-quota: update apply route');
|
|
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, ' ') + String.fromCharCode(10));
|
|
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');}
|
|
60
|
+
}
|
|
100
61
|
|
|
101
62
|
function createReader(ctx, settings) {
|
|
102
63
|
const cache = new Map();
|
package/package.json
CHANGED