icoa-cli 2.19.42 → 2.19.43
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/lang.js +34 -0
- package/package.json +1 -1
package/dist/commands/lang.js
CHANGED
|
@@ -106,6 +106,40 @@ export function registerLangCommand(program) {
|
|
|
106
106
|
console.log(chalk.gray(' Language changed. Type: demo'));
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
else if (state && state.session.token) {
|
|
110
|
+
// Real exam with token: re-fetch questions in new language from server
|
|
111
|
+
try {
|
|
112
|
+
const { getConfig } = await import('../lib/config.js');
|
|
113
|
+
const { saveExamState } = await import('../lib/exam-state.js');
|
|
114
|
+
const { getDeviceFingerprint } = await import('../lib/access.js');
|
|
115
|
+
const config = getConfig();
|
|
116
|
+
const serverUrl = config.ctfdUrl || 'https://practice.icoa2026.au';
|
|
117
|
+
const token = state.session.token;
|
|
118
|
+
const res = await fetch(`${serverUrl}/api/icoa/exam-token`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: { 'Content-Type': 'application/json' },
|
|
121
|
+
body: JSON.stringify({ token, deviceHash: getDeviceFingerprint(), lang: code }),
|
|
122
|
+
signal: AbortSignal.timeout(10000),
|
|
123
|
+
});
|
|
124
|
+
if (res.ok) {
|
|
125
|
+
const json = await res.json();
|
|
126
|
+
const newQuestions = json.data.questions;
|
|
127
|
+
// Keep answers, interactions, aiUsage — only update question text
|
|
128
|
+
state.questions = newQuestions;
|
|
129
|
+
saveExamState(state);
|
|
130
|
+
const currentQ = state._lastQ || 1;
|
|
131
|
+
console.log();
|
|
132
|
+
printSuccess(`Exam questions updated to ${LANG_NAMES[code] || code}. Your answers are kept.`);
|
|
133
|
+
console.log(chalk.white(` Resume: exam q ${currentQ}`));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
console.log(chalk.yellow(' Could not reload questions in new language. Try again later.'));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
console.log(chalk.yellow(' Could not reach server. Language changed for UI only.'));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
109
143
|
else if (state) {
|
|
110
144
|
const currentQ = state._lastQ || 1;
|
|
111
145
|
console.log();
|