ai_co_discuss 0.4.54 → 0.4.55
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/package.json +1 -1
- package/runner/admin_panel.mjs +7 -4
- package/runner/i18n_en.mjs +0 -1
- package/runner/launcher.mjs +63 -1
- package/web/admin.css +1 -1
- package/web/admin.html +1 -1
- package/web/admin.js +13 -13
- package/web/codiscuss.ico +0 -0
- package/web/modern.css +1 -1
- package/web/modern.js +23 -23
package/package.json
CHANGED
package/runner/admin_panel.mjs
CHANGED
|
@@ -778,7 +778,7 @@ export function create_panel({ data, key, port, ops = {}, sessions = new Set() }
|
|
|
778
778
|
const url = new URL(request.url, 'http://127.0.0.1');
|
|
779
779
|
// Only a page this browser opened from this address; anything else (another site, a renamed host) is refused.
|
|
780
780
|
if (!hosts.has(String(request.headers.host || ''))) return send_json(response, 403, error_body(panel_error('只接受本机访问')));
|
|
781
|
-
if (url.pathname === '/enter') {
|
|
781
|
+
if (url.pathname === '/enter' || (url.pathname === '/' && url.searchParams.has('key'))) {
|
|
782
782
|
if (url.searchParams.get('key') !== key) return send_json(response, 403, error_body(panel_error('钥匙无效,请从任务栏图标打开管理面板')));
|
|
783
783
|
const session = randomBytes(24).toString('hex');
|
|
784
784
|
sessions.add(session);
|
|
@@ -1097,8 +1097,9 @@ function open_browser(url) {
|
|
|
1097
1097
|
spawn('rundll32', ['url.dll,FileProtocolHandler', url], { detached: true, stdio: 'ignore', windowsHide: true }).unref();
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
|
-
// The panel page's <title
|
|
1101
|
-
|
|
1100
|
+
// The panel page's <title> (web/admin.html, the same in every language); its own window carries it, which is how an open
|
|
1101
|
+
// window is found again. Not translated: a translated title missed the open window and opened another one beside it.
|
|
1102
|
+
const WINDOW_TITLE = '共议 · 管理面板';
|
|
1102
1103
|
const WINDOW_SIZE = '1180,860';
|
|
1103
1104
|
const EDGE_PATHS = [join(process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)', 'Microsoft', 'Edge', 'Application', 'msedge.exe'),
|
|
1104
1105
|
join(process.env.ProgramFiles || 'C:\\Program Files', 'Microsoft', 'Edge', 'Application', 'msedge.exe')];
|
|
@@ -1133,8 +1134,10 @@ function launch_panel_window(data, url) {
|
|
|
1133
1134
|
{ detached: true, stdio: 'ignore', windowsHide: false }).unref();
|
|
1134
1135
|
}
|
|
1135
1136
|
|
|
1137
|
+
// The window opens on the page's own address: Edge keeps an app window's size under its address's path, so opening
|
|
1138
|
+
// /enter and landing on / kept the owner's size under / and restored the older one under /enter each time.
|
|
1136
1139
|
function panel_url(state) {
|
|
1137
|
-
return `http://127.0.0.1:${state.port}
|
|
1140
|
+
return `http://127.0.0.1:${state.port}/?key=${state.key}`;
|
|
1138
1141
|
}
|
|
1139
1142
|
|
|
1140
1143
|
/** The owner's own site, for the icon's second entry. */
|
package/runner/i18n_en.mjs
CHANGED
|
@@ -145,7 +145,6 @@ export default {
|
|
|
145
145
|
",最近 {value1} 次": "; latest {value1}",
|
|
146
146
|
"{value1} 次执行失败{value2}:": "{value1} failed runs{value2}:",
|
|
147
147
|
"客户那边看到的是失败卡片和重试按钮;登录失效、额度用完这类问题要你在管理面板处理。": "The user sees a failure card and Retry button. Handle issues such as expired sign-ins or exhausted quotas in the admin panel.",
|
|
148
|
-
"共议 · 管理面板": "CoDiscuss · Admin panel",
|
|
149
148
|
"codiscuss local {value1} 失败(退出码 {value2})": "codiscuss local {value1} failed (exit code {value2})",
|
|
150
149
|
"管理面板已在运行:http://127.0.0.1:{value1}": "Admin panel is already running: http://127.0.0.1:{value1}",
|
|
151
150
|
"入口没有启动:{value1}\n": "Entry did not start: {value1}\n",
|
package/runner/launcher.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSyn
|
|
|
12
12
|
import { homedir, tmpdir } from 'node:os';
|
|
13
13
|
import { dirname, join } from 'node:path';
|
|
14
14
|
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { crc32, deflateSync, inflateSync } from 'node:zlib';
|
|
15
16
|
import { t } from './i18n.mjs';
|
|
16
17
|
|
|
17
18
|
const RUNNER = dirname(fileURLToPath(import.meta.url));
|
|
@@ -427,6 +428,66 @@ export function ico_from_pngs(images) {
|
|
|
427
428
|
return Buffer.concat([header, ...images.map(image => image.png)]);
|
|
428
429
|
}
|
|
429
430
|
|
|
431
|
+
// At or below this size a tile corner is only a pixel or two, and its half-transparent edge shows as a dark speck on the
|
|
432
|
+
// taskbar; such sizes get hard corners instead.
|
|
433
|
+
const HARD_CORNER_SIZE = 40;
|
|
434
|
+
|
|
435
|
+
/** Decode an 8-bit RGBA PNG (what Edge's screenshot writes) into { width, height, pixels }. */
|
|
436
|
+
function decode_rgba(png) {
|
|
437
|
+
let offset = 8, width = 0, height = 0;
|
|
438
|
+
const data = [];
|
|
439
|
+
while (offset < png.length) {
|
|
440
|
+
const length = png.readUInt32BE(offset), type = png.toString('ascii', offset + 4, offset + 8), body = png.subarray(offset + 8, offset + 8 + length);
|
|
441
|
+
if (type === 'IHDR') {
|
|
442
|
+
width = body.readUInt32BE(0); height = body.readUInt32BE(4);
|
|
443
|
+
if (body[8] !== 8 || body[9] !== 6) throw new Error('icon render is not 8-bit RGBA');
|
|
444
|
+
}
|
|
445
|
+
if (type === 'IDAT') data.push(body);
|
|
446
|
+
offset += 12 + length;
|
|
447
|
+
}
|
|
448
|
+
const raw = inflateSync(Buffer.concat(data)), stride = width * 4, pixels = Buffer.alloc(height * stride);
|
|
449
|
+
let previous = Buffer.alloc(stride);
|
|
450
|
+
for (let y = 0; y < height; y++) {
|
|
451
|
+
const filter = raw[y * (stride + 1)], line = raw.subarray(y * (stride + 1) + 1, (y + 1) * (stride + 1)), row = Buffer.alloc(stride);
|
|
452
|
+
for (let x = 0; x < stride; x++) {
|
|
453
|
+
const left = x >= 4 ? row[x - 4] : 0, up = previous[x], corner = x >= 4 ? previous[x - 4] : 0;
|
|
454
|
+
let value = line[x];
|
|
455
|
+
if (filter === 1) value += left;
|
|
456
|
+
else if (filter === 2) value += up;
|
|
457
|
+
else if (filter === 3) value += (left + up) >> 1;
|
|
458
|
+
else if (filter === 4) {
|
|
459
|
+
const guess = left + up - corner, to_left = Math.abs(guess - left), to_up = Math.abs(guess - up), to_corner = Math.abs(guess - corner);
|
|
460
|
+
value += to_left <= to_up && to_left <= to_corner ? left : to_up <= to_corner ? up : corner;
|
|
461
|
+
}
|
|
462
|
+
row[x] = value & 255;
|
|
463
|
+
}
|
|
464
|
+
row.copy(pixels, y * stride);
|
|
465
|
+
previous = row;
|
|
466
|
+
}
|
|
467
|
+
return { width, height, pixels };
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Encode RGBA pixels as a PNG. */
|
|
471
|
+
function encode_rgba({ width, height, pixels }) {
|
|
472
|
+
const chunk = (type, body) => {
|
|
473
|
+
const head = Buffer.alloc(8); head.writeUInt32BE(body.length, 0); head.write(type, 4, 'ascii');
|
|
474
|
+
const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(Buffer.concat([Buffer.from(type, 'ascii'), body])) >>> 0, 0);
|
|
475
|
+
return Buffer.concat([head, body, crc]);
|
|
476
|
+
};
|
|
477
|
+
const header = Buffer.alloc(13);
|
|
478
|
+
header.writeUInt32BE(width, 0); header.writeUInt32BE(height, 4); header[8] = 8; header[9] = 6;
|
|
479
|
+
const stride = width * 4, raw = Buffer.alloc(height * (stride + 1));
|
|
480
|
+
for (let y = 0; y < height; y++) pixels.copy(raw, y * (stride + 1) + 1, y * stride, (y + 1) * stride);
|
|
481
|
+
return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk('IHDR', header), chunk('IDAT', deflateSync(raw)), chunk('IEND', Buffer.alloc(0))]);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Make every pixel either fully transparent or fully opaque, so a small icon's corners have no half-transparent edge. */
|
|
485
|
+
export function hard_corners(png) {
|
|
486
|
+
const image = decode_rgba(png);
|
|
487
|
+
for (let index = 3; index < image.pixels.length; index += 4) image.pixels[index] = image.pixels[index] >= 128 ? 255 : 0;
|
|
488
|
+
return encode_rgba(image);
|
|
489
|
+
}
|
|
490
|
+
|
|
430
491
|
/** The light product mark on a white rounded tile, as the panel's window icon shows it. */
|
|
431
492
|
function tile_svg() {
|
|
432
493
|
return readFileSync(join(ROOT, 'web', 'mark-tile.svg'), 'utf8');
|
|
@@ -449,7 +510,8 @@ export function render_icon(folder) {
|
|
|
449
510
|
writeFileSync(page, `<!doctype html><html><body style="margin:0;background:transparent">${svg.replace('<svg ', `<svg width="${size}" height="${size}" `)}</body></html>`);
|
|
450
511
|
spawnSync(edge, ['--headless=new', '--disable-gpu', '--hide-scrollbars', `--user-data-dir=${join(work, 'profile')}`, '--default-background-color=00000000',
|
|
451
512
|
`--window-size=${size},${size}`, `--screenshot=${png}`, `file:///${page.replaceAll('\\', '/')}`], { windowsHide: true, timeout: 60_000 });
|
|
452
|
-
|
|
513
|
+
if (!existsSync(png)) return null;
|
|
514
|
+
return { size, png: size <= HARD_CORNER_SIZE ? hard_corners(readFileSync(png)) : readFileSync(png) };
|
|
453
515
|
});
|
|
454
516
|
if (images.some(image => !image)) return null;
|
|
455
517
|
const path = join(folder, 'codiscuss.ico');
|