icoa-cli 2.19.709 → 2.19.710
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/dist/commands/ai4ctf.js +1 -1
- package/dist/commands/ctf4ai-demo.js +1 -1
- package/dist/commands/ctf4vla.js +1 -1
- package/dist/commands/entry.js +1 -0
- package/dist/commands/exam.js +1 -1
- package/dist/commands/ipynb.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/access.js +1 -1
- package/dist/lib/commands.js +1 -1
- package/dist/lib/site.js +1 -1
- package/dist/repl.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import chalk from"chalk";import{logCommand as o}from"../lib/logger.js";import{asciiOnly as e,tx as n}from"../lib/guide-panel.js";import{ENTRIES as t,currentEntry as r,loadSite as s,setEntry as l}from"../lib/site.js";const c={hk:"hk",hongkong:"hk","hong-kong":"hk",cn:"hk",china:"hk",relay:"hk","香港":"hk",2:"hk",direct:"direct",default:"direct",practice:"direct",sg:"direct",singapore:"direct",off:"direct",normal:"direct","直连":"direct",1:"direct",auto:"auto",best:"auto","自动":"auto",status:"status",test:"status",list:"status"},i=()=>e()?"[ok]":"✅";async function a(o){const e=Date.now();try{const n=await fetch(`${o}/api/icoa/server-time?t=${e}`,{signal:AbortSignal.timeout(8e3)});return await n.arrayBuffer(),n.ok?Date.now()-e:null}catch{return null}}async function h(o){const e=[];for(let n=0;n<3;n++){const n=await a(t[o].base);null!==n&&e.push(n)}return e.sort((o,e)=>o-e),{key:o,ms:e.length?e[Math.floor(e.length/2)]:null,ok:e.length}}export function recommend(o,e,n="direct"){const[t,r]="hk"===n?[e,o]:[o,e];return null===r.ms?t.key:null===t.ms||t.ok<r.ok||t.ms>600&&t.ms>=2*r.ms?r.key:t.key}const g={direct:{en:"straight to Singapore (default)",zh:"直连新加坡(默认)"},hk:{en:"through Hong Kong — for mainland China",zh:"经香港中转 —— 适合中国大陆"}};function y(o){if(null===o.ms)return chalk.red(n({en:"no answer",zh:"无响应"}));const e=3-o.ok,t=e?chalk.yellow(n({en:` ${e} of 3 lost`,zh:` 3 次丢 ${e} 次`})):"";return chalk.white(`${o.ms} ms`)+t}function u(){for(const o of["ICOA_LEARN_SERVER","ICOA_EXAM_SERVER"])if(process.env[o]?.trim())return`${o} is set — it wins over the entry for that service.`;const o=s();return o.ok?`venue profile "${o.profile.name}" is active — it wins over the entry until it expires.`:null}function d(){console.log(chalk.gray(n({en:" Applies the next time icoa starts — if you are inside icoa now: exit, then icoa.",zh:" 下次启动 icoa 时生效 —— 如果你现在就在 icoa 里:exit,再敲 icoa。"})))}async function $(o){const s=e()?"[i]":"📖",c=r();console.log(),console.log(chalk.bold.white(` ${s} `)+chalk.bold.white(n({en:"Entry — which door icoa uses to reach the server",zh:"入口 —— icoa 走哪扇门连服务器"}))),console.log(chalk.gray(n({en:" Same server either way: your tokens, progress and scores do not change.",zh:" 两扇门后面是同一台服务器:token、进度、成绩都不变。"}))),console.log(chalk.gray(n({en:" Measuring both doors…",zh:" 正在测两扇门的速度…"})));const[a,$]=await Promise.all([h("direct"),h("hk")]);console.log();for(const o of[a,$]){const t=o.key===c,r=t?chalk.cyan(e()?" * ":" ● "):" ",s=chalk.cyan(o.key.padEnd(7)),l=chalk.gray(n(g[o.key])),i=t?chalk.cyan(n({en:e()?" <- in use":" ← in use",zh:" ← 正在用"})):"";console.log(` ${r}${s} ${y(o)} ${l}${i}`)}console.log();const k=u();if(k&&console.log(chalk.yellow(` ⚠ ${k}`)),null===a.ms&&null===$.ms)return console.log(chalk.yellow(n({en:" Neither door answered — this is the network here, not the entry.",zh:" 两扇门都没响应 —— 是这里的网络问题,不是入口的问题。"}))),console.log(chalk.green(n({en:" ▸ Type: doctor",zh:" ▸ 敲: doctor"}))),void console.log();const f=recommend(a,$,c);if(o&&f!==c)return l(f,"auto"),console.log(chalk.white(n({en:` ${i()} Switched to ${f} — ${t[f].label}.`,zh:` ${i()} 已切到 ${f}(${"hk"===f?"香港中转":"直连"})。`}))),d(),console.log(chalk.gray(n({en:" Undo: ",zh:" 撤销: "}))+chalk.cyan("entry "+("hk"===f?"direct":"hk"))),void console.log();f===c?(console.log(chalk.white(n({en:` ${i()} ${c} is the right door from here — nothing to change.`,zh:` ${i()} 从这里走 ${c} 就是对的 —— 不用改。`}))),console.log(chalk.gray(n({en:" Other door: ",zh:" 另一扇门: "}))+chalk.cyan("entry "+("hk"===c?"direct":"hk")))):(console.log(chalk.white(n({en:` ${f} is clearly better from this network.`,zh:` 从这个网络走 ${f} 明显更好。`}))),console.log(chalk.green(n({en:` ▸ Type: entry ${f}`,zh:` ▸ 敲: entry ${f}`})))),console.log()}export async function runEntry(e){o("entry"+(e?` ${e}`:""));const s=(e||"status").trim().toLowerCase(),a=c[s];return a?"status"===a?$(!1):"auto"===a?$(!0):void function(o){const e=r(),s="hk"===o?"direct":"hk";console.log(),e===o?console.log(chalk.white(n({en:` ${i()} Already using ${o} (${t[o].label}).`,zh:` ${i()} 已经在用 ${o}(${"hk"===o?"香港中转":"直连"})。`}))):(l(o,"user"),console.log(chalk.white(n({en:` ${i()} Entry set to ${o} (${t[o].label}) → ${t[o].base}`,zh:` ${i()} 入口已设为 ${o}(${"hk"===o?"香港中转":"直连"})→ ${t[o].base}`}))),d());const c=u();c&&console.log(chalk.yellow(` ⚠ ${c}`)),console.log(chalk.gray(n({en:" Other door: ",zh:" 另一扇门: "}))+chalk.cyan(`entry ${s}`)+chalk.gray(n({en:" · measure both: ",zh:" · 测两扇门: "}))+chalk.cyan("entry")),console.log()}(a):(console.log(),console.log(chalk.yellow(n({en:` "${e}" is not an entry.`,zh:` 「${e}」不是一个入口。`}))+chalk.gray(n({en:" Use one of: ",zh:" 可用: "}))+chalk.cyan("entry")+chalk.gray(" · ")+chalk.cyan("entry hk")+chalk.gray(" · ")+chalk.cyan("entry direct")+chalk.gray(" · ")+chalk.cyan("entry auto")),void console.log())}export function registerEntryCommand(o){o.command("entry [door]").description("Choose the door to the ICOA server: direct (default) · hk (Hong Kong relay, mainland China) · auto").action(runEntry)}
|