@langlink/dsh-memoq 0.1.7 → 0.1.9
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/README.md +1 -1
- package/bin/MemoQ.Bridge.Helper.exe +0 -0
- package/dist/index.js +1814 -380
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/skills/memoq-setup-troubleshoot/SKILL.md +5 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/dsh-memoq/src/index.ts
|
|
2
2
|
import { existsSync as existsSync9, mkdirSync as mkdirSync6, readFileSync as readFileSync8, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
3
|
-
import { dirname as
|
|
3
|
+
import { dirname as dirname7, join as join9, resolve as resolve6 } from "node:path";
|
|
4
4
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
5
5
|
|
|
6
6
|
// packages/memoq-bridge/src/contract.ts
|
|
@@ -823,18 +823,18 @@ function createPreviewClient(options = {}) {
|
|
|
823
823
|
}
|
|
824
824
|
const id = randomUUID();
|
|
825
825
|
const message = JSON.stringify({ ...payload, id }) + "\n";
|
|
826
|
-
return new Promise((
|
|
826
|
+
return new Promise((resolve7) => {
|
|
827
827
|
const timer = setTimeout(() => {
|
|
828
828
|
pendingAcks.delete(id);
|
|
829
|
-
|
|
829
|
+
resolve7({ ok: false, error: `Preview helper command timed out (${String(payload.type ?? "unknown")}).` });
|
|
830
830
|
}, timeoutMs);
|
|
831
|
-
pendingAcks.set(id, { resolve:
|
|
831
|
+
pendingAcks.set(id, { resolve: resolve7, timer });
|
|
832
832
|
try {
|
|
833
833
|
child.stdin.write(message, "utf8");
|
|
834
834
|
} catch (error) {
|
|
835
835
|
clearTimeout(timer);
|
|
836
836
|
pendingAcks.delete(id);
|
|
837
|
-
|
|
837
|
+
resolve7({ ok: false, error: error instanceof Error ? error.message : String(error) });
|
|
838
838
|
}
|
|
839
839
|
});
|
|
840
840
|
}
|
|
@@ -972,9 +972,9 @@ function createPreviewClient(options = {}) {
|
|
|
972
972
|
const settleMs = Math.max(0, Math.min(500, query.settleMs ?? 80));
|
|
973
973
|
if (settleMs > 0 && lastEventAtMs > 0 && Date.now() - lastEventAtMs < settleMs) {
|
|
974
974
|
const firstRev = revision;
|
|
975
|
-
await new Promise((
|
|
975
|
+
await new Promise((resolve7) => setTimeout(resolve7, settleMs));
|
|
976
976
|
if (revision !== firstRev) {
|
|
977
|
-
await new Promise((
|
|
977
|
+
await new Promise((resolve7) => setTimeout(resolve7, settleMs));
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
const doc = resolveDocument();
|
|
@@ -4969,17 +4969,23 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
4969
4969
|
<head>
|
|
4970
4970
|
<meta charset="utf-8" />
|
|
4971
4971
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
4972
|
-
<title>LangLink memoQ \u53CC\u8BED\u5BA1\u6821\u4E0E QA \u5DE5\u4F5C\u53F0</title>
|
|
4972
|
+
<title>LangLink memoQ CAT \u53CC\u8BED\u5BA1\u6821\u4E0E QA \u5DE5\u4F5C\u53F0</title>
|
|
4973
4973
|
<style>
|
|
4974
4974
|
:root {
|
|
4975
4975
|
color-scheme: light dark;
|
|
4976
|
-
--bg: #
|
|
4977
|
-
--
|
|
4976
|
+
--bg: #eef2f6;
|
|
4977
|
+
--panel: #ffffff;
|
|
4978
4978
|
--subtle: #f8fafc;
|
|
4979
|
-
--
|
|
4980
|
-
--
|
|
4981
|
-
--
|
|
4979
|
+
--grid-head: #f1f5f9;
|
|
4980
|
+
--row-hover: #f8fafc;
|
|
4981
|
+
--row-active: #eff6ff;
|
|
4982
|
+
--text: #0f172a;
|
|
4983
|
+
--muted: #475569;
|
|
4984
|
+
--faint: #64748b;
|
|
4985
|
+
--border: #cbd5e1;
|
|
4986
|
+
--border-soft: #e2e8f0;
|
|
4982
4987
|
--accent: #1d4ed8;
|
|
4988
|
+
--accent-solid: #2563eb;
|
|
4983
4989
|
--accent-soft: #dbeafe;
|
|
4984
4990
|
--ok: #15803d;
|
|
4985
4991
|
--ok-soft: #dcfce7;
|
|
@@ -4989,16 +4995,25 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
4989
4995
|
--err-soft: #fee2e2;
|
|
4990
4996
|
--rev: #6d28d9;
|
|
4991
4997
|
--rev-soft: #ede9fe;
|
|
4998
|
+
--tag-bg: #e0f2fe;
|
|
4999
|
+
--tag-fg: #0369a1;
|
|
5000
|
+
--tag-border: #bae6fd;
|
|
4992
5001
|
}
|
|
4993
5002
|
@media (prefers-color-scheme: dark) {
|
|
4994
5003
|
:root {
|
|
4995
|
-
--bg: #
|
|
4996
|
-
--
|
|
5004
|
+
--bg: #0b1120;
|
|
5005
|
+
--panel: #111827;
|
|
4997
5006
|
--subtle: #0f172a;
|
|
5007
|
+
--grid-head: #1e293b;
|
|
5008
|
+
--row-hover: #172033;
|
|
5009
|
+
--row-active: #172554;
|
|
4998
5010
|
--text: #f1f5f9;
|
|
4999
5011
|
--muted: #94a3b8;
|
|
5012
|
+
--faint: #64748b;
|
|
5000
5013
|
--border: #334155;
|
|
5014
|
+
--border-soft: #1e293b;
|
|
5001
5015
|
--accent: #60a5fa;
|
|
5016
|
+
--accent-solid: #3b82f6;
|
|
5002
5017
|
--accent-soft: #1e3a8a;
|
|
5003
5018
|
--ok: #4ade80;
|
|
5004
5019
|
--ok-soft: #14532d;
|
|
@@ -5008,253 +5023,634 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5008
5023
|
--err-soft: #450a0a;
|
|
5009
5024
|
--rev: #c4b5fd;
|
|
5010
5025
|
--rev-soft: #2e1065;
|
|
5026
|
+
--tag-bg: #0c4a6e;
|
|
5027
|
+
--tag-fg: #7dd3fc;
|
|
5028
|
+
--tag-border: #0369a1;
|
|
5011
5029
|
}
|
|
5012
5030
|
}
|
|
5013
5031
|
* { box-sizing: border-box; }
|
|
5032
|
+
html, body { height: 100%; margin: 0; }
|
|
5014
5033
|
body {
|
|
5015
|
-
margin: 0;
|
|
5016
|
-
padding: 16px;
|
|
5017
5034
|
background: var(--bg);
|
|
5018
5035
|
color: var(--text);
|
|
5019
|
-
font:
|
|
5036
|
+
font: 13px/1.45 "Segoe UI", -apple-system, BlinkMacSystemFont, "Microsoft YaHei UI", sans-serif;
|
|
5037
|
+
display: flex;
|
|
5038
|
+
flex-direction: column;
|
|
5039
|
+
overflow: hidden;
|
|
5020
5040
|
}
|
|
5021
|
-
.
|
|
5022
|
-
.
|
|
5023
|
-
|
|
5041
|
+
.hidden { display: none !important; }
|
|
5042
|
+
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; }
|
|
5043
|
+
|
|
5044
|
+
/* Top CAT Ribbon */
|
|
5045
|
+
.cat-ribbon {
|
|
5046
|
+
flex-shrink: 0;
|
|
5047
|
+
min-height: 46px;
|
|
5048
|
+
background: var(--panel);
|
|
5049
|
+
border-bottom: 1px solid var(--border);
|
|
5050
|
+
padding: 6px 12px;
|
|
5051
|
+
display: flex;
|
|
5052
|
+
flex-wrap: wrap;
|
|
5053
|
+
align-items: center;
|
|
5054
|
+
justify-content: space-between;
|
|
5055
|
+
gap: 8px;
|
|
5056
|
+
}
|
|
5057
|
+
.ribbon-left, .ribbon-right {
|
|
5058
|
+
display: flex;
|
|
5059
|
+
flex-wrap: wrap;
|
|
5060
|
+
align-items: center;
|
|
5061
|
+
gap: 8px;
|
|
5062
|
+
min-width: 0;
|
|
5063
|
+
}
|
|
5064
|
+
.brand-chip {
|
|
5065
|
+
display: inline-flex;
|
|
5066
|
+
align-items: center;
|
|
5067
|
+
gap: 6px;
|
|
5068
|
+
font-weight: 700;
|
|
5069
|
+
font-size: 13px;
|
|
5070
|
+
letter-spacing: -0.01em;
|
|
5071
|
+
}
|
|
5072
|
+
.brand-badge {
|
|
5073
|
+
background: var(--accent-solid);
|
|
5074
|
+
color: #ffffff;
|
|
5075
|
+
border-radius: 5px;
|
|
5076
|
+
padding: 2px 6px;
|
|
5077
|
+
font-size: 11px;
|
|
5078
|
+
font-weight: 700;
|
|
5079
|
+
}
|
|
5080
|
+
.doc-title {
|
|
5081
|
+
margin: 0;
|
|
5082
|
+
font-size: 13px;
|
|
5083
|
+
font-weight: 600;
|
|
5084
|
+
max-width: 240px;
|
|
5085
|
+
white-space: nowrap;
|
|
5086
|
+
overflow: hidden;
|
|
5087
|
+
text-overflow: ellipsis;
|
|
5088
|
+
}
|
|
5089
|
+
.doc-select {
|
|
5090
|
+
max-width: 280px;
|
|
5091
|
+
height: 28px;
|
|
5092
|
+
padding: 2px 8px;
|
|
5024
5093
|
border: 1px solid var(--border);
|
|
5025
|
-
border-radius:
|
|
5026
|
-
|
|
5094
|
+
border-radius: 6px;
|
|
5095
|
+
background: var(--subtle);
|
|
5096
|
+
color: var(--text);
|
|
5097
|
+
font-size: 12px;
|
|
5027
5098
|
}
|
|
5028
|
-
|
|
5099
|
+
|
|
5100
|
+
/* Sub-toolbar */
|
|
5101
|
+
.cat-subbar {
|
|
5102
|
+
flex-shrink: 0;
|
|
5103
|
+
min-height: 38px;
|
|
5104
|
+
background: var(--panel);
|
|
5105
|
+
border-bottom: 1px solid var(--border);
|
|
5106
|
+
padding: 4px 12px;
|
|
5029
5107
|
display: flex;
|
|
5030
5108
|
flex-wrap: wrap;
|
|
5031
5109
|
align-items: center;
|
|
5032
5110
|
justify-content: space-between;
|
|
5033
|
-
gap:
|
|
5111
|
+
gap: 8px;
|
|
5034
5112
|
}
|
|
5035
|
-
.
|
|
5036
|
-
.
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
padding:
|
|
5041
|
-
border:
|
|
5113
|
+
.tabs { display: flex; gap: 4px; align-items: center; }
|
|
5114
|
+
.tab-btn {
|
|
5115
|
+
border: 1px solid transparent;
|
|
5116
|
+
background: transparent;
|
|
5117
|
+
color: var(--muted);
|
|
5118
|
+
padding: 4px 10px;
|
|
5119
|
+
border-radius: 5px;
|
|
5120
|
+
font-size: 12px;
|
|
5121
|
+
font-weight: 600;
|
|
5122
|
+
cursor: pointer;
|
|
5042
5123
|
}
|
|
5043
|
-
.
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
.
|
|
5049
|
-
.
|
|
5124
|
+
.tab-btn.active {
|
|
5125
|
+
background: var(--accent-soft);
|
|
5126
|
+
color: var(--accent);
|
|
5127
|
+
border-color: var(--accent);
|
|
5128
|
+
}
|
|
5129
|
+
.v-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
|
|
5130
|
+
.filter-pills { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
|
|
5131
|
+
.filter-pill {
|
|
5132
|
+
padding: 3px 9px;
|
|
5133
|
+
border-radius: 999px;
|
|
5134
|
+
font-size: 11px;
|
|
5135
|
+
font-weight: 500;
|
|
5136
|
+
border: 1px solid var(--border);
|
|
5137
|
+
background: var(--subtle);
|
|
5138
|
+
color: var(--text);
|
|
5139
|
+
cursor: pointer;
|
|
5140
|
+
}
|
|
5141
|
+
.filter-pill.active {
|
|
5142
|
+
background: var(--accent-solid);
|
|
5143
|
+
color: #ffffff;
|
|
5144
|
+
border-color: var(--accent-solid);
|
|
5145
|
+
}
|
|
5146
|
+
.search-wrap { display: flex; align-items: center; gap: 8px; }
|
|
5147
|
+
.kbd-hint { font-size: 11px; color: var(--faint); white-space: nowrap; }
|
|
5148
|
+
|
|
5149
|
+
/* Buttons & Inputs */
|
|
5050
5150
|
button {
|
|
5051
5151
|
cursor: pointer;
|
|
5052
|
-
border-radius:
|
|
5152
|
+
border-radius: 6px;
|
|
5053
5153
|
border: 1px solid var(--border);
|
|
5054
|
-
background: var(--
|
|
5154
|
+
background: var(--panel);
|
|
5055
5155
|
color: var(--text);
|
|
5056
|
-
padding:
|
|
5156
|
+
padding: 4px 10px;
|
|
5057
5157
|
font: inherit;
|
|
5058
|
-
font-size:
|
|
5158
|
+
font-size: 12px;
|
|
5059
5159
|
font-weight: 600;
|
|
5160
|
+
line-height: 1.35;
|
|
5060
5161
|
}
|
|
5061
|
-
button:hover {
|
|
5062
|
-
button.primary { background: var(--accent); color: #ffffff; border-color: var(--accent); }
|
|
5162
|
+
button:hover { border-color: var(--accent); }
|
|
5163
|
+
button.primary { background: var(--accent-solid); color: #ffffff; border-color: var(--accent-solid); }
|
|
5063
5164
|
button.success { background: #15803d; color: #ffffff; border-color: #15803d; }
|
|
5064
5165
|
button.warn { background: #b45309; color: #ffffff; border-color: #b45309; }
|
|
5065
|
-
button.sm { padding:
|
|
5166
|
+
button.sm { padding: 3px 7px; font-size: 11px; }
|
|
5167
|
+
button.active-toggle { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
|
|
5066
5168
|
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
5067
|
-
|
|
5169
|
+
input[type="text"], textarea, select {
|
|
5170
|
+
border: 1px solid var(--border);
|
|
5171
|
+
background: var(--subtle);
|
|
5172
|
+
color: var(--text);
|
|
5173
|
+
border-radius: 5px;
|
|
5174
|
+
padding: 4px 8px;
|
|
5175
|
+
font: inherit;
|
|
5176
|
+
font-size: 12px;
|
|
5177
|
+
}
|
|
5178
|
+
|
|
5179
|
+
/* Pills */
|
|
5180
|
+
.pill {
|
|
5181
|
+
display: inline-flex;
|
|
5182
|
+
align-items: center;
|
|
5183
|
+
gap: 4px;
|
|
5184
|
+
padding: 2px 8px;
|
|
5185
|
+
border-radius: 999px;
|
|
5186
|
+
font-size: 11px;
|
|
5187
|
+
font-weight: 600;
|
|
5188
|
+
border: 1px solid var(--border);
|
|
5189
|
+
background: var(--subtle);
|
|
5190
|
+
white-space: nowrap;
|
|
5191
|
+
}
|
|
5192
|
+
.pill.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
|
|
5193
|
+
.pill.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
|
|
5194
|
+
.pill.err { color: var(--err); background: var(--err-soft); border-color: transparent; }
|
|
5195
|
+
.pill.rev { color: var(--rev); background: var(--rev-soft); border-color: transparent; }
|
|
5196
|
+
.pill.info { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
|
|
5197
|
+
|
|
5198
|
+
/* Collapsible QA Config & Banners */
|
|
5199
|
+
.qa-panel {
|
|
5200
|
+
flex-shrink: 0;
|
|
5201
|
+
background: var(--subtle);
|
|
5202
|
+
border-bottom: 1px solid var(--border);
|
|
5068
5203
|
padding: 10px 14px;
|
|
5069
|
-
|
|
5070
|
-
|
|
5204
|
+
max-height: 280px;
|
|
5205
|
+
overflow-y: auto;
|
|
5206
|
+
}
|
|
5207
|
+
.rule-grid {
|
|
5208
|
+
display: grid;
|
|
5209
|
+
grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
|
|
5210
|
+
gap: 4px 10px;
|
|
5211
|
+
margin-top: 6px;
|
|
5212
|
+
}
|
|
5213
|
+
.rule-item { display: flex; gap: 6px; align-items: flex-start; font-size: 11px; }
|
|
5214
|
+
.box-label { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
|
|
5215
|
+
.banner {
|
|
5216
|
+
flex-shrink: 0;
|
|
5217
|
+
padding: 6px 14px;
|
|
5218
|
+
font-size: 12px;
|
|
5219
|
+
border-bottom: 1px solid var(--border);
|
|
5071
5220
|
display: flex;
|
|
5072
5221
|
flex-wrap: wrap;
|
|
5073
5222
|
align-items: center;
|
|
5074
5223
|
justify-content: space-between;
|
|
5075
|
-
gap:
|
|
5224
|
+
gap: 8px;
|
|
5076
5225
|
}
|
|
5077
5226
|
.banner.ok { background: var(--ok-soft); color: var(--ok); }
|
|
5078
5227
|
.banner.warn { background: var(--warn-soft); color: var(--warn); }
|
|
5079
5228
|
.banner.err { background: var(--err-soft); color: var(--err); }
|
|
5080
5229
|
.banner.rev { background: var(--rev-soft); color: var(--rev); }
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
.
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
input[type="text"], textarea, select {
|
|
5090
|
-
border: 1px solid var(--border);
|
|
5091
|
-
background: var(--subtle);
|
|
5092
|
-
color: var(--text);
|
|
5093
|
-
border-radius: 6px;
|
|
5094
|
-
padding: 6px 8px;
|
|
5095
|
-
font: inherit;
|
|
5096
|
-
font-size: 13px;
|
|
5230
|
+
|
|
5231
|
+
/* Main Split CAT Workspace */
|
|
5232
|
+
.cat-workspace {
|
|
5233
|
+
flex: 1;
|
|
5234
|
+
min-height: 0;
|
|
5235
|
+
display: grid;
|
|
5236
|
+
grid-template-columns: minmax(0, 1fr) 336px;
|
|
5237
|
+
background: var(--bg);
|
|
5097
5238
|
}
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
background: var(--card);
|
|
5239
|
+
.cat-workspace.inspector-collapsed {
|
|
5240
|
+
grid-template-columns: minmax(0, 1fr);
|
|
5241
|
+
}
|
|
5242
|
+
.cat-main {
|
|
5243
|
+
min-width: 0;
|
|
5244
|
+
min-height: 0;
|
|
5105
5245
|
display: flex;
|
|
5106
5246
|
flex-direction: column;
|
|
5107
|
-
|
|
5247
|
+
background: var(--panel);
|
|
5248
|
+
overflow: hidden;
|
|
5249
|
+
}
|
|
5250
|
+
.cat-grid-scroll {
|
|
5251
|
+
flex: 1;
|
|
5252
|
+
min-height: 0;
|
|
5253
|
+
overflow: auto;
|
|
5254
|
+
scrollbar-gutter: stable;
|
|
5255
|
+
}
|
|
5256
|
+
|
|
5257
|
+
/* Classic 4-column CAT Bilingual Grid */
|
|
5258
|
+
.cat-grid-head, .cat-row {
|
|
5259
|
+
display: grid;
|
|
5260
|
+
grid-template-columns: 60px minmax(0, 1fr) minmax(0, 1fr) 128px;
|
|
5261
|
+
align-items: stretch;
|
|
5262
|
+
}
|
|
5263
|
+
.cat-grid-head {
|
|
5264
|
+
position: sticky;
|
|
5265
|
+
top: 0;
|
|
5266
|
+
z-index: 3;
|
|
5267
|
+
background: var(--grid-head);
|
|
5268
|
+
border-bottom: 1px solid var(--border);
|
|
5269
|
+
font-size: 11px;
|
|
5270
|
+
font-weight: 700;
|
|
5271
|
+
color: var(--muted);
|
|
5272
|
+
text-transform: uppercase;
|
|
5273
|
+
letter-spacing: 0.02em;
|
|
5274
|
+
}
|
|
5275
|
+
.cat-grid-head > div {
|
|
5276
|
+
padding: 7px 10px;
|
|
5277
|
+
}
|
|
5278
|
+
.cat-grid-head > div:nth-child(3),
|
|
5279
|
+
.cat-grid-head > div:nth-child(4) {
|
|
5280
|
+
border-left: 1px solid var(--border-soft);
|
|
5281
|
+
}
|
|
5282
|
+
|
|
5283
|
+
.cat-row {
|
|
5284
|
+
border-bottom: 1px solid var(--border-soft);
|
|
5285
|
+
background: var(--panel);
|
|
5286
|
+
transition: background 120ms ease;
|
|
5287
|
+
}
|
|
5288
|
+
.cat-row:hover { background: var(--row-hover); }
|
|
5289
|
+
.cat-row.active-row {
|
|
5290
|
+
background: var(--row-active);
|
|
5291
|
+
}
|
|
5292
|
+
.cat-rail {
|
|
5293
|
+
padding: 9px 6px;
|
|
5294
|
+
display: flex;
|
|
5295
|
+
flex-direction: column;
|
|
5296
|
+
align-items: center;
|
|
5297
|
+
gap: 4px;
|
|
5298
|
+
border-left: 3px solid transparent;
|
|
5299
|
+
color: var(--muted);
|
|
5300
|
+
font-variant-numeric: tabular-nums;
|
|
5301
|
+
font-size: 11px;
|
|
5302
|
+
user-select: none;
|
|
5303
|
+
}
|
|
5304
|
+
.cat-row.st-approved .cat-rail { border-left-color: var(--ok); }
|
|
5305
|
+
.cat-row.st-draft .cat-rail { border-left-color: var(--warn); }
|
|
5306
|
+
.cat-row.st-needs_revision .cat-rail { border-left-color: var(--rev); }
|
|
5307
|
+
.cat-row.st-memoq .cat-rail { border-left-color: var(--border); }
|
|
5308
|
+
.cat-row.active-row .cat-rail { border-left-color: var(--accent-solid); }
|
|
5309
|
+
|
|
5310
|
+
.doc-chip {
|
|
5311
|
+
font-size: 10px;
|
|
5312
|
+
padding: 1px 4px;
|
|
5313
|
+
border-radius: 3px;
|
|
5314
|
+
background: var(--accent-soft);
|
|
5315
|
+
color: var(--accent);
|
|
5316
|
+
max-width: 50px;
|
|
5317
|
+
overflow: hidden;
|
|
5318
|
+
text-overflow: ellipsis;
|
|
5319
|
+
white-space: nowrap;
|
|
5320
|
+
}
|
|
5321
|
+
.cat-source {
|
|
5322
|
+
min-width: 0;
|
|
5323
|
+
padding: 9px 12px;
|
|
5324
|
+
border-left: 1px solid var(--border-soft);
|
|
5325
|
+
display: flex;
|
|
5326
|
+
flex-direction: column;
|
|
5327
|
+
gap: 6px;
|
|
5108
5328
|
}
|
|
5109
|
-
.
|
|
5110
|
-
.seg-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
|
|
5111
|
-
.seg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
5112
|
-
@media (max-width: 900px) { .seg-grid { grid-template-columns: 1fr; } }
|
|
5113
|
-
.box-label { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
|
|
5114
|
-
.pre-text {
|
|
5329
|
+
.src-text {
|
|
5115
5330
|
white-space: pre-wrap;
|
|
5116
5331
|
word-break: break-word;
|
|
5117
|
-
background: var(--subtle);
|
|
5118
|
-
border: 1px solid var(--border);
|
|
5119
|
-
border-radius: 6px;
|
|
5120
|
-
padding: 8px 10px;
|
|
5121
5332
|
font-size: 13px;
|
|
5333
|
+
line-height: 1.65;
|
|
5334
|
+
color: var(--text);
|
|
5335
|
+
}
|
|
5336
|
+
.cat-tag {
|
|
5337
|
+
display: inline-block;
|
|
5338
|
+
margin: 0 1px;
|
|
5339
|
+
padding: 0 4px;
|
|
5340
|
+
border-radius: 3px;
|
|
5341
|
+
font-family: ui-monospace, Consolas, monospace;
|
|
5342
|
+
font-size: 11px;
|
|
5343
|
+
line-height: 1.4;
|
|
5344
|
+
background: var(--tag-bg);
|
|
5345
|
+
color: var(--tag-fg);
|
|
5346
|
+
border: 1px solid var(--tag-border);
|
|
5347
|
+
vertical-align: baseline;
|
|
5348
|
+
}
|
|
5349
|
+
.cat-target {
|
|
5350
|
+
min-width: 0;
|
|
5351
|
+
padding: 7px 10px;
|
|
5352
|
+
border-left: 1px solid var(--border-soft);
|
|
5353
|
+
display: flex;
|
|
5354
|
+
flex-direction: column;
|
|
5355
|
+
gap: 4px;
|
|
5356
|
+
}
|
|
5357
|
+
.tgt-edit {
|
|
5358
|
+
width: 100%;
|
|
5122
5359
|
min-height: 44px;
|
|
5360
|
+
padding: 5px 7px;
|
|
5361
|
+
border: 1px solid transparent;
|
|
5362
|
+
border-radius: 5px;
|
|
5363
|
+
background: transparent;
|
|
5364
|
+
color: var(--text);
|
|
5365
|
+
font: 13px/1.65 "Segoe UI", -apple-system, BlinkMacSystemFont, "Microsoft YaHei UI", sans-serif;
|
|
5366
|
+
resize: vertical;
|
|
5367
|
+
outline: none;
|
|
5368
|
+
}
|
|
5369
|
+
.cat-row:hover .tgt-edit { border-color: var(--border-soft); background: var(--panel); }
|
|
5370
|
+
.tgt-edit:focus {
|
|
5371
|
+
border-color: var(--accent-solid);
|
|
5372
|
+
background: var(--panel);
|
|
5373
|
+
box-shadow: 0 0 0 2px var(--accent-soft);
|
|
5374
|
+
}
|
|
5375
|
+
.memoq-ref-line {
|
|
5376
|
+
font-size: 11px;
|
|
5377
|
+
color: var(--muted);
|
|
5378
|
+
padding: 3px 6px;
|
|
5379
|
+
border-left: 2px solid var(--border);
|
|
5380
|
+
background: var(--subtle);
|
|
5381
|
+
white-space: pre-wrap;
|
|
5382
|
+
word-break: break-word;
|
|
5123
5383
|
}
|
|
5124
|
-
.
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5384
|
+
.cmt-chip {
|
|
5385
|
+
font-size: 11px;
|
|
5386
|
+
color: var(--rev);
|
|
5387
|
+
background: var(--rev-soft);
|
|
5388
|
+
padding: 2px 7px;
|
|
5389
|
+
border-radius: 4px;
|
|
5390
|
+
width: fit-content;
|
|
5391
|
+
max-width: 100%;
|
|
5392
|
+
word-break: break-word;
|
|
5393
|
+
}
|
|
5394
|
+
.dirty-tag {
|
|
5395
|
+
display: inline-block;
|
|
5396
|
+
font-size: 10px;
|
|
5397
|
+
color: var(--warn);
|
|
5398
|
+
font-weight: 600;
|
|
5399
|
+
}
|
|
5400
|
+
|
|
5401
|
+
.cat-status {
|
|
5402
|
+
padding: 8px 8px;
|
|
5403
|
+
border-left: 1px solid var(--border-soft);
|
|
5404
|
+
display: flex;
|
|
5405
|
+
flex-direction: column;
|
|
5406
|
+
align-items: flex-start;
|
|
5407
|
+
gap: 5px;
|
|
5408
|
+
}
|
|
5409
|
+
.row-mini-btns {
|
|
5410
|
+
display: flex;
|
|
5411
|
+
flex-wrap: wrap;
|
|
5412
|
+
gap: 4px;
|
|
5413
|
+
}
|
|
5414
|
+
.badge-list { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
5415
|
+
|
|
5416
|
+
/* Docked CAT Inspector */
|
|
5417
|
+
.cat-inspector {
|
|
5418
|
+
min-width: 0;
|
|
5419
|
+
min-height: 0;
|
|
5420
|
+
border-left: 1px solid var(--border);
|
|
5421
|
+
background: var(--panel);
|
|
5422
|
+
display: flex;
|
|
5423
|
+
flex-direction: column;
|
|
5424
|
+
overflow-y: auto;
|
|
5425
|
+
padding: 12px;
|
|
5426
|
+
gap: 12px;
|
|
5427
|
+
}
|
|
5428
|
+
.cat-workspace.inspector-collapsed .cat-inspector { display: none; }
|
|
5429
|
+
.insp-section {
|
|
5430
|
+
border: 1px solid var(--border-soft);
|
|
5431
|
+
border-radius: 7px;
|
|
5432
|
+
padding: 9px 10px;
|
|
5128
5433
|
background: var(--subtle);
|
|
5434
|
+
display: flex;
|
|
5435
|
+
flex-direction: column;
|
|
5436
|
+
gap: 6px;
|
|
5437
|
+
}
|
|
5438
|
+
.insp-title {
|
|
5439
|
+
font-size: 11px;
|
|
5440
|
+
font-weight: 700;
|
|
5441
|
+
color: var(--muted);
|
|
5442
|
+
text-transform: uppercase;
|
|
5443
|
+
letter-spacing: 0.02em;
|
|
5444
|
+
display: flex;
|
|
5445
|
+
align-items: center;
|
|
5446
|
+
justify-content: space-between;
|
|
5447
|
+
gap: 6px;
|
|
5448
|
+
}
|
|
5449
|
+
.insp-ref-text {
|
|
5129
5450
|
font-size: 12px;
|
|
5130
5451
|
white-space: pre-wrap;
|
|
5131
5452
|
word-break: break-word;
|
|
5453
|
+
line-height: 1.5;
|
|
5454
|
+
}
|
|
5455
|
+
.qa-issue-card {
|
|
5456
|
+
border: 1px solid var(--border-soft);
|
|
5457
|
+
border-radius: 6px;
|
|
5458
|
+
padding: 7px 8px;
|
|
5459
|
+
background: var(--panel);
|
|
5460
|
+
font-size: 12px;
|
|
5461
|
+
display: flex;
|
|
5462
|
+
flex-direction: column;
|
|
5463
|
+
gap: 3px;
|
|
5464
|
+
}
|
|
5465
|
+
|
|
5466
|
+
/* QA Report Tab */
|
|
5467
|
+
.qa-table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
5468
|
+
.qa-table th, .qa-table td {
|
|
5469
|
+
border-bottom: 1px solid var(--border-soft);
|
|
5470
|
+
padding: 7px 10px;
|
|
5471
|
+
text-align: left;
|
|
5472
|
+
vertical-align: top;
|
|
5473
|
+
}
|
|
5474
|
+
.qa-table th {
|
|
5475
|
+
position: sticky;
|
|
5476
|
+
top: 0;
|
|
5477
|
+
background: var(--grid-head);
|
|
5478
|
+
font-size: 11px;
|
|
5479
|
+
color: var(--muted);
|
|
5480
|
+
border-bottom: 1px solid var(--border);
|
|
5481
|
+
}
|
|
5482
|
+
|
|
5483
|
+
/* Bottom CAT Status Bar */
|
|
5484
|
+
.cat-statusbar {
|
|
5485
|
+
flex-shrink: 0;
|
|
5486
|
+
min-height: 30px;
|
|
5487
|
+
background: var(--panel);
|
|
5488
|
+
border-top: 1px solid var(--border);
|
|
5489
|
+
padding: 4px 12px;
|
|
5490
|
+
display: flex;
|
|
5491
|
+
flex-wrap: wrap;
|
|
5492
|
+
align-items: center;
|
|
5493
|
+
justify-content: space-between;
|
|
5494
|
+
gap: 10px;
|
|
5495
|
+
font-size: 11px;
|
|
5496
|
+
color: var(--muted);
|
|
5497
|
+
}
|
|
5498
|
+
.status-group { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
|
5499
|
+
.progress-track {
|
|
5500
|
+
width: 110px;
|
|
5501
|
+
height: 6px;
|
|
5502
|
+
border-radius: 999px;
|
|
5503
|
+
background: var(--border-soft);
|
|
5504
|
+
overflow: hidden;
|
|
5505
|
+
display: inline-block;
|
|
5506
|
+
vertical-align: middle;
|
|
5507
|
+
}
|
|
5508
|
+
.progress-fill {
|
|
5509
|
+
height: 100%;
|
|
5510
|
+
width: 0%;
|
|
5511
|
+
background: var(--ok);
|
|
5512
|
+
transition: width 200ms ease;
|
|
5513
|
+
}
|
|
5514
|
+
.empty-state {
|
|
5515
|
+
padding: 36px 20px;
|
|
5516
|
+
text-align: center;
|
|
5517
|
+
color: var(--muted);
|
|
5518
|
+
font-size: 13px;
|
|
5519
|
+
}
|
|
5520
|
+
@media (max-width: 1024px) {
|
|
5521
|
+
.cat-workspace { grid-template-columns: minmax(0, 1fr); }
|
|
5522
|
+
.cat-inspector { display: none; }
|
|
5523
|
+
.kbd-hint { display: none; }
|
|
5132
5524
|
}
|
|
5133
|
-
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
|
|
5134
|
-
.feedback-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; flex: 1; min-width: 260px; }
|
|
5135
|
-
.feedback-row input[type="text"] { flex: 1; min-width: 180px; }
|
|
5136
|
-
.qa-panel { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--subtle); }
|
|
5137
|
-
.rule-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 12px; margin-top: 8px; }
|
|
5138
|
-
.rule-item { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; }
|
|
5139
|
-
.qa-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
5140
|
-
.qa-table th, .qa-table td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
|
|
5141
|
-
.qa-table th { font-size: 12px; color: var(--muted); background: var(--subtle); }
|
|
5142
|
-
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
|
|
5143
|
-
.badge-list { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
5144
5525
|
</style>
|
|
5145
5526
|
</head>
|
|
5146
5527
|
<body>
|
|
5147
|
-
<
|
|
5148
|
-
<div class="
|
|
5149
|
-
<
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
<
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
<span class="pill rev" id="pillRev">\u9700\u4FEE\u8BA2: 0</span>
|
|
5166
|
-
<span class="pill ok" id="pillApproved">\u5DF2\u653E\u884C: 0</span>
|
|
5167
|
-
<span class="pill err" id="pillQa">QA \u95EE\u9898: -</span>
|
|
5168
|
-
<span class="pill info" id="pillMqm">MQM: -</span>
|
|
5169
|
-
</div>
|
|
5170
|
-
</div>
|
|
5528
|
+
<header class="cat-ribbon">
|
|
5529
|
+
<div class="ribbon-left">
|
|
5530
|
+
<span class="brand-chip"><span class="brand-badge">CAT</span><span id="docTitle" class="doc-title">LangLink memoQ \u5DE5\u4F5C\u53F0</span></span>
|
|
5531
|
+
<select id="docSelector" class="doc-select" aria-label="\u6587\u6863\u5207\u6362"></select>
|
|
5532
|
+
<span id="langPair" class="pill">- \u2192 -</span>
|
|
5533
|
+
<span id="previewBadge" class="pill">Preview: \u68C0\u6D4B\u4E2D</span>
|
|
5534
|
+
<span id="docIdLine" class="mono" style="color:var(--faint);"></span>
|
|
5535
|
+
</div>
|
|
5536
|
+
<div class="ribbon-right">
|
|
5537
|
+
<button id="btnApproveAll" class="success" type="button">\u4E00\u952E\u653E\u884C\u5168\u90E8\u5B9A\u7A3F\u5230 memoQ</button>
|
|
5538
|
+
<button id="btnRevokeAll" type="button">\u64A4\u56DE\u5168\u90E8\u4E3A\u8349\u7A3F</button>
|
|
5539
|
+
<button id="btnRunQa" class="primary" type="button">\u8FD0\u884C QA \u68C0\u67E5</button>
|
|
5540
|
+
<button id="btnToggleQaCfg" type="button">QA \u53C2\u6570 \u25BE</button>
|
|
5541
|
+
<button id="btnToggleInspector" class="active-toggle" type="button">\u8BE6\u60C5\u9762\u677F</button>
|
|
5542
|
+
<label style="font-size:11px;display:inline-flex;align-items:center;gap:4px;cursor:pointer;">
|
|
5543
|
+
<input id="chkAutoPoll" type="checkbox" checked /> \u81EA\u52A8\u540C\u6B65 (3s)
|
|
5544
|
+
</label>
|
|
5545
|
+
<button id="btnRefresh" type="button">\u5237\u65B0</button>
|
|
5171
5546
|
</div>
|
|
5547
|
+
</header>
|
|
5172
5548
|
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
<button id="btnRunQa" class="primary" type="button">\u8FD0\u884C QA \u68C0\u67E5</button>
|
|
5179
|
-
<button id="btnToggleQaCfg" type="button">QA \u89C4\u5219\u4E0E\u53C2\u6570 \u25BE</button>
|
|
5180
|
-
</div>
|
|
5181
|
-
<div class="btn-group">
|
|
5182
|
-
<label style="font-size:12px;display:inline-flex;align-items:center;gap:4px;cursor:pointer;">
|
|
5183
|
-
<input id="chkAutoPoll" type="checkbox" checked /> \u81EA\u52A8\u540C\u6B65 Agent \u66F4\u65B0 (3s)
|
|
5184
|
-
</label>
|
|
5185
|
-
<button id="btnRefresh" type="button">\u7ACB\u5373\u5237\u65B0</button>
|
|
5186
|
-
</div>
|
|
5549
|
+
<nav class="cat-subbar">
|
|
5550
|
+
<div class="ribbon-left">
|
|
5551
|
+
<div class="tabs">
|
|
5552
|
+
<button id="tabBtnReview" class="tab-btn active" type="button">\u53CC\u8BED\u7F51\u683C</button>
|
|
5553
|
+
<button id="tabBtnQa" class="tab-btn" type="button">QA \u68C0\u67E5\u6E05\u5355</button>
|
|
5187
5554
|
</div>
|
|
5188
|
-
|
|
5189
|
-
<div
|
|
5190
|
-
<
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
<div class="btn-group">
|
|
5198
|
-
<button id="btnRulesDefault" class="sm" type="button">\u9ED8\u8BA4\u89C4\u5219</button>
|
|
5199
|
-
<button id="btnRulesAll" class="sm" type="button">\u5168\u90E8\u89C4\u5219</button>
|
|
5200
|
-
<button id="btnRulesCritical" class="sm" type="button">\u4EC5\u4E25\u91CD\u9519\u8BEF</button>
|
|
5201
|
-
</div>
|
|
5202
|
-
</div>
|
|
5203
|
-
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:10px;margin-top:10px;">
|
|
5204
|
-
<div>
|
|
5205
|
-
<div class="box-label">\u672F\u8BED\u8868\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009 .csv/.tsv/.tbx\uFF09</div>
|
|
5206
|
-
<input id="inpGlossaryPath" type="text" style="width:100%;" placeholder="\u4F8B\u5982 D:\\project\\terms.csv" />
|
|
5207
|
-
</div>
|
|
5208
|
-
<div>
|
|
5209
|
-
<div class="box-label">\u9879\u76EE\u76EE\u5F55\uFF08\u53EF\u9009\uFF0C\u81EA\u52A8\u8BFB\u53D6 .langlink/manifest.json\uFF09</div>
|
|
5210
|
-
<input id="inpProjectDir" type="text" style="width:100%;" placeholder="\u7559\u7A7A\u5219\u6CBF\u7528\u5DF2\u914D\u7F6E\u9879\u76EE\u76EE\u5F55" />
|
|
5211
|
-
</div>
|
|
5212
|
-
<div>
|
|
5213
|
-
<div class="box-label">\u539F\u6587\u514D\u67E5\u767D\u540D\u5355\uFF08UNTRANSLATED_COPY\uFF0C\u9017\u53F7\u5206\u9694\uFF09</div>
|
|
5214
|
-
<input id="inpWhitelist" type="text" style="width:100%;" placeholder="\u4F8B\u5982 Gold Coin, Discord, X" />
|
|
5215
|
-
</div>
|
|
5216
|
-
</div>
|
|
5217
|
-
<div id="qaRulesContainer" style="margin-top:10px;"></div>
|
|
5555
|
+
<span class="v-sep"></span>
|
|
5556
|
+
<div class="filter-pills" id="filterPills">
|
|
5557
|
+
<button class="filter-pill active" data-filter="all" type="button">\u5168\u90E8</button>
|
|
5558
|
+
<button class="filter-pill" data-filter="draft" type="button">\u5F85\u5BA1\u8349\u7A3F</button>
|
|
5559
|
+
<button class="filter-pill" data-filter="needs_revision" type="button">\u9700\u4FEE\u8BA2</button>
|
|
5560
|
+
<button class="filter-pill" data-filter="approved" type="button">\u5DF2\u653E\u884C</button>
|
|
5561
|
+
<button class="filter-pill" data-filter="qa_issue" type="button">\u6709 QA \u95EE\u9898</button>
|
|
5562
|
+
<button class="filter-pill" data-filter="diff" type="button">\u4E0E memoQ \u4E0D\u540C</button>
|
|
5563
|
+
<button class="filter-pill" data-filter="comment" type="button">\u6709\u6279\u6CE8</button>
|
|
5218
5564
|
</div>
|
|
5219
5565
|
</div>
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
<span>\u5F53\u524D\u6709 <strong id="revCount">0</strong> \u6761\u53E5\u6BB5\u6807\u8BB0\u4E3A\u300C\u9700 Agent \u4FEE\u6539\u300D\u3002\u4F60\u53EF\u4EE5\u76F4\u63A5\u590D\u5236\u8FD9\u6761\u63D0\u793A\u8BCD\u56DE\u53D1\u7ED9\u5BF9\u8BDD\u91CC\u7684 Agent\uFF1A</span>
|
|
5224
|
-
<button id="btnCopyPrompt" class="sm primary" type="button">\u590D\u5236\u7ED9 Agent \u7684\u4FEE\u8BA2\u6307\u4EE4</button>
|
|
5566
|
+
<div class="search-wrap">
|
|
5567
|
+
<span class="kbd-hint">Ctrl+Enter \u653E\u884C\u5E76\u4E0B\u4E00\u53E5 \xB7 Ctrl+S \u4FDD\u5B58 \xB7 Alt+\u2191\u2193 \u5207\u6362</span>
|
|
5568
|
+
<input id="searchBox" type="text" style="width:220px;" placeholder="\u641C\u7D22\u539F\u6587 / \u8BD1\u6587 / \u6279\u6CE8..." />
|
|
5225
5569
|
</div>
|
|
5570
|
+
</nav>
|
|
5226
5571
|
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
<
|
|
5572
|
+
<section id="qaConfigPanel" class="qa-panel hidden">
|
|
5573
|
+
<div style="display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between;">
|
|
5574
|
+
<div style="display:flex;flex-wrap:wrap;gap:10px;align-items:center;font-size:12px;">
|
|
5575
|
+
<strong>\u68C0\u67E5\u5BF9\u8C61\uFF1A</strong>
|
|
5576
|
+
<label><input type="radio" name="qaScope" value="merged" checked /> \u5408\u5E76\u89C6\u56FE\uFF08\u6682\u5B58\u4F18\u5148\uFF0C\u7A7A\u7F3A\u8865 memoQ\uFF09</label>
|
|
5577
|
+
<label><input type="radio" name="qaScope" value="memoq" /> \u4EC5 memoQ \u73B0\u6709\u8BD1\u6587</label>
|
|
5578
|
+
<label><input type="radio" name="qaScope" value="staged" /> \u4EC5 Agent \u6682\u5B58\u8BD1\u6587</label>
|
|
5579
|
+
</div>
|
|
5580
|
+
<div style="display:flex;gap:6px;">
|
|
5581
|
+
<button id="btnRulesDefault" class="sm" type="button">\u9ED8\u8BA4\u89C4\u5219</button>
|
|
5582
|
+
<button id="btnRulesAll" class="sm" type="button">\u5168\u90E8\u89C4\u5219</button>
|
|
5583
|
+
<button id="btnRulesCritical" class="sm" type="button">\u4EC5\u4E25\u91CD\u9519\u8BEF</button>
|
|
5584
|
+
</div>
|
|
5585
|
+
</div>
|
|
5586
|
+
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:8px;margin-top:8px;">
|
|
5587
|
+
<div>
|
|
5588
|
+
<div class="box-label">\u672F\u8BED\u8868\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009 .csv/.tsv/.tbx\uFF09</div>
|
|
5589
|
+
<input id="inpGlossaryPath" type="text" style="width:100%;" placeholder="\u4F8B\u5982 D:\\project\\terms.csv" />
|
|
5231
5590
|
</div>
|
|
5591
|
+
<div>
|
|
5592
|
+
<div class="box-label">\u9879\u76EE\u76EE\u5F55\uFF08\u53EF\u9009\uFF0C\u81EA\u52A8\u8BFB\u53D6 .langlink/manifest.json\uFF09</div>
|
|
5593
|
+
<input id="inpProjectDir" type="text" style="width:100%;" placeholder="\u7559\u7A7A\u5219\u6CBF\u7528\u5DF2\u914D\u7F6E\u9879\u76EE\u76EE\u5F55" />
|
|
5594
|
+
</div>
|
|
5595
|
+
<div>
|
|
5596
|
+
<div class="box-label">\u539F\u6587\u514D\u67E5\u767D\u540D\u5355\uFF08UNTRANSLATED_COPY\uFF0C\u9017\u53F7\u5206\u9694\uFF09</div>
|
|
5597
|
+
<input id="inpWhitelist" type="text" style="width:100%;" placeholder="\u4F8B\u5982 Gold Coin, Discord, X" />
|
|
5598
|
+
</div>
|
|
5599
|
+
</div>
|
|
5600
|
+
<div id="qaRulesContainer" style="margin-top:8px;"></div>
|
|
5601
|
+
</section>
|
|
5602
|
+
|
|
5603
|
+
<div id="statusBanner" class="banner hidden"></div>
|
|
5604
|
+
<div id="revBanner" class="banner rev hidden">
|
|
5605
|
+
<span>\u5F53\u524D\u6709 <strong id="revCount">0</strong> \u6761\u53E5\u6BB5\u6807\u8BB0\u4E3A\u300C\u9700 Agent \u4FEE\u6539\u300D\u3002\u53EF\u76F4\u63A5\u590D\u5236\u6307\u4EE4\u53D1\u9001\u7ED9\u5BF9\u8BDD\u91CC\u7684 Agent\uFF1A</span>
|
|
5606
|
+
<button id="btnCopyPrompt" class="sm primary" type="button">\u590D\u5236\u7ED9 Agent \u7684\u4FEE\u8BA2\u6307\u4EE4</button>
|
|
5607
|
+
</div>
|
|
5232
5608
|
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
<button class="filter-pill" data-filter="diff" type="button">\u4E0E memoQ \u4E0D\u540C</button>
|
|
5242
|
-
<button class="filter-pill" data-filter="comment" type="button">\u6709\u6279\u6CE8</button>
|
|
5243
|
-
</div>
|
|
5244
|
-
<input id="searchBox" type="text" style="min-width:260px;" placeholder="\u641C\u7D22\u539F\u6587 / \u8BD1\u6587 / \u6279\u6CE8..." />
|
|
5609
|
+
<main id="catWorkspace" class="cat-workspace">
|
|
5610
|
+
<section class="cat-main">
|
|
5611
|
+
<div id="panelReview" class="cat-grid-scroll">
|
|
5612
|
+
<div class="cat-grid-head">
|
|
5613
|
+
<div>#</div>
|
|
5614
|
+
<div>\u539F\u6587 (Source)</div>
|
|
5615
|
+
<div>\u8BD1\u6587 (Target)</div>
|
|
5616
|
+
<div>\u72B6\u6001 / \u64CD\u4F5C</div>
|
|
5245
5617
|
</div>
|
|
5246
|
-
<div id="segmentList"
|
|
5618
|
+
<div id="segmentList"></div>
|
|
5247
5619
|
</div>
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
<div id="qaSummaryArea" style="margin-bottom:12px;"></div>
|
|
5620
|
+
<div id="panelQa" class="cat-grid-scroll hidden" style="padding:12px;">
|
|
5621
|
+
<div id="qaSummaryArea" style="margin-bottom:10px;"></div>
|
|
5251
5622
|
<div id="qaIssuesArea"></div>
|
|
5252
5623
|
</div>
|
|
5624
|
+
</section>
|
|
5625
|
+
|
|
5626
|
+
<aside id="inspectorPane" class="cat-inspector" aria-label="\u53E5\u6BB5\u8BE6\u60C5\u9762\u677F">
|
|
5627
|
+
<div id="inspectorContent"></div>
|
|
5628
|
+
</aside>
|
|
5629
|
+
</main>
|
|
5630
|
+
|
|
5631
|
+
<footer class="cat-statusbar">
|
|
5632
|
+
<div class="status-group">
|
|
5633
|
+
<span id="pillTotal">\u603B\u53E5\u6BB5: 0</span>
|
|
5634
|
+
<span>\u653E\u884C\u8FDB\u5EA6: <span class="progress-track"><span id="progressFill" class="progress-fill"></span></span> <strong id="progressPct">0%</strong></span>
|
|
5635
|
+
<span class="pill warn" id="pillDraft">\u8349\u7A3F\u5F85\u5BA1: 0</span>
|
|
5636
|
+
<span class="pill rev" id="pillRev">\u9700\u4FEE\u8BA2: 0</span>
|
|
5637
|
+
<span class="pill ok" id="pillApproved">\u5DF2\u653E\u884C: 0</span>
|
|
5638
|
+
<span class="pill err" id="pillQa">QA \u95EE\u9898: -</span>
|
|
5639
|
+
<span class="pill info" id="pillMqm">MQM: -</span>
|
|
5253
5640
|
</div>
|
|
5254
|
-
|
|
5641
|
+
<div class="status-group">
|
|
5642
|
+
<span id="bridgeStatusPill" class="pill ok">\u25CF \u6865\u63A5\u5DF2\u8FDE\u63A5</span>
|
|
5643
|
+
</div>
|
|
5644
|
+
</footer>
|
|
5255
5645
|
|
|
5256
5646
|
<script nonce="${options.nonce}">
|
|
5257
5647
|
const BOOT = ${bootJson};
|
|
5648
|
+
if (window.location.search) {
|
|
5649
|
+
try {
|
|
5650
|
+
history.replaceState(null, "", window.location.pathname);
|
|
5651
|
+
} catch {}
|
|
5652
|
+
}
|
|
5653
|
+
|
|
5258
5654
|
const state = {
|
|
5259
5655
|
data: null,
|
|
5260
5656
|
qa: null,
|
|
@@ -5266,7 +5662,10 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5266
5662
|
selectedRules: null,
|
|
5267
5663
|
dirtyTexts: new Map(),
|
|
5268
5664
|
dirtyComments: new Map(),
|
|
5269
|
-
|
|
5665
|
+
activeRowKey: "",
|
|
5666
|
+
lastFilteredKeys: [],
|
|
5667
|
+
inspectorOpen: true,
|
|
5668
|
+
bridgeConnected: true
|
|
5270
5669
|
};
|
|
5271
5670
|
|
|
5272
5671
|
const headers = () => ({
|
|
@@ -5282,6 +5681,34 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5282
5681
|
.replace(/"/g, """);
|
|
5283
5682
|
}
|
|
5284
5683
|
|
|
5684
|
+
const TAG_TOKEN_RE = /<span\\b[^>]*\\bdata-mqitag=(?:"[^"]*"|'[^']*')[^>]*>[\\s\\S]*?<\\/span>|\\{\\{[^{}\\r\\n]+\\}\\}|\\$\\{[^{}\\r\\n]+\\}|\\{[^{}\\r\\n]+\\}|<\\/>|<\\/?[A-Za-z0-9_#][^\\r\\n<>]*>|%(?:\\d+\\$)?[-+#0]*(?:\\d+)?(?:\\.\\d+)?[hlL]?[sdifFeEgGxXoucpaA%](?![A-Za-z])|\\r?\\n|\\\\[nrt]/gu;
|
|
5685
|
+
|
|
5686
|
+
function formatSourceHtml(rawText) {
|
|
5687
|
+
const text = String(rawText ?? "");
|
|
5688
|
+
if (!text) return "";
|
|
5689
|
+
let out = "";
|
|
5690
|
+
let lastIndex = 0;
|
|
5691
|
+
TAG_TOKEN_RE.lastIndex = 0;
|
|
5692
|
+
let match;
|
|
5693
|
+
while ((match = TAG_TOKEN_RE.exec(text)) !== null) {
|
|
5694
|
+
const idx = match.index;
|
|
5695
|
+
if (idx > lastIndex) {
|
|
5696
|
+
out += esc(text.slice(lastIndex, idx));
|
|
5697
|
+
}
|
|
5698
|
+
const tok = match[0];
|
|
5699
|
+
if (tok === "\\n" || tok === "\\r\\n") {
|
|
5700
|
+
out += '<span class="cat-tag" title="\u6362\u884C">\u21B5</span>\\n';
|
|
5701
|
+
} else {
|
|
5702
|
+
out += '<span class="cat-tag">' + esc(tok) + "</span>";
|
|
5703
|
+
}
|
|
5704
|
+
lastIndex = idx + tok.length;
|
|
5705
|
+
}
|
|
5706
|
+
if (lastIndex < text.length) {
|
|
5707
|
+
out += esc(text.slice(lastIndex));
|
|
5708
|
+
}
|
|
5709
|
+
return out;
|
|
5710
|
+
}
|
|
5711
|
+
|
|
5285
5712
|
function showBanner(type, text) {
|
|
5286
5713
|
const el = document.getElementById("statusBanner");
|
|
5287
5714
|
el.className = "banner " + type;
|
|
@@ -5293,20 +5720,55 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5293
5720
|
document.getElementById("statusBanner").classList.add("hidden");
|
|
5294
5721
|
}
|
|
5295
5722
|
|
|
5296
|
-
|
|
5297
|
-
const
|
|
5298
|
-
|
|
5299
|
-
if (
|
|
5300
|
-
|
|
5723
|
+
function renderBridgePill() {
|
|
5724
|
+
const el = document.getElementById("bridgeStatusPill");
|
|
5725
|
+
if (!el) return;
|
|
5726
|
+
if (state.bridgeConnected) {
|
|
5727
|
+
el.className = "pill ok";
|
|
5728
|
+
el.textContent = "\u25CF \u6865\u63A5\u5DF2\u8FDE\u63A5";
|
|
5729
|
+
} else {
|
|
5730
|
+
el.className = "pill warn";
|
|
5731
|
+
el.textContent = "\u25CB \u6865\u63A5\u91CD\u8FDE\u4E2D\u2026";
|
|
5732
|
+
}
|
|
5301
5733
|
}
|
|
5302
5734
|
|
|
5303
|
-
async function
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5735
|
+
async function apiRequest(method, path, body) {
|
|
5736
|
+
let res;
|
|
5737
|
+
try {
|
|
5738
|
+
res = await fetch(path, {
|
|
5739
|
+
method,
|
|
5740
|
+
headers: method === "GET" ? { "X-Review-Token": BOOT.reviewToken } : headers(),
|
|
5741
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
5742
|
+
});
|
|
5743
|
+
} catch (networkErr) {
|
|
5744
|
+
state.bridgeConnected = false;
|
|
5745
|
+
renderBridgePill();
|
|
5746
|
+
throw networkErr;
|
|
5747
|
+
}
|
|
5748
|
+
|
|
5749
|
+
if (res.status === 401) {
|
|
5750
|
+
throw new Error("\u5BA1\u6821\u6388\u6743\u5DF2\u5931\u6548\uFF0C\u8BF7\u4FDD\u7559\u5F53\u524D\u7F16\u8F91\u5E76\u4ECE Agent \u5BF9\u8BDD\u91CD\u65B0\u6253\u5F00 memoq_open_review \u94FE\u63A5\u3002");
|
|
5751
|
+
}
|
|
5752
|
+
|
|
5753
|
+
const data = await res.json().catch(() => ({}));
|
|
5754
|
+
if (!res.ok) {
|
|
5755
|
+
throw new Error(data.error || ("HTTP " + res.status));
|
|
5756
|
+
}
|
|
5757
|
+
if (!state.bridgeConnected) {
|
|
5758
|
+
state.bridgeConnected = true;
|
|
5759
|
+
renderBridgePill();
|
|
5760
|
+
}
|
|
5307
5761
|
return data;
|
|
5308
5762
|
}
|
|
5309
5763
|
|
|
5764
|
+
function apiGet(path) {
|
|
5765
|
+
return apiRequest("GET", path);
|
|
5766
|
+
}
|
|
5767
|
+
|
|
5768
|
+
function apiPost(path, body) {
|
|
5769
|
+
return apiRequest("POST", path, body);
|
|
5770
|
+
}
|
|
5771
|
+
|
|
5310
5772
|
function mergeRows() {
|
|
5311
5773
|
const previewSegs = (state.data && state.data.previewSegments) || [];
|
|
5312
5774
|
const stagedItems = (state.data && state.data.staged && state.data.staged.items) || [];
|
|
@@ -5402,11 +5864,18 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5402
5864
|
return map;
|
|
5403
5865
|
}
|
|
5404
5866
|
|
|
5867
|
+
function rowStatusClass(staged) {
|
|
5868
|
+
if (!staged) return "st-memoq";
|
|
5869
|
+
if (staged.status === "approved") return "st-approved";
|
|
5870
|
+
if (staged.status === "needs_revision") return "st-needs_revision";
|
|
5871
|
+
return "st-draft";
|
|
5872
|
+
}
|
|
5873
|
+
|
|
5405
5874
|
function statusBadgeHtml(staged) {
|
|
5406
|
-
if (!staged) return '<span class="pill">\u4EC5 memoQ
|
|
5407
|
-
if (staged.status === "approved") return '<span class="pill ok">\u5DF2\u653E\u884C v' + staged.revision + "</span>";
|
|
5875
|
+
if (!staged) return '<span class="pill">\u4EC5 memoQ</span>';
|
|
5876
|
+
if (staged.status === "approved") return '<span class="pill ok">\u2713 \u5DF2\u653E\u884C v' + staged.revision + "</span>";
|
|
5408
5877
|
if (staged.status === "needs_revision") return '<span class="pill rev">\u9700\u4FEE\u8BA2 v' + staged.revision + "</span>";
|
|
5409
|
-
return '<span class="pill warn">\u8349\u7A3F
|
|
5878
|
+
return '<span class="pill warn">\u8349\u7A3F v' + staged.revision + "</span>";
|
|
5410
5879
|
}
|
|
5411
5880
|
|
|
5412
5881
|
function renderRulesCatalog() {
|
|
@@ -5428,7 +5897,7 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5428
5897
|
for (const g of groups) {
|
|
5429
5898
|
const items = catalog.filter((r) => r.category === g.key);
|
|
5430
5899
|
if (!items.length) continue;
|
|
5431
|
-
html += '<div style="margin-top:
|
|
5900
|
+
html += '<div style="margin-top:6px;"><strong style="font-size:11px;">' + esc(g.title) + '</strong><div class="rule-grid">';
|
|
5432
5901
|
for (const r of items) {
|
|
5433
5902
|
const checked = state.selectedRules.has(r.ruleId) ? "checked" : "";
|
|
5434
5903
|
html += '<label class="rule-item" title="' + esc(r.description) + '">' +
|
|
@@ -5449,19 +5918,19 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5449
5918
|
const total = Math.max(previewSegCount, (d.staged && d.staged.total) || 0);
|
|
5450
5919
|
|
|
5451
5920
|
document.getElementById("docTitle").textContent =
|
|
5452
|
-
(doc.documentName || BOOT.initialDocumentName || "memoQ \u5F53\u524D\u6587\u6863")
|
|
5921
|
+
(doc.documentName || BOOT.initialDocumentName || "memoQ \u5F53\u524D\u6587\u6863");
|
|
5453
5922
|
document.getElementById("langPair").textContent =
|
|
5454
|
-
|
|
5923
|
+
(doc.sourceLanguage || "-") + " \u2192 " + (doc.targetLanguage || "-");
|
|
5455
5924
|
document.getElementById("docIdLine").textContent = doc.documentId && doc.documentId !== "__all__"
|
|
5456
|
-
?
|
|
5457
|
-
: (doc.documentId === "__all__" ? "\u8DE8\u6587\u6863
|
|
5925
|
+
? doc.documentId.slice(0, 8)
|
|
5926
|
+
: (doc.documentId === "__all__" ? "\u8DE8\u6587\u6863" : "");
|
|
5458
5927
|
|
|
5459
5928
|
const sel = document.getElementById("docSelector");
|
|
5460
5929
|
const docsList = d.documents || [];
|
|
5461
5930
|
const currentVal = state.selectedDocumentId || d.selectedDocumentId || doc.documentId || "";
|
|
5462
|
-
let optHtml = '<option value="">\u5F53\u524D\u6D3B\u8DC3\u6587\u6863\uFF08\u8DDF\u968F memoQ
|
|
5931
|
+
let optHtml = '<option value="">\u5F53\u524D\u6D3B\u8DC3\u6587\u6863\uFF08\u8DDF\u968F memoQ\uFF09</option>';
|
|
5463
5932
|
if (docsList.length > 0) {
|
|
5464
|
-
optHtml += '<option value="__all__"' + (currentVal === "__all__" ? " selected" : "") + '>\u5168\u90E8\u5DF2\u6253\u5F00\u6587\u6863
|
|
5933
|
+
optHtml += '<option value="__all__"' + (currentVal === "__all__" ? " selected" : "") + '>\u5168\u90E8\u5DF2\u6253\u5F00\u6587\u6863 (\u5171 ' + docsList.length + ' \u4EFD)</option>';
|
|
5465
5934
|
}
|
|
5466
5935
|
for (const item of docsList) {
|
|
5467
5936
|
const activeTag = item.isActive ? "[\u6D3B\u8DC3] " : "";
|
|
@@ -5481,6 +5950,9 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5481
5950
|
document.getElementById("pillDraft").textContent = "\u8349\u7A3F\u5F85\u5BA1: " + counts.draft;
|
|
5482
5951
|
document.getElementById("pillRev").textContent = "\u9700\u4FEE\u8BA2: " + counts.needsRevision;
|
|
5483
5952
|
document.getElementById("pillApproved").textContent = "\u5DF2\u653E\u884C: " + counts.approved;
|
|
5953
|
+
const pct = total > 0 ? Math.min(100, Math.round((counts.approved / total) * 100)) : 0;
|
|
5954
|
+
document.getElementById("progressFill").style.width = pct + "%";
|
|
5955
|
+
document.getElementById("progressPct").textContent = pct + "%";
|
|
5484
5956
|
|
|
5485
5957
|
const revBanner = document.getElementById("revBanner");
|
|
5486
5958
|
document.getElementById("revCount").textContent = String(counts.needsRevision);
|
|
@@ -5497,6 +5969,110 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5497
5969
|
|
|
5498
5970
|
const projInput = document.getElementById("inpProjectDir");
|
|
5499
5971
|
if (!projInput.value && d.projectDir) projInput.value = d.projectDir;
|
|
5972
|
+
renderBridgePill();
|
|
5973
|
+
}
|
|
5974
|
+
|
|
5975
|
+
function autoSizeTextarea(el) {
|
|
5976
|
+
if (!el) return;
|
|
5977
|
+
el.style.height = "auto";
|
|
5978
|
+
el.style.height = Math.max(44, Math.min(el.scrollHeight + 2, 240)) + "px";
|
|
5979
|
+
}
|
|
5980
|
+
|
|
5981
|
+
function renderInspector() {
|
|
5982
|
+
const box = document.getElementById("inspectorContent");
|
|
5983
|
+
if (!box) return;
|
|
5984
|
+
const rows = mergeRows();
|
|
5985
|
+
const row = rows.find((r) => r.rowKey === state.activeRowKey) || null;
|
|
5986
|
+
if (!row) {
|
|
5987
|
+
box.innerHTML = '<div class="empty-state">\u5728\u5DE6\u4FA7\u53CC\u8BED\u7F51\u683C\u4E2D\u70B9\u51FB\u4EFB\u610F\u53E5\u6BB5\uFF0C\u5373\u53EF\u5728\u6B64\u67E5\u770B\u4FEE\u8BA2\u5386\u53F2\u3001memoQ \u5B9E\u65F6\u8BD1\u6587\u3001QA \u95EE\u9898\u5E76\u5199\u6279\u6CE8\u3002</div>';
|
|
5988
|
+
return;
|
|
5989
|
+
}
|
|
5990
|
+
|
|
5991
|
+
const s = row.staged;
|
|
5992
|
+
const issueMap = issuesByRowMap();
|
|
5993
|
+
const rowIssues = issueMap.get(row.rowKey)
|
|
5994
|
+
|| issueMap.get(row.previewPartId)
|
|
5995
|
+
|| (s ? issueMap.get("staged:" + s.id) : null)
|
|
5996
|
+
|| [];
|
|
5997
|
+
const currentComment = state.dirtyComments.has(row.rowKey)
|
|
5998
|
+
? state.dirtyComments.get(row.rowKey)
|
|
5999
|
+
: (s ? s.reviewComment : "");
|
|
6000
|
+
|
|
6001
|
+
let historyHtml = '<div style="font-size:12px;color:var(--muted);">\u6682\u65E0\u591A\u8F6E\u5386\u53F2\uFF08\u9996\u6B21\u4FDD\u5B58\u6216\u4FEE\u8BA2\u540E\u81EA\u52A8\u8BB0\u5F55\uFF09\u3002</div>';
|
|
6002
|
+
if (s && Array.isArray(s.history) && s.history.length > 0) {
|
|
6003
|
+
historyHtml = '<div style="display:flex;gap:6px;align-items:center;">' +
|
|
6004
|
+
'<select class="rev-select" style="flex:1;min-width:0;" data-row="' + esc(row.rowKey) + '" data-id="' + esc(s.id) + '">' +
|
|
6005
|
+
s.history.slice().reverse().map((h) =>
|
|
6006
|
+
'<option value="' + h.revision + '">v' + h.revision + " (" + esc(h.editedBy) + "): " + esc(h.targetText.slice(0, 36)) + "</option>"
|
|
6007
|
+
).join("") +
|
|
6008
|
+
'</select><button class="sm btn-revert" data-id="' + esc(s.id) + '" data-row="' + esc(row.rowKey) + '" type="button">\u56DE\u9000</button></div>';
|
|
6009
|
+
}
|
|
6010
|
+
|
|
6011
|
+
let qaHtml = '<div style="font-size:12px;color:var(--muted);">' + (state.qa ? "\u672C\u53E5\u6BB5\u672A\u68C0\u51FA QA \u95EE\u9898\u3002" : "\u5C1A\u672A\u8FD0\u884C QA \u68C0\u67E5\u3002") + "</div>";
|
|
6012
|
+
if (rowIssues.length > 0) {
|
|
6013
|
+
qaHtml = rowIssues.map((iss) => {
|
|
6014
|
+
const cls = iss.severity === "critical" ? "err" : (iss.severity === "major" ? "warn" : "info");
|
|
6015
|
+
return '<div class="qa-issue-card">' +
|
|
6016
|
+
'<div><span class="pill ' + cls + '">' + esc(iss.severity) + '</span> <strong>' + esc(iss.ruleLabel) + "</strong></div>" +
|
|
6017
|
+
'<div>' + esc(iss.message) + "</div>" +
|
|
6018
|
+
(iss.evidence ? '<div class="mono" style="color:var(--muted);">' + esc(iss.evidence) + "</div>" : "") +
|
|
6019
|
+
(iss.suggestion ? '<div style="color:var(--ok);font-size:11px;">\u5EFA\u8BAE: ' + esc(iss.suggestion) + "</div>" : "") +
|
|
6020
|
+
"</div>";
|
|
6021
|
+
}).join("");
|
|
6022
|
+
}
|
|
6023
|
+
|
|
6024
|
+
const memoqText = row.memoqTargetText || "";
|
|
6025
|
+
const fillBtn = memoqText
|
|
6026
|
+
? '<button id="btnFillMemoqTarget" class="sm" data-row="' + esc(row.rowKey) + '" type="button">\u586B\u5165\u7F16\u8F91\u6846</button>'
|
|
6027
|
+
: "";
|
|
6028
|
+
const focusBtn = row.previewPartId
|
|
6029
|
+
? '<button class="sm btn-focus" data-part="' + esc(row.previewPartId) + '" data-doc="' + esc(row.documentId) + '" data-src="' + esc(row.sourceText) + '" type="button">\u5B9A\u4F4D memoQ</button>'
|
|
6030
|
+
: "";
|
|
6031
|
+
|
|
6032
|
+
box.innerHTML =
|
|
6033
|
+
'<div class="insp-section">' +
|
|
6034
|
+
'<div class="insp-title"><span>\u53E5\u6BB5 #' + (row.index + 1) + '</span>' + statusBadgeHtml(s) + "</div>" +
|
|
6035
|
+
'<div style="font-size:11px;color:var(--muted);">' +
|
|
6036
|
+
(row.documentName ? esc(row.documentName) + " \xB7 " : "") +
|
|
6037
|
+
esc(row.sourceLanguage || "-") + " \u2192 " + esc(row.targetLanguage || "-") +
|
|
6038
|
+
(s && s.stagedBy ? (" \xB7 by " + esc(s.stagedBy)) : "") +
|
|
6039
|
+
"</div>" +
|
|
6040
|
+
(focusBtn ? '<div style="margin-top:2px;">' + focusBtn + "</div>" : "") +
|
|
6041
|
+
"</div>" +
|
|
6042
|
+
'<div class="insp-section">' +
|
|
6043
|
+
'<div class="insp-title"><span>memoQ \u5B9E\u65F6\u8BD1\u6587\u5BF9\u7167</span>' + fillBtn + "</div>" +
|
|
6044
|
+
'<div class="insp-ref-text">' + (memoqText ? esc(memoqText) : '<span style="color:var(--faint);">(memoQ \u4E2D\u5F53\u524D\u4E3A\u7A7A)</span>') + "</div>" +
|
|
6045
|
+
"</div>" +
|
|
6046
|
+
'<div class="insp-section">' +
|
|
6047
|
+
'<div class="insp-title"><span>\u7ED9 Agent \u7684\u4FEE\u6539\u610F\u89C1</span></div>' +
|
|
6048
|
+
'<textarea id="inspectorCommentInput" class="cmt-edit" data-row="' + esc(row.rowKey) + '" rows="2" placeholder="\u8F93\u5165\u6279\u6CE8\uFF08\u5982\uFF1A\u672F\u8BED\u6539\u7528\u201C\u73CD\u5947\u201D\uFF0C\u8BED\u6C14\u66F4\u53E3\u8BED\uFF09">' + esc(currentComment) + "</textarea>" +
|
|
6049
|
+
'<div><button class="sm warn btn-feedback" data-row="' + esc(row.rowKey) + '" data-id="' + esc(s ? s.id : "") + '" type="button">\u6807\u8BB0\u9700\u4FEE\u8BA2\u5E76\u4FDD\u5B58\u6279\u6CE8</button></div>' +
|
|
6050
|
+
"</div>" +
|
|
6051
|
+
'<div class="insp-section">' +
|
|
6052
|
+
'<div class="insp-title"><span>\u591A\u8F6E\u4FEE\u8BA2\u5386\u53F2</span></div>' +
|
|
6053
|
+
historyHtml +
|
|
6054
|
+
"</div>" +
|
|
6055
|
+
'<div class="insp-section">' +
|
|
6056
|
+
'<div class="insp-title"><span>\u53E5\u6BB5 QA \u8BCA\u65AD (' + rowIssues.length + ")</span></div>" +
|
|
6057
|
+
qaHtml +
|
|
6058
|
+
"</div>";
|
|
6059
|
+
}
|
|
6060
|
+
|
|
6061
|
+
function selectActiveRow(rowKey, focusEditor = false) {
|
|
6062
|
+
if (!rowKey) return;
|
|
6063
|
+
state.activeRowKey = rowKey;
|
|
6064
|
+
for (const el of document.querySelectorAll("[data-row-card]")) {
|
|
6065
|
+
el.classList.toggle("active-row", el.getAttribute("data-row-card") === rowKey);
|
|
6066
|
+
}
|
|
6067
|
+
renderInspector();
|
|
6068
|
+
if (focusEditor) {
|
|
6069
|
+
const card = document.querySelector('[data-row-card="' + CSS.escape(rowKey) + '"]');
|
|
6070
|
+
const ta = card && card.querySelector(".tgt-edit");
|
|
6071
|
+
if (ta) {
|
|
6072
|
+
ta.focus();
|
|
6073
|
+
ta.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
6074
|
+
}
|
|
6075
|
+
}
|
|
5500
6076
|
}
|
|
5501
6077
|
|
|
5502
6078
|
function renderReviewList() {
|
|
@@ -5507,7 +6083,7 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5507
6083
|
|
|
5508
6084
|
const filtered = rows.filter((row) => {
|
|
5509
6085
|
const s = row.staged;
|
|
5510
|
-
const rowIssues = issueMap.get(row.rowKey) || (s ? issueMap.get("staged:" + s.id) : null) || [];
|
|
6086
|
+
const rowIssues = issueMap.get(row.rowKey) || issueMap.get(row.previewPartId) || (s ? issueMap.get("staged:" + s.id) : null) || [];
|
|
5511
6087
|
if (state.filter === "draft" && (!s || s.status !== "draft")) return false;
|
|
5512
6088
|
if (state.filter === "needs_revision" && (!s || s.status !== "needs_revision")) return false;
|
|
5513
6089
|
if (state.filter === "approved" && (!s || s.status !== "approved")) return false;
|
|
@@ -5528,11 +6104,18 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5528
6104
|
return true;
|
|
5529
6105
|
});
|
|
5530
6106
|
|
|
6107
|
+
state.lastFilteredKeys = filtered.map((r) => r.rowKey);
|
|
5531
6108
|
if (filtered.length === 0) {
|
|
5532
|
-
|
|
6109
|
+
state.activeRowKey = "";
|
|
6110
|
+
container.innerHTML = '<div class="empty-state">\u5F53\u524D\u7B5B\u9009\u6761\u4EF6\u4E0B\u6CA1\u6709\u53E5\u6BB5\u3002</div>';
|
|
6111
|
+
renderInspector();
|
|
5533
6112
|
return;
|
|
5534
6113
|
}
|
|
5535
6114
|
|
|
6115
|
+
if (!state.activeRowKey || !filtered.some((r) => r.rowKey === state.activeRowKey)) {
|
|
6116
|
+
state.activeRowKey = filtered[0].rowKey;
|
|
6117
|
+
}
|
|
6118
|
+
|
|
5536
6119
|
const showDocBadge = state.selectedDocumentId === "__all__"
|
|
5537
6120
|
|| (state.data && state.data.selectedDocumentId === "__all__")
|
|
5538
6121
|
|| (state.data && Array.isArray(state.data.documents) && state.data.documents.length > 1);
|
|
@@ -5545,80 +6128,64 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5545
6128
|
|| issueMap.get(row.previewPartId)
|
|
5546
6129
|
|| (s ? issueMap.get("staged:" + s.id) : null)
|
|
5547
6130
|
|| [];
|
|
5548
|
-
const
|
|
6131
|
+
const isDirty = state.dirtyTexts.has(row.rowKey);
|
|
6132
|
+
const currentTarget = isDirty
|
|
5549
6133
|
? state.dirtyTexts.get(row.rowKey)
|
|
5550
6134
|
: (s ? s.targetText : row.memoqTargetText);
|
|
5551
|
-
const
|
|
5552
|
-
? state.dirtyComments.get(row.rowKey)
|
|
5553
|
-
: (s ? s.reviewComment : "");
|
|
5554
|
-
const focusClass = state.highlightedRowKey === row.rowKey ? " highlight-focus" : "";
|
|
6135
|
+
const activeClass = state.activeRowKey === row.rowKey ? " active-row" : "";
|
|
5555
6136
|
const docBadge = showDocBadge && row.documentName
|
|
5556
|
-
? '<span class="
|
|
6137
|
+
? '<span class="doc-chip" title="' + esc(row.documentName) + '">' + esc(row.documentName) + "</span>"
|
|
5557
6138
|
: "";
|
|
5558
6139
|
|
|
5559
6140
|
let issuesBadges = "";
|
|
5560
6141
|
if (rowIssues.length > 0) {
|
|
5561
|
-
issuesBadges = '<div class="badge-list">' + rowIssues.map((iss) => {
|
|
6142
|
+
issuesBadges = '<div class="badge-list">' + rowIssues.slice(0, 3).map((iss) => {
|
|
5562
6143
|
const cls = iss.severity === "critical" ? "err" : (iss.severity === "major" ? "warn" : "info");
|
|
5563
|
-
return '<span class="pill ' + cls + '" title="' + esc(iss.evidence) + '">' + esc(iss.ruleLabel) +
|
|
5564
|
-
}).join("") + "</div>";
|
|
5565
|
-
}
|
|
5566
|
-
|
|
5567
|
-
let historyHtml = "";
|
|
5568
|
-
if (s && Array.isArray(s.history) && s.history.length > 0) {
|
|
5569
|
-
historyHtml = '<select class="rev-select" data-row="' + esc(row.rowKey) + '" data-id="' + esc(s.id) + '">' +
|
|
5570
|
-
s.history.slice().reverse().map((h) =>
|
|
5571
|
-
'<option value="' + h.revision + '">v' + h.revision + " (" + esc(h.editedBy) + "): " + esc(h.targetText.slice(0, 32)) + "</option>"
|
|
5572
|
-
).join("") +
|
|
5573
|
-
'</select><button class="sm btn-revert" data-id="' + esc(s.id) + '" data-row="' + esc(row.rowKey) + '" type="button">\u56DE\u9000\u8BE5\u7248\u672C</button>';
|
|
6144
|
+
return '<span class="pill ' + cls + '" title="' + esc(iss.evidence) + '">' + esc(iss.ruleLabel) + "</span>";
|
|
6145
|
+
}).join("") + (rowIssues.length > 3 ? '<span class="pill info">+' + (rowIssues.length - 3) + "</span>" : "") + "</div>";
|
|
5574
6146
|
}
|
|
5575
6147
|
|
|
5576
6148
|
const memoqDiffHtml = s && row.memoqTargetText && row.memoqTargetText !== s.targetText
|
|
5577
|
-
? '<div class="memoq-ref"
|
|
5578
|
-
:
|
|
5579
|
-
|
|
5580
|
-
|
|
6149
|
+
? '<div class="memoq-ref-line">memoQ: ' + esc(row.memoqTargetText) + "</div>"
|
|
6150
|
+
: "";
|
|
6151
|
+
const cmtBadge = s && s.reviewComment
|
|
6152
|
+
? '<div class="cmt-chip">\u6279\u6CE8: ' + esc(s.reviewComment) + "</div>"
|
|
6153
|
+
: "";
|
|
5581
6154
|
|
|
5582
6155
|
const approveBtn = s
|
|
5583
6156
|
? (s.status === "approved"
|
|
5584
|
-
? '<button class="sm btn-toggle-approve" data-id="' + esc(s.id) + '" data-next="draft" type="button"
|
|
5585
|
-
: '<button class="sm success btn-toggle-approve" data-id="' + esc(s.id) + '" data-next="approved" type="button"
|
|
6157
|
+
? '<button class="sm btn-toggle-approve" data-id="' + esc(s.id) + '" data-next="draft" type="button" title="\u64A4\u56DE\u4E3A\u8349\u7A3F">\u64A4\u56DE</button>'
|
|
6158
|
+
: '<button class="sm success btn-toggle-approve" data-id="' + esc(s.id) + '" data-next="approved" type="button" title="\u653E\u884C\u5B9A\u7A3F\u5230 memoQ">\u2713</button>')
|
|
5586
6159
|
: "";
|
|
5587
|
-
|
|
5588
6160
|
const focusBtn = row.previewPartId
|
|
5589
|
-
? '<button class="sm btn-focus" data-part="' + esc(row.previewPartId) + '" data-doc="' + esc(row.documentId) + '" data-src="' + esc(row.sourceText) + '" data-tgt="' + esc(currentTarget) + '" type="button"
|
|
6161
|
+
? '<button class="sm btn-focus" data-part="' + esc(row.previewPartId) + '" data-doc="' + esc(row.documentId) + '" data-src="' + esc(row.sourceText) + '" data-tgt="' + esc(currentTarget) + '" type="button" title="\u5728 memoQ \u4E2D\u5B9A\u4F4D">\u2316</button>'
|
|
5590
6162
|
: "";
|
|
5591
6163
|
|
|
5592
|
-
html += '<div class="
|
|
5593
|
-
'<div class="
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
'<
|
|
6164
|
+
html += '<div class="cat-row ' + rowStatusClass(s) + activeClass + '" data-row-card="' + esc(row.rowKey) + '">' +
|
|
6165
|
+
'<div class="cat-rail"><strong>' + (row.index + 1) + "</strong>" + docBadge + (isDirty ? '<span class="dirty-tag">\u672A\u4FDD\u5B58</span>' : "") + "</div>" +
|
|
6166
|
+
'<div class="cat-source"><div class="src-text">' + formatSourceHtml(row.sourceText) + "</div>" + issuesBadges + "</div>" +
|
|
6167
|
+
'<div class="cat-target">' +
|
|
6168
|
+
'<textarea class="tgt-edit" data-row="' + esc(row.rowKey) + '" placeholder="\u8F93\u5165\u6216\u7F16\u8F91\u8BD1\u6587...">' + esc(currentTarget) + "</textarea>" +
|
|
6169
|
+
memoqDiffHtml + cmtBadge +
|
|
5597
6170
|
"</div>" +
|
|
5598
|
-
'<div class="
|
|
5599
|
-
|
|
5600
|
-
'<div class="
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
'<textarea class="tgt-edit" data-row="' + esc(row.rowKey) + '">' + esc(currentTarget) + "</textarea>" +
|
|
5604
|
-
'<div class="row-actions" style="margin-top:6px;">' +
|
|
5605
|
-
'<div class="btn-group">' +
|
|
5606
|
-
'<button class="sm primary btn-save-edit" data-row="' + esc(row.rowKey) + '" data-id="' + esc(s ? s.id : "") + '" type="button">' + (s ? "\u4FDD\u5B58\u65B0\u7248\u672C" : "\u4FDD\u5B58\u4E3A\u8349\u7A3F") + "</button>" +
|
|
5607
|
-
historyHtml +
|
|
5608
|
-
"</div>" +
|
|
5609
|
-
'<div class="feedback-row">' +
|
|
5610
|
-
'<input type="text" class="cmt-edit" data-row="' + esc(row.rowKey) + '" value="' + esc(currentComment) + '" placeholder="\u5199\u7ED9 Agent \u7684\u4FEE\u6539\u610F\u89C1\uFF08\u5982\uFF1A\u672F\u8BED\u518D\u53E3\u8BED\u4E9B\uFF09" />' +
|
|
5611
|
-
'<button class="sm warn btn-feedback" data-row="' + esc(row.rowKey) + '" data-id="' + esc(s ? s.id : "") + '" type="button">\u6807\u8BB0\u9700\u4FEE\u6539</button>' +
|
|
5612
|
-
"</div>" +
|
|
6171
|
+
'<div class="cat-status">' +
|
|
6172
|
+
statusBadgeHtml(s) +
|
|
6173
|
+
'<div class="row-mini-btns">' +
|
|
6174
|
+
'<button class="sm primary btn-save-edit" data-row="' + esc(row.rowKey) + '" data-id="' + esc(s ? s.id : "") + '" type="button">' + (s ? "\u4FDD\u5B58" : "\u6682\u5B58") + "</button>" +
|
|
6175
|
+
approveBtn + focusBtn +
|
|
5613
6176
|
"</div>" +
|
|
5614
6177
|
"</div>" +
|
|
5615
|
-
|
|
6178
|
+
"</div>";
|
|
5616
6179
|
}
|
|
5617
6180
|
if (filtered.length > maxRender) {
|
|
5618
6181
|
const remaining = filtered.length - maxRender;
|
|
5619
|
-
html += '<div class="banner warn"><span>\
|
|
6182
|
+
html += '<div class="banner warn"><span>\u5DF2\u5C55\u793A\u524D ' + maxRender + " \u6761\uFF08\u5171\u5339\u914D " + filtered.length + " \u6761\uFF0C\u8FD8\u6709 " + remaining + ' \u6761\u672A\u5C55\u5F00\uFF09\u3002</span><button id="btnLoadMoreRows" class="sm primary" type="button">\u518D\u52A0\u8F7D 300 \u6761</button></div>';
|
|
5620
6183
|
}
|
|
5621
6184
|
container.innerHTML = html;
|
|
6185
|
+
for (const ta of container.querySelectorAll(".tgt-edit")) {
|
|
6186
|
+
autoSizeTextarea(ta);
|
|
6187
|
+
}
|
|
6188
|
+
renderInspector();
|
|
5622
6189
|
}
|
|
5623
6190
|
|
|
5624
6191
|
function renderQaReport() {
|
|
@@ -5638,13 +6205,13 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5638
6205
|
? ("\u5DF2\u52A0\u8F7D\u672F\u8BED " + r.glossary.entriesCount + " \u6761\uFF08" + esc(r.glossary.sources.join(", ")) + "\uFF09")
|
|
5639
6206
|
: "\u672A\u52A0\u8F7D\u5916\u90E8\u672F\u8BED\u8868\uFF08\u672F\u8BED\u89C4\u5219\u5DF2\u8BDA\u5B9E\u6807\u6CE8 skipped\uFF09";
|
|
5640
6207
|
|
|
5641
|
-
const ruleSummaryHtml = '<details style="margin-top:
|
|
5642
|
-
'<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(
|
|
6208
|
+
const ruleSummaryHtml = '<details style="margin-top:6px;font-size:12px;"><summary style="cursor:pointer;font-weight:600;">\u89C4\u5219\u6267\u884C\u660E\u7EC6\uFF08\u5171 ' + r.rules.length + ' \u6761\uFF09</summary>' +
|
|
6209
|
+
'<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:4px 10px;margin-top:6px;font-size:11px;">' +
|
|
5643
6210
|
r.rules.map((rule) => '<div><strong>' + esc(rule.ruleId) + "</strong>: " + esc(rule.status) + " (" + rule.checkedSegments + ")" + (rule.reason ? " - " + esc(rule.reason) : "") + "</div>").join("") +
|
|
5644
6211
|
"</div></details>";
|
|
5645
6212
|
|
|
5646
6213
|
sumEl.innerHTML =
|
|
5647
|
-
'<div
|
|
6214
|
+
'<div style="display:flex;flex-wrap:wrap;gap:6px;align-items:center;margin-bottom:6px;">' +
|
|
5648
6215
|
'<span class="pill info">\u68C0\u67E5\u6A21\u5F0F: ' + esc(r.scope) + "</span>" +
|
|
5649
6216
|
'<span class="pill">\u603B\u53E5\u6BB5: ' + s.totalSegments + "</span>" +
|
|
5650
6217
|
'<span class="pill">\u5DF2\u8BD1/\u975E\u7A7A: ' + s.translatedSegments + " / \u7A7A\u8BD1: " + s.emptyTargetSegments + "</span>" +
|
|
@@ -5654,7 +6221,7 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5654
6221
|
'<span class="pill">MQM RQS: ' + s.mqm.rqs + " (APT=" + s.mqm.apt + ", EWC=" + s.mqm.ewc + ")</span>" +
|
|
5655
6222
|
covPill +
|
|
5656
6223
|
"</div>" +
|
|
5657
|
-
'<div
|
|
6224
|
+
'<div style="font-size:12px;color:var(--muted);">' + glossaryInfo +
|
|
5658
6225
|
(r.glossary.warnings.length ? (" | \u6CE8\u610F: " + esc(r.glossary.warnings.join("; "))) : "") +
|
|
5659
6226
|
"</div>" + ruleSummaryHtml;
|
|
5660
6227
|
|
|
@@ -5672,7 +6239,7 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5672
6239
|
const jumpKey = (iss.documentId && iss.previewPartId ? (iss.documentId + "::" + iss.previewPartId) : iss.previewPartId)
|
|
5673
6240
|
|| (iss.stagedId ? ("staged:" + iss.stagedId) : "");
|
|
5674
6241
|
const jumpBtn = jumpKey
|
|
5675
|
-
? '<button class="sm primary btn-jump-review" data-row="' + esc(jumpKey) + '" type="button">\u53BB\u5BA1\u6821
|
|
6242
|
+
? '<button class="sm primary btn-jump-review" data-row="' + esc(jumpKey) + '" type="button">\u53BB\u5BA1\u6821</button>'
|
|
5676
6243
|
: "";
|
|
5677
6244
|
const segCell = (r.allDocuments && iss.documentName)
|
|
5678
6245
|
? ('<div><span class="pill info">' + esc(iss.documentName) + "</span></div><div>#" + (iss.docSegmentNumber || iss.segmentNumber) + "</div>")
|
|
@@ -5682,12 +6249,12 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5682
6249
|
'<td><span class="pill ' + cls + '">' + esc(iss.severity) + "</span></td>" +
|
|
5683
6250
|
"<td><strong>" + esc(iss.ruleLabel) + '</strong><div class="mono">' + esc(iss.ruleId) + "</div></td>" +
|
|
5684
6251
|
"<td>" + segCell + "</td>" +
|
|
5685
|
-
"<td><div style='margin-bottom:
|
|
6252
|
+
"<td><div style='margin-bottom:3px;'><strong>\u6E90\uFF1A</strong>" + esc(iss.sourceText) + "</div>" +
|
|
5686
6253
|
"<div><strong>\u8BD1\uFF1A</strong>" + esc(iss.targetText || "(\u7A7A)") + "</div></td>" +
|
|
5687
|
-
"<td><div>" + esc(iss.message) + '</div><div class="mono">' + esc(iss.evidence) + "</div>" +
|
|
5688
|
-
(iss.suggestion ? ('<div style="color:var(--ok);font-size:
|
|
6254
|
+
"<td><div>" + esc(iss.message) + '</div><div class="mono" style="color:var(--muted);">' + esc(iss.evidence) + "</div>" +
|
|
6255
|
+
(iss.suggestion ? ('<div style="color:var(--ok);font-size:11px;">\u5EFA\u8BAE: ' + esc(iss.suggestion) + "</div>") : "") +
|
|
5689
6256
|
"</td>" +
|
|
5690
|
-
'<td><div
|
|
6257
|
+
'<td><div style="display:flex;gap:4px;flex-wrap:wrap;">' + focusBtn + jumpBtn + "</div></td>" +
|
|
5691
6258
|
"</tr>";
|
|
5692
6259
|
}
|
|
5693
6260
|
|
|
@@ -5712,6 +6279,24 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5712
6279
|
}
|
|
5713
6280
|
}
|
|
5714
6281
|
|
|
6282
|
+
async function saveRowDraft(rowKey, stagedId, targetText, nextStatus) {
|
|
6283
|
+
const row = mergeRows().find((r) => r.rowKey === rowKey);
|
|
6284
|
+
if (!row) return null;
|
|
6285
|
+
const res = await apiPost("/review/api/update", {
|
|
6286
|
+
...(stagedId ? { id: stagedId } : {}),
|
|
6287
|
+
targetText,
|
|
6288
|
+
...(nextStatus ? { status: nextStatus } : {}),
|
|
6289
|
+
editedBy: "translator",
|
|
6290
|
+
sourceText: row.sourceText,
|
|
6291
|
+
sourceLanguage: row.sourceLanguage || "eng",
|
|
6292
|
+
targetLanguage: row.targetLanguage || "zho-CN",
|
|
6293
|
+
documentId: row.documentId || "",
|
|
6294
|
+
previewPartId: row.previewPartId || ""
|
|
6295
|
+
});
|
|
6296
|
+
state.dirtyTexts.delete(rowKey);
|
|
6297
|
+
return res.entry || null;
|
|
6298
|
+
}
|
|
6299
|
+
|
|
5715
6300
|
async function runQa() {
|
|
5716
6301
|
const scopeEl = document.querySelector('input[name="qaScope"]:checked');
|
|
5717
6302
|
const scope = scopeEl ? scopeEl.value : "merged";
|
|
@@ -5764,10 +6349,6 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5764
6349
|
if (tab === "qa") renderQaReport();
|
|
5765
6350
|
}
|
|
5766
6351
|
|
|
5767
|
-
function findRowByKey(rowKey) {
|
|
5768
|
-
return mergeRows().find((r) => r.rowKey === rowKey);
|
|
5769
|
-
}
|
|
5770
|
-
|
|
5771
6352
|
document.getElementById("docSelector").addEventListener("change", (ev) => {
|
|
5772
6353
|
state.selectedDocumentId = ev.target.value || "";
|
|
5773
6354
|
state.renderLimit = 300;
|
|
@@ -5781,6 +6362,11 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5781
6362
|
document.getElementById("btnToggleQaCfg").addEventListener("click", () => {
|
|
5782
6363
|
document.getElementById("qaConfigPanel").classList.toggle("hidden");
|
|
5783
6364
|
});
|
|
6365
|
+
document.getElementById("btnToggleInspector").addEventListener("click", () => {
|
|
6366
|
+
state.inspectorOpen = !state.inspectorOpen;
|
|
6367
|
+
document.getElementById("catWorkspace").classList.toggle("inspector-collapsed", !state.inspectorOpen);
|
|
6368
|
+
document.getElementById("btnToggleInspector").classList.toggle("active-toggle", state.inspectorOpen);
|
|
6369
|
+
});
|
|
5784
6370
|
|
|
5785
6371
|
document.getElementById("btnRulesDefault").addEventListener("click", () => {
|
|
5786
6372
|
const cat = (state.data && state.data.qaCatalog) || [];
|
|
@@ -5811,7 +6397,7 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5811
6397
|
const docId = (state.data && state.data.document && state.data.document.documentId) || "";
|
|
5812
6398
|
const res = await apiPost("/review/api/approve", { ...(docId ? { documentId: docId } : {}), status: "approved" });
|
|
5813
6399
|
await refreshState(true);
|
|
5814
|
-
showBanner("ok", "\u5DF2\u653E\u884C " + res.approvedTotal + " \u6761\u6700\u7EC8\u5B9A\u7A3F\uFF01\u8BF7\u5207\u56DE memoQ \u8FD0\u884C Pre-translate \u5373\u53EF\u6BEB\u79D2\u5199\u5165\
|
|
6400
|
+
showBanner("ok", "\u5DF2\u653E\u884C " + res.approvedTotal + " \u6761\u6700\u7EC8\u5B9A\u7A3F\uFF01\u8BF7\u5207\u56DE memoQ \u8FD0\u884C Pre-translate \u5373\u53EF\u6BEB\u79D2\u5199\u5165\u3002");
|
|
5815
6401
|
} catch (err) {
|
|
5816
6402
|
showBanner("err", "\u653E\u884C\u5931\u8D25: " + (err.message || err));
|
|
5817
6403
|
}
|
|
@@ -5858,8 +6444,76 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5858
6444
|
if (!t || !t.getAttribute) return;
|
|
5859
6445
|
const rowKey = t.getAttribute("data-row");
|
|
5860
6446
|
if (!rowKey) return;
|
|
5861
|
-
if (t.classList.contains("tgt-edit"))
|
|
5862
|
-
|
|
6447
|
+
if (t.classList.contains("tgt-edit")) {
|
|
6448
|
+
state.dirtyTexts.set(rowKey, t.value);
|
|
6449
|
+
autoSizeTextarea(t);
|
|
6450
|
+
}
|
|
6451
|
+
if (t.classList.contains("cmt-edit")) {
|
|
6452
|
+
state.dirtyComments.set(rowKey, t.value);
|
|
6453
|
+
}
|
|
6454
|
+
});
|
|
6455
|
+
|
|
6456
|
+
document.addEventListener("focusin", (ev) => {
|
|
6457
|
+
const card = ev.target && ev.target.closest ? ev.target.closest("[data-row-card]") : null;
|
|
6458
|
+
if (card) {
|
|
6459
|
+
const rk = card.getAttribute("data-row-card");
|
|
6460
|
+
if (rk && rk !== state.activeRowKey) {
|
|
6461
|
+
selectActiveRow(rk, false);
|
|
6462
|
+
}
|
|
6463
|
+
}
|
|
6464
|
+
});
|
|
6465
|
+
|
|
6466
|
+
document.addEventListener("keydown", async (ev) => {
|
|
6467
|
+
const t = ev.target;
|
|
6468
|
+
if (!t || !t.classList || !t.classList.contains("tgt-edit")) return;
|
|
6469
|
+
const rowKey = t.getAttribute("data-row") || "";
|
|
6470
|
+
if (!rowKey) return;
|
|
6471
|
+
|
|
6472
|
+
if ((ev.ctrlKey || ev.metaKey) && ev.key === "Enter") {
|
|
6473
|
+
ev.preventDefault();
|
|
6474
|
+
const card = t.closest("[data-row-card]");
|
|
6475
|
+
const saveBtn = card && card.querySelector(".btn-save-edit");
|
|
6476
|
+
const stagedId = (saveBtn && saveBtn.getAttribute("data-id")) || "";
|
|
6477
|
+
const keys = state.lastFilteredKeys || [];
|
|
6478
|
+
const curIdx = keys.indexOf(rowKey);
|
|
6479
|
+
const nextKey = curIdx >= 0 && curIdx + 1 < keys.length ? keys[curIdx + 1] : rowKey;
|
|
6480
|
+
try {
|
|
6481
|
+
await saveRowDraft(rowKey, stagedId, t.value, "approved");
|
|
6482
|
+
state.activeRowKey = nextKey;
|
|
6483
|
+
await refreshState(true);
|
|
6484
|
+
selectActiveRow(nextKey, true);
|
|
6485
|
+
showBanner("ok", "\u5DF2\u653E\u884C\u5F53\u524D\u53E5\u6BB5\u5E76\u8DF3\u8F6C\u5230\u4E0B\u4E00\u53E5\u3002");
|
|
6486
|
+
} catch (err) {
|
|
6487
|
+
showBanner("err", "\u5FEB\u6377\u653E\u884C\u5931\u8D25: " + (err.message || err));
|
|
6488
|
+
}
|
|
6489
|
+
return;
|
|
6490
|
+
}
|
|
6491
|
+
|
|
6492
|
+
if ((ev.ctrlKey || ev.metaKey) && ev.key.toLowerCase() === "s") {
|
|
6493
|
+
ev.preventDefault();
|
|
6494
|
+
const card = t.closest("[data-row-card]");
|
|
6495
|
+
const saveBtn = card && card.querySelector(".btn-save-edit");
|
|
6496
|
+
const stagedId = (saveBtn && saveBtn.getAttribute("data-id")) || "";
|
|
6497
|
+
try {
|
|
6498
|
+
await saveRowDraft(rowKey, stagedId, t.value);
|
|
6499
|
+
await refreshState(true);
|
|
6500
|
+
selectActiveRow(rowKey, true);
|
|
6501
|
+
showBanner("ok", "\u5DF2\u4FDD\u5B58\u5F53\u524D\u4FEE\u8BA2\u7248\u672C\u3002");
|
|
6502
|
+
} catch (err) {
|
|
6503
|
+
showBanner("err", "\u4FDD\u5B58\u5931\u8D25: " + (err.message || err));
|
|
6504
|
+
}
|
|
6505
|
+
return;
|
|
6506
|
+
}
|
|
6507
|
+
|
|
6508
|
+
if (ev.altKey && (ev.key === "ArrowDown" || ev.key === "ArrowUp")) {
|
|
6509
|
+
ev.preventDefault();
|
|
6510
|
+
const keys = state.lastFilteredKeys || [];
|
|
6511
|
+
const curIdx = keys.indexOf(rowKey);
|
|
6512
|
+
if (curIdx < 0) return;
|
|
6513
|
+
const delta = ev.key === "ArrowDown" ? 1 : -1;
|
|
6514
|
+
const nextIdx = Math.max(0, Math.min(keys.length - 1, curIdx + delta));
|
|
6515
|
+
selectActiveRow(keys[nextIdx], true);
|
|
6516
|
+
}
|
|
5863
6517
|
});
|
|
5864
6518
|
|
|
5865
6519
|
document.addEventListener("click", async (ev) => {
|
|
@@ -5870,6 +6524,23 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5870
6524
|
return;
|
|
5871
6525
|
}
|
|
5872
6526
|
|
|
6527
|
+
const btnFillMemoq = ev.target.closest("#btnFillMemoqTarget");
|
|
6528
|
+
if (btnFillMemoq) {
|
|
6529
|
+
const rowKey = btnFillMemoq.getAttribute("data-row") || "";
|
|
6530
|
+
const row = mergeRows().find((r) => r.rowKey === rowKey);
|
|
6531
|
+
if (!row || !row.memoqTargetText) return;
|
|
6532
|
+
state.dirtyTexts.set(rowKey, row.memoqTargetText);
|
|
6533
|
+
const card = document.querySelector('[data-row-card="' + CSS.escape(rowKey) + '"]');
|
|
6534
|
+
const ta = card && card.querySelector(".tgt-edit");
|
|
6535
|
+
if (ta) {
|
|
6536
|
+
ta.value = row.memoqTargetText;
|
|
6537
|
+
autoSizeTextarea(ta);
|
|
6538
|
+
ta.focus();
|
|
6539
|
+
}
|
|
6540
|
+
showBanner("ok", "\u5DF2\u5C06 memoQ \u5B9E\u65F6\u8BD1\u6587\u586B\u5165\u7F16\u8F91\u6846\uFF08\u522B\u5FD8\u4E86\u6309 Ctrl+S \u4FDD\u5B58\uFF09\u3002");
|
|
6541
|
+
return;
|
|
6542
|
+
}
|
|
6543
|
+
|
|
5873
6544
|
const btnFocus = ev.target.closest(".btn-focus");
|
|
5874
6545
|
if (btnFocus) {
|
|
5875
6546
|
try {
|
|
@@ -5888,24 +6559,12 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5888
6559
|
|
|
5889
6560
|
const btnSave = ev.target.closest(".btn-save-edit");
|
|
5890
6561
|
if (btnSave) {
|
|
5891
|
-
const rowKey = btnSave.getAttribute("data-row");
|
|
6562
|
+
const rowKey = btnSave.getAttribute("data-row") || "";
|
|
5892
6563
|
const id = btnSave.getAttribute("data-id") || "";
|
|
5893
|
-
const row = findRowByKey(rowKey);
|
|
5894
|
-
if (!row) return;
|
|
5895
6564
|
const card = btnSave.closest("[data-row-card]");
|
|
5896
6565
|
const targetText = card.querySelector(".tgt-edit").value;
|
|
5897
6566
|
try {
|
|
5898
|
-
await
|
|
5899
|
-
...(id ? { id } : {}),
|
|
5900
|
-
targetText,
|
|
5901
|
-
editedBy: "translator",
|
|
5902
|
-
sourceText: row.sourceText,
|
|
5903
|
-
sourceLanguage: row.sourceLanguage || "eng",
|
|
5904
|
-
targetLanguage: row.targetLanguage || "zho-CN",
|
|
5905
|
-
documentId: row.documentId || "",
|
|
5906
|
-
previewPartId: row.previewPartId || ""
|
|
5907
|
-
});
|
|
5908
|
-
state.dirtyTexts.delete(rowKey);
|
|
6567
|
+
await saveRowDraft(rowKey, id, targetText);
|
|
5909
6568
|
await refreshState(true);
|
|
5910
6569
|
showBanner("ok", "\u5DF2\u4FDD\u5B58\u4FEE\u8BA2\u7248\u672C\u3002");
|
|
5911
6570
|
} catch (err) {
|
|
@@ -5917,9 +6576,9 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5917
6576
|
const btnRevert = ev.target.closest(".btn-revert");
|
|
5918
6577
|
if (btnRevert) {
|
|
5919
6578
|
const id = btnRevert.getAttribute("data-id");
|
|
5920
|
-
const rowKey = btnRevert.getAttribute("data-row");
|
|
5921
|
-
const
|
|
5922
|
-
const sel =
|
|
6579
|
+
const rowKey = btnRevert.getAttribute("data-row") || "";
|
|
6580
|
+
const insp = document.getElementById("inspectorPane");
|
|
6581
|
+
const sel = insp && insp.querySelector(".rev-select");
|
|
5923
6582
|
if (!id || !sel) return;
|
|
5924
6583
|
try {
|
|
5925
6584
|
await apiPost("/review/api/update", { id, revertToRevision: Number(sel.value), editedBy: "translator" });
|
|
@@ -5934,13 +6593,15 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5934
6593
|
|
|
5935
6594
|
const btnFeedback = ev.target.closest(".btn-feedback");
|
|
5936
6595
|
if (btnFeedback) {
|
|
5937
|
-
const rowKey = btnFeedback.getAttribute("data-row");
|
|
6596
|
+
const rowKey = btnFeedback.getAttribute("data-row") || "";
|
|
5938
6597
|
const id = btnFeedback.getAttribute("data-id") || "";
|
|
5939
|
-
const row =
|
|
6598
|
+
const row = mergeRows().find((r) => r.rowKey === rowKey);
|
|
5940
6599
|
if (!row) return;
|
|
5941
|
-
const
|
|
5942
|
-
const comment =
|
|
5943
|
-
const
|
|
6600
|
+
const cmtInput = document.getElementById("inspectorCommentInput");
|
|
6601
|
+
const comment = cmtInput ? cmtInput.value : "";
|
|
6602
|
+
const card = document.querySelector('[data-row-card="' + CSS.escape(rowKey) + '"]');
|
|
6603
|
+
const ta = card && card.querySelector(".tgt-edit");
|
|
6604
|
+
const currentTarget = ta ? ta.value : (row.staged ? row.staged.targetText : row.memoqTargetText);
|
|
5944
6605
|
try {
|
|
5945
6606
|
await apiPost("/review/api/feedback", {
|
|
5946
6607
|
...(id ? { id } : {}),
|
|
@@ -5978,15 +6639,22 @@ function renderReviewWorkbenchHtml(options) {
|
|
|
5978
6639
|
const btnJump = ev.target.closest(".btn-jump-review");
|
|
5979
6640
|
if (btnJump) {
|
|
5980
6641
|
const rowKey = btnJump.getAttribute("data-row") || "";
|
|
5981
|
-
state.highlightedRowKey = rowKey;
|
|
5982
6642
|
state.filter = "all";
|
|
5983
6643
|
for (const el of document.querySelectorAll("#filterPills [data-filter]")) {
|
|
5984
6644
|
el.classList.toggle("active", el.getAttribute("data-filter") === "all");
|
|
5985
6645
|
}
|
|
5986
6646
|
switchTab("review");
|
|
5987
6647
|
renderReviewList();
|
|
5988
|
-
|
|
5989
|
-
|
|
6648
|
+
selectActiveRow(rowKey, true);
|
|
6649
|
+
return;
|
|
6650
|
+
}
|
|
6651
|
+
|
|
6652
|
+
const clickedCard = ev.target.closest("[data-row-card]");
|
|
6653
|
+
if (clickedCard) {
|
|
6654
|
+
const rk = clickedCard.getAttribute("data-row-card");
|
|
6655
|
+
if (rk && rk !== state.activeRowKey) {
|
|
6656
|
+
selectActiveRow(rk, false);
|
|
6657
|
+
}
|
|
5990
6658
|
}
|
|
5991
6659
|
});
|
|
5992
6660
|
|
|
@@ -6056,14 +6724,54 @@ function safeBearerEquals(headerValue, expectedToken) {
|
|
|
6056
6724
|
if (!headerValue || !headerValue.startsWith("Bearer ")) return false;
|
|
6057
6725
|
return safeTokenEquals(headerValue.slice("Bearer ".length), expectedToken);
|
|
6058
6726
|
}
|
|
6059
|
-
|
|
6727
|
+
var REVIEW_COOKIE_NAME = "memoq_review_token";
|
|
6728
|
+
var REVIEW_COOKIE_MAX_AGE_SECONDS = 31536e3;
|
|
6729
|
+
function readCookieValue(cookieHeader, cookieName) {
|
|
6730
|
+
if (!cookieHeader) return void 0;
|
|
6731
|
+
for (const part of cookieHeader.split(";")) {
|
|
6732
|
+
const eqIndex = part.indexOf("=");
|
|
6733
|
+
if (eqIndex <= 0) continue;
|
|
6734
|
+
const name2 = part.slice(0, eqIndex).trim();
|
|
6735
|
+
if (name2 !== cookieName) continue;
|
|
6736
|
+
const value = part.slice(eqIndex + 1).trim();
|
|
6737
|
+
return value || void 0;
|
|
6738
|
+
}
|
|
6739
|
+
return void 0;
|
|
6740
|
+
}
|
|
6741
|
+
function renderReviewUnauthorizedHtml() {
|
|
6742
|
+
return `<!DOCTYPE html>
|
|
6743
|
+
<html lang="zh-CN">
|
|
6744
|
+
<head>
|
|
6745
|
+
<meta charset="utf-8" />
|
|
6746
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6747
|
+
<title>LangLink memoQ \u5DE5\u4F5C\u53F0\u9700\u8981\u6388\u6743\u94FE\u63A5</title>
|
|
6748
|
+
<style>
|
|
6749
|
+
body { margin: 0; padding: 36px 20px; font: 14px/1.6 "Segoe UI", "Microsoft YaHei UI", sans-serif; background: #f8fafc; color: #0f172a; }
|
|
6750
|
+
.card { max-width: 560px; margin: 40px auto; background: #ffffff; border: 1px solid #cbd5e1; border-radius: 10px; padding: 24px; box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06); }
|
|
6751
|
+
h1 { margin: 0 0 10px; font-size: 18px; }
|
|
6752
|
+
p { margin: 8px 0; color: #334155; }
|
|
6753
|
+
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
|
|
6754
|
+
</style>
|
|
6755
|
+
</head>
|
|
6756
|
+
<body>
|
|
6757
|
+
<main class="card">
|
|
6758
|
+
<h1>\u9700\u8981\u6709\u6548\u7684 memoQ \u5BA1\u6821\u5DE5\u4F5C\u53F0\u6388\u6743\u94FE\u63A5</h1>
|
|
6759
|
+
<p>\u51FA\u4E8E\u672C\u5730\u5B89\u5168\u9694\u79BB\u8981\u6C42\uFF0C\u6253\u5F00\u5BA1\u6821\u5DE5\u4F5C\u53F0\u9700\u8981\u5148\u901A\u8FC7 <code>memoq_open_review</code> \u83B7\u53D6\u7684\u6301\u4E45\u5316\u4EE4\u724C\u94FE\u63A5\uFF08<code>/review?token=...</code>\uFF09\u3002</p>
|
|
6760
|
+
<p>\u5728\u540C\u4E00\u6D4F\u89C8\u5668\u4E2D\u901A\u8FC7\u6709\u6548\u94FE\u63A5\u6253\u5F00\u4E00\u6B21\u540E\uFF0C\u6D4F\u89C8\u5668\u4F1A\u81EA\u52A8\u4FDD\u7559\u53D7\u9650 Cookie \u6388\u6743\uFF1B\u6B64\u540E\u5237\u65B0\u9875\u9762\u3001\u4F7F\u7528\u4E66\u7B7E\u6216\u91CD\u542F\u540E\u53F0\u670D\u52A1\u540E\u518D\u6B21\u6253\u5F00\u5747\u53EF\u7EE7\u7EED\u4F7F\u7528\u3002</p>
|
|
6761
|
+
<p style="color:#64748b;font-size:12px;">Unauthorized: present a valid persisted review token link via <code>memoq_open_review</code>.</p>
|
|
6762
|
+
</main>
|
|
6763
|
+
</body>
|
|
6764
|
+
</html>`;
|
|
6765
|
+
}
|
|
6766
|
+
function sendHtml(response, statusCode, html, csp, extraHeaders) {
|
|
6060
6767
|
response.writeHead(statusCode, {
|
|
6061
6768
|
"Content-Type": "text/html; charset=utf-8",
|
|
6062
6769
|
"Cache-Control": "no-store",
|
|
6063
6770
|
"Content-Security-Policy": csp,
|
|
6064
6771
|
"Referrer-Policy": "no-referrer",
|
|
6065
6772
|
"X-Frame-Options": "DENY",
|
|
6066
|
-
"X-Content-Type-Options": "nosniff"
|
|
6773
|
+
"X-Content-Type-Options": "nosniff",
|
|
6774
|
+
...extraHeaders
|
|
6067
6775
|
});
|
|
6068
6776
|
response.end(html);
|
|
6069
6777
|
}
|
|
@@ -6077,13 +6785,35 @@ function isAllowedOrigin(originHeader, boundHost, boundPort) {
|
|
|
6077
6785
|
const normalized = originHeader.toLowerCase();
|
|
6078
6786
|
return normalized === `http://${boundHost}:${boundPort}`.toLowerCase() || normalized === `http://localhost:${boundPort}` || normalized === `http://127.0.0.1:${boundPort}`;
|
|
6079
6787
|
}
|
|
6788
|
+
function isAllowedFetchSite(headerValue) {
|
|
6789
|
+
if (headerValue === void 0) return false;
|
|
6790
|
+
const raw = (Array.isArray(headerValue) ? headerValue[0] : headerValue) ?? "";
|
|
6791
|
+
return raw.trim().toLowerCase() === "same-origin";
|
|
6792
|
+
}
|
|
6793
|
+
function isAllowedReviewNavigation(request) {
|
|
6794
|
+
const fetchMode = request.headers["sec-fetch-mode"];
|
|
6795
|
+
const mode = (Array.isArray(fetchMode) ? fetchMode[0] : fetchMode)?.trim().toLowerCase() ?? "";
|
|
6796
|
+
if (mode === "no-cors") {
|
|
6797
|
+
return false;
|
|
6798
|
+
}
|
|
6799
|
+
const fetchSite = request.headers["sec-fetch-site"];
|
|
6800
|
+
const site = (Array.isArray(fetchSite) ? fetchSite[0] : fetchSite)?.trim().toLowerCase() ?? "";
|
|
6801
|
+
if (site === "cross-site" && mode !== "navigate") {
|
|
6802
|
+
return false;
|
|
6803
|
+
}
|
|
6804
|
+
if (mode && mode !== "navigate" && mode !== "same-origin" && mode !== "cors") {
|
|
6805
|
+
return false;
|
|
6806
|
+
}
|
|
6807
|
+
return true;
|
|
6808
|
+
}
|
|
6080
6809
|
async function createMtGateway(options) {
|
|
6081
6810
|
const host = options.host ?? DEFAULT_HOST;
|
|
6082
6811
|
const requestedPort = options.port ?? DEFAULT_PORT;
|
|
6083
6812
|
const productName = options.productName ?? BRIDGE_PRODUCT_NAME;
|
|
6084
6813
|
const desktopVersion = options.desktopVersion ?? BRIDGE_VERSION;
|
|
6085
6814
|
const controlToken = options.controlToken ?? randomUUID3().replace(/-/gu, "");
|
|
6086
|
-
const
|
|
6815
|
+
const candidateReviewToken = typeof options.reviewToken === "string" ? options.reviewToken.trim() : "";
|
|
6816
|
+
const reviewToken = candidateReviewToken.length >= 24 && candidateReviewToken !== controlToken ? candidateReviewToken : randomBytes(24).toString("hex");
|
|
6087
6817
|
const aggregateJobs = /* @__PURE__ */ new Map();
|
|
6088
6818
|
function getReviewUrl() {
|
|
6089
6819
|
return `http://${host}:${actualPort}/review?token=${reviewToken}`;
|
|
@@ -6681,9 +7411,22 @@ async function createMtGateway(options) {
|
|
|
6681
7411
|
response.setHeader("Referrer-Policy", "no-referrer");
|
|
6682
7412
|
response.setHeader("X-Frame-Options", "DENY");
|
|
6683
7413
|
if (method === "GET" && pathname === "/review") {
|
|
6684
|
-
|
|
6685
|
-
|
|
6686
|
-
|
|
7414
|
+
if (!isAllowedReviewNavigation(request)) {
|
|
7415
|
+
sendJson(response, 403, { success: false, error: "Rejected non-navigation review page fetch." });
|
|
7416
|
+
return;
|
|
7417
|
+
}
|
|
7418
|
+
const hasQueryTokenParam = url.searchParams.has("token");
|
|
7419
|
+
const queryToken = url.searchParams.get("token") ?? void 0;
|
|
7420
|
+
const cookieToken = readCookieValue(request.headers.cookie, REVIEW_COOKIE_NAME);
|
|
7421
|
+
const authenticatedByQuery = hasQueryTokenParam && safeTokenEquals(queryToken, reviewToken);
|
|
7422
|
+
const authenticatedByCookie = !hasQueryTokenParam && safeTokenEquals(cookieToken, reviewToken);
|
|
7423
|
+
if (!authenticatedByQuery && !authenticatedByCookie) {
|
|
7424
|
+
sendHtml(
|
|
7425
|
+
response,
|
|
7426
|
+
401,
|
|
7427
|
+
renderReviewUnauthorizedHtml(),
|
|
7428
|
+
"default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'"
|
|
7429
|
+
);
|
|
6687
7430
|
return;
|
|
6688
7431
|
}
|
|
6689
7432
|
const nonce = randomBytes(16).toString("base64");
|
|
@@ -6697,14 +7440,25 @@ async function createMtGateway(options) {
|
|
|
6697
7440
|
reviewToken,
|
|
6698
7441
|
...initialDocName ? { initialDocumentName: initialDocName } : {}
|
|
6699
7442
|
}),
|
|
6700
|
-
csp
|
|
7443
|
+
csp,
|
|
7444
|
+
authenticatedByQuery ? {
|
|
7445
|
+
"Set-Cookie": `${REVIEW_COOKIE_NAME}=${reviewToken}; HttpOnly; SameSite=Strict; Path=/review; Max-Age=${REVIEW_COOKIE_MAX_AGE_SECONDS}`
|
|
7446
|
+
} : void 0
|
|
6701
7447
|
);
|
|
6702
7448
|
return;
|
|
6703
7449
|
}
|
|
7450
|
+
if (!isAllowedFetchSite(request.headers["sec-fetch-site"])) {
|
|
7451
|
+
sendJson(response, 403, { success: false, error: "Cross-site or missing Sec-Fetch-Site review API requests are not allowed." });
|
|
7452
|
+
return;
|
|
7453
|
+
}
|
|
6704
7454
|
const headerToken = request.headers["x-review-token"];
|
|
6705
7455
|
const providedHeader = Array.isArray(headerToken) ? headerToken[0] : headerToken;
|
|
6706
7456
|
if (!safeTokenEquals(providedHeader, reviewToken)) {
|
|
6707
|
-
sendJson(response, 401, {
|
|
7457
|
+
sendJson(response, 401, {
|
|
7458
|
+
success: false,
|
|
7459
|
+
code: "REVIEW_TOKEN_REQUIRED",
|
|
7460
|
+
error: "Valid review token is required."
|
|
7461
|
+
});
|
|
6708
7462
|
return;
|
|
6709
7463
|
}
|
|
6710
7464
|
if (method === "GET" && pathname === "/review/api/state") {
|
|
@@ -7058,14 +7812,14 @@ async function createMtGateway(options) {
|
|
|
7058
7812
|
}
|
|
7059
7813
|
sendJson(response, 404, { error: `Unknown control route: ${pathname}` });
|
|
7060
7814
|
}
|
|
7061
|
-
await new Promise((
|
|
7815
|
+
await new Promise((resolve7, reject) => {
|
|
7062
7816
|
const onError = (error) => {
|
|
7063
7817
|
server.off("listening", onListening);
|
|
7064
7818
|
reject(error);
|
|
7065
7819
|
};
|
|
7066
7820
|
const onListening = () => {
|
|
7067
7821
|
server.off("error", onError);
|
|
7068
|
-
|
|
7822
|
+
resolve7();
|
|
7069
7823
|
};
|
|
7070
7824
|
server.once("error", onError);
|
|
7071
7825
|
server.once("listening", onListening);
|
|
@@ -7085,8 +7839,8 @@ async function createMtGateway(options) {
|
|
|
7085
7839
|
reviewUrl: getReviewUrl(),
|
|
7086
7840
|
close: () => {
|
|
7087
7841
|
options.stagingStore.flush?.();
|
|
7088
|
-
return new Promise((
|
|
7089
|
-
server.close((error) => error ? reject(error) :
|
|
7842
|
+
return new Promise((resolve7, reject) => {
|
|
7843
|
+
server.close((error) => error ? reject(error) : resolve7());
|
|
7090
7844
|
});
|
|
7091
7845
|
},
|
|
7092
7846
|
handleTranslateForTest: processTranslate
|
|
@@ -7095,8 +7849,9 @@ async function createMtGateway(options) {
|
|
|
7095
7849
|
|
|
7096
7850
|
// packages/memoq-bridge/src/dll-assets.ts
|
|
7097
7851
|
import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
|
|
7098
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
7099
|
-
import {
|
|
7852
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync, readFileSync as readFileSync4, renameSync as renameSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
7853
|
+
import { homedir as homedir2 } from "node:os";
|
|
7854
|
+
import { dirname as dirname4, join as join5, resolve as resolve3 } from "node:path";
|
|
7100
7855
|
import { unzipSync } from "fflate";
|
|
7101
7856
|
var DEFAULT_PLUGIN_DLL_MANIFEST = {
|
|
7102
7857
|
pluginDllName: PLUGIN_DLL_NAME,
|
|
@@ -7109,6 +7864,23 @@ var DEFAULT_PLUGIN_DLL_MANIFEST = {
|
|
|
7109
7864
|
releaseTag: "v1.0.59",
|
|
7110
7865
|
downloadUrl: "https://github.com/langlink-localization/memoq-ai-hub/releases/download/v1.0.59/memoq-ai-hub-win32-x64.zip"
|
|
7111
7866
|
};
|
|
7867
|
+
var MAX_DISCOVERY_DIR_ENTRIES = 200;
|
|
7868
|
+
var MAX_ZIP_INSPECT_BYTES = 200 * 1024 * 1024;
|
|
7869
|
+
var MAX_FAST_ZIP_HASH_BYTES = 25 * 1024 * 1024;
|
|
7870
|
+
var ZIP_CANDIDATE_NAME_RE = /memoq.*(?:ai[-_]?hub|plugin)|memoq\.ai\.hub\.plugin/iu;
|
|
7871
|
+
function acceptedPluginSha256s(explicitExpectedSha256) {
|
|
7872
|
+
const override = (explicitExpectedSha256?.trim() || process.env.MEMOQ_PLUGIN_DLL_SHA256?.trim() || "").toUpperCase();
|
|
7873
|
+
if (override) {
|
|
7874
|
+
return [override];
|
|
7875
|
+
}
|
|
7876
|
+
const all = [DEFAULT_PLUGIN_DLL_MANIFEST.sha256, ...DEFAULT_PLUGIN_DLL_MANIFEST.compatibleSha256s].map((s) => s.trim().toUpperCase()).filter(Boolean);
|
|
7877
|
+
return Array.from(new Set(all));
|
|
7878
|
+
}
|
|
7879
|
+
function matchesAcceptedSha256(actualSha256, explicitExpectedSha256) {
|
|
7880
|
+
const normalized = actualSha256.trim().toUpperCase();
|
|
7881
|
+
if (!normalized) return false;
|
|
7882
|
+
return acceptedPluginSha256s(explicitExpectedSha256).includes(normalized);
|
|
7883
|
+
}
|
|
7112
7884
|
function computeBufferSha256(bytes) {
|
|
7113
7885
|
return createHash2("sha256").update(bytes).digest("hex").toUpperCase();
|
|
7114
7886
|
}
|
|
@@ -7135,6 +7907,15 @@ function parseAllowedAssetUrl(raw) {
|
|
|
7135
7907
|
}
|
|
7136
7908
|
return url;
|
|
7137
7909
|
}
|
|
7910
|
+
function normalizeExpectedShaList(expectedSha256) {
|
|
7911
|
+
if (Array.isArray(expectedSha256)) {
|
|
7912
|
+
return Array.from(new Set(expectedSha256.map((s) => s.trim().toUpperCase()).filter(Boolean)));
|
|
7913
|
+
}
|
|
7914
|
+
if (typeof expectedSha256 === "string" && expectedSha256.trim()) {
|
|
7915
|
+
return [expectedSha256.trim().toUpperCase()];
|
|
7916
|
+
}
|
|
7917
|
+
return [];
|
|
7918
|
+
}
|
|
7138
7919
|
function extractPluginDllFromBytes(bytes, expectedSha256) {
|
|
7139
7920
|
if (bytes.length < 2) {
|
|
7140
7921
|
throw new Error("Downloaded plugin artifact is empty.");
|
|
@@ -7161,9 +7942,10 @@ function extractPluginDllFromBytes(bytes, expectedSha256) {
|
|
|
7161
7942
|
dllBytes = bytes;
|
|
7162
7943
|
}
|
|
7163
7944
|
const actualSha256 = computeBufferSha256(dllBytes);
|
|
7164
|
-
|
|
7945
|
+
const expectedList = normalizeExpectedShaList(expectedSha256);
|
|
7946
|
+
if (expectedList.length > 0 && !expectedList.includes(actualSha256)) {
|
|
7165
7947
|
throw new Error(
|
|
7166
|
-
`Plugin DLL SHA-256 mismatch. Expected ${
|
|
7948
|
+
`Plugin DLL SHA-256 mismatch. Expected ${expectedList.join(" or ")}, actual ${actualSha256}.`
|
|
7167
7949
|
);
|
|
7168
7950
|
}
|
|
7169
7951
|
return { dllBytes, sha256: actualSha256 };
|
|
@@ -7189,50 +7971,212 @@ function getPluginAssetCachePath(dataDir, version = DEFAULT_PLUGIN_DLL_MANIFEST.
|
|
|
7189
7971
|
const root = dataDir ?? defaultBridgeDataDir();
|
|
7190
7972
|
return join5(root, "assets", version, PLUGIN_DLL_NAME);
|
|
7191
7973
|
}
|
|
7974
|
+
function writeAtomicCacheDll(cachePath, dllBytes) {
|
|
7975
|
+
mkdirSync3(dirname4(cachePath), { recursive: true });
|
|
7976
|
+
const temp = `${cachePath}.${randomUUID4()}.tmp`;
|
|
7977
|
+
writeFileSync3(temp, dllBytes);
|
|
7978
|
+
renameSync2(temp, cachePath);
|
|
7979
|
+
}
|
|
7980
|
+
function inspectCandidateFile(filePath, source, acceptedShas, maxZipHashBytes) {
|
|
7981
|
+
try {
|
|
7982
|
+
const resolved = resolve3(filePath);
|
|
7983
|
+
if (!existsSync4(resolved)) return null;
|
|
7984
|
+
const stats = statSync2(resolved);
|
|
7985
|
+
if (!stats.isFile()) return null;
|
|
7986
|
+
const lower = resolved.toLowerCase();
|
|
7987
|
+
let isZip = lower.endsWith(".zip");
|
|
7988
|
+
if (!isZip && stats.size >= 2) {
|
|
7989
|
+
const head = readFileSync4(resolved).subarray(0, 2);
|
|
7990
|
+
isZip = head[0] === 80 && head[1] === 75;
|
|
7991
|
+
}
|
|
7992
|
+
if (isZip) {
|
|
7993
|
+
if (stats.size > MAX_ZIP_INSPECT_BYTES) return null;
|
|
7994
|
+
if (stats.size > maxZipHashBytes) {
|
|
7995
|
+
return {
|
|
7996
|
+
path: resolved,
|
|
7997
|
+
kind: "zip",
|
|
7998
|
+
source,
|
|
7999
|
+
sha256: "",
|
|
8000
|
+
sha256MatchesExpected: false,
|
|
8001
|
+
sizeBytes: stats.size
|
|
8002
|
+
};
|
|
8003
|
+
}
|
|
8004
|
+
const bytes2 = readFileSync4(resolved);
|
|
8005
|
+
const { sha256: sha2562 } = extractPluginDllFromBytes(bytes2);
|
|
8006
|
+
return {
|
|
8007
|
+
path: resolved,
|
|
8008
|
+
kind: "zip",
|
|
8009
|
+
source,
|
|
8010
|
+
sha256: sha2562,
|
|
8011
|
+
sha256MatchesExpected: acceptedShas.includes(sha2562),
|
|
8012
|
+
sizeBytes: stats.size
|
|
8013
|
+
};
|
|
8014
|
+
}
|
|
8015
|
+
const bytes = readFileSync4(resolved);
|
|
8016
|
+
if (bytes.length < 2 || bytes[0] !== 77 || bytes[1] !== 90) {
|
|
8017
|
+
return null;
|
|
8018
|
+
}
|
|
8019
|
+
const sha256 = computeBufferSha256(bytes);
|
|
8020
|
+
return {
|
|
8021
|
+
path: resolved,
|
|
8022
|
+
kind: "dll",
|
|
8023
|
+
source,
|
|
8024
|
+
sha256,
|
|
8025
|
+
sha256MatchesExpected: acceptedShas.includes(sha256),
|
|
8026
|
+
sizeBytes: stats.size
|
|
8027
|
+
};
|
|
8028
|
+
} catch {
|
|
8029
|
+
return null;
|
|
8030
|
+
}
|
|
8031
|
+
}
|
|
8032
|
+
function discoverLocalPluginDllCandidates(options = {}) {
|
|
8033
|
+
const dataDir = options.dataDir ?? defaultBridgeDataDir();
|
|
8034
|
+
const version = options.version ?? DEFAULT_PLUGIN_DLL_MANIFEST.version;
|
|
8035
|
+
const acceptedShas = acceptedPluginSha256s(options.expectedSha256);
|
|
8036
|
+
const candidates = [];
|
|
8037
|
+
const seenFiles = /* @__PURE__ */ new Set();
|
|
8038
|
+
const pushCandidate = (candidate) => {
|
|
8039
|
+
if (!candidate) return;
|
|
8040
|
+
const key = process.platform === "win32" ? candidate.path.toLowerCase() : candidate.path;
|
|
8041
|
+
if (seenFiles.has(key)) return;
|
|
8042
|
+
seenFiles.add(key);
|
|
8043
|
+
candidates.push(candidate);
|
|
8044
|
+
};
|
|
8045
|
+
const explicitPath = (options.dllPath ?? process.env.MEMOQ_PLUGIN_DLL_PATH ?? "").trim();
|
|
8046
|
+
if (explicitPath) {
|
|
8047
|
+
pushCandidate(inspectCandidateFile(explicitPath, "explicit", acceptedShas, MAX_ZIP_INSPECT_BYTES));
|
|
8048
|
+
}
|
|
8049
|
+
const cachePath = getPluginAssetCachePath(dataDir, version);
|
|
8050
|
+
pushCandidate(inspectCandidateFile(cachePath, "cache", acceptedShas, MAX_FAST_ZIP_HASH_BYTES));
|
|
8051
|
+
for (const hubCandidate of defaultDiscoveryCandidates()) {
|
|
8052
|
+
pushCandidate(inspectCandidateFile(hubCandidate, "memoq-ai-hub", acceptedShas, MAX_FAST_ZIP_HASH_BYTES));
|
|
8053
|
+
}
|
|
8054
|
+
for (const extra of options.extraFilePaths ?? []) {
|
|
8055
|
+
if (!extra?.trim()) continue;
|
|
8056
|
+
pushCandidate(inspectCandidateFile(extra, "memoq-addins", acceptedShas, MAX_FAST_ZIP_HASH_BYTES));
|
|
8057
|
+
}
|
|
8058
|
+
const rawDirs = [...options.searchDirs ?? []];
|
|
8059
|
+
if (options.includeDefaultUserDirs !== false) {
|
|
8060
|
+
const home = homedir2();
|
|
8061
|
+
rawDirs.push(process.cwd(), join5(home, "Downloads"), join5(home, "Desktop"));
|
|
8062
|
+
}
|
|
8063
|
+
const seenDirs = /* @__PURE__ */ new Set();
|
|
8064
|
+
for (const rawDir of rawDirs) {
|
|
8065
|
+
if (!rawDir?.trim()) continue;
|
|
8066
|
+
let resolvedDir;
|
|
8067
|
+
try {
|
|
8068
|
+
resolvedDir = resolve3(rawDir.trim());
|
|
8069
|
+
} catch {
|
|
8070
|
+
continue;
|
|
8071
|
+
}
|
|
8072
|
+
const dirKey = process.platform === "win32" ? resolvedDir.toLowerCase() : resolvedDir;
|
|
8073
|
+
if (seenDirs.has(dirKey)) continue;
|
|
8074
|
+
seenDirs.add(dirKey);
|
|
8075
|
+
if (!existsSync4(resolvedDir)) continue;
|
|
8076
|
+
try {
|
|
8077
|
+
const entries = readdirSync(resolvedDir, { withFileTypes: true }).slice(0, MAX_DISCOVERY_DIR_ENTRIES);
|
|
8078
|
+
for (const entry of entries) {
|
|
8079
|
+
if (!entry.isFile()) continue;
|
|
8080
|
+
const lowerName = entry.name.toLowerCase();
|
|
8081
|
+
if (lowerName === PLUGIN_DLL_NAME.toLowerCase()) {
|
|
8082
|
+
pushCandidate(
|
|
8083
|
+
inspectCandidateFile(join5(resolvedDir, entry.name), "local-folder", acceptedShas, MAX_FAST_ZIP_HASH_BYTES)
|
|
8084
|
+
);
|
|
8085
|
+
} else if (lowerName.endsWith(".zip") && ZIP_CANDIDATE_NAME_RE.test(entry.name)) {
|
|
8086
|
+
pushCandidate(
|
|
8087
|
+
inspectCandidateFile(join5(resolvedDir, entry.name), "local-folder", acceptedShas, MAX_FAST_ZIP_HASH_BYTES)
|
|
8088
|
+
);
|
|
8089
|
+
}
|
|
8090
|
+
}
|
|
8091
|
+
} catch {
|
|
8092
|
+
}
|
|
8093
|
+
}
|
|
8094
|
+
return candidates.sort((a, b) => {
|
|
8095
|
+
const matchDiff = Number(b.sha256MatchesExpected) - Number(a.sha256MatchesExpected);
|
|
8096
|
+
if (matchDiff !== 0) return matchDiff;
|
|
8097
|
+
return Number(b.kind === "dll") - Number(a.kind === "dll");
|
|
8098
|
+
});
|
|
8099
|
+
}
|
|
7192
8100
|
async function resolvePluginDllAsset(options = {}) {
|
|
7193
8101
|
const dataDir = options.dataDir ?? defaultBridgeDataDir();
|
|
7194
8102
|
const version = options.version ?? DEFAULT_PLUGIN_DLL_MANIFEST.version;
|
|
7195
|
-
const
|
|
8103
|
+
const acceptedShas = acceptedPluginSha256s(options.expectedSha256);
|
|
8104
|
+
const expectedDisplay = acceptedShas.join(" or ");
|
|
8105
|
+
const cachePath = getPluginAssetCachePath(dataDir, version);
|
|
7196
8106
|
const explicitPath = (options.dllPath ?? process.env.MEMOQ_PLUGIN_DLL_PATH ?? "").trim();
|
|
7197
8107
|
if (explicitPath) {
|
|
7198
8108
|
const resolved = resolve3(explicitPath);
|
|
7199
8109
|
if (!existsSync4(resolved)) {
|
|
7200
8110
|
throw new Error(`Configured MEMOQ_PLUGIN_DLL_PATH does not exist: ${resolved}`);
|
|
7201
8111
|
}
|
|
7202
|
-
const
|
|
7203
|
-
|
|
7204
|
-
|
|
8112
|
+
const rawBytes2 = readFileSync4(resolved);
|
|
8113
|
+
const isZip = rawBytes2.length >= 2 && rawBytes2[0] === 80 && rawBytes2[1] === 75;
|
|
8114
|
+
if (isZip) {
|
|
8115
|
+
const extracted = extractPluginDllFromBytes(
|
|
8116
|
+
rawBytes2,
|
|
8117
|
+
options.allowUnverifiedLocalDev ? void 0 : acceptedShas
|
|
8118
|
+
);
|
|
8119
|
+
writeAtomicCacheDll(cachePath, extracted.dllBytes);
|
|
8120
|
+
return {
|
|
8121
|
+
path: cachePath,
|
|
8122
|
+
sha256: extracted.sha256,
|
|
8123
|
+
version,
|
|
8124
|
+
source: "explicit",
|
|
8125
|
+
verified: acceptedShas.includes(extracted.sha256)
|
|
8126
|
+
};
|
|
8127
|
+
}
|
|
8128
|
+
const isPe = rawBytes2.length >= 2 && rawBytes2[0] === 77 && rawBytes2[1] === 90;
|
|
8129
|
+
if (!isPe) {
|
|
8130
|
+
throw new Error(`File is neither a PE DLL nor a ZIP archive containing ${PLUGIN_DLL_NAME}: ${resolved}`);
|
|
8131
|
+
}
|
|
8132
|
+
const sha2562 = computeBufferSha256(rawBytes2);
|
|
8133
|
+
const verified = acceptedShas.includes(sha2562);
|
|
8134
|
+
if (!options.allowUnverifiedLocalDev && acceptedShas.length > 0 && !verified) {
|
|
8135
|
+
throw new Error(`Plugin DLL SHA-256 mismatch at ${resolved}. Expected ${expectedDisplay}, actual ${sha2562}.`);
|
|
7205
8136
|
}
|
|
7206
8137
|
return {
|
|
7207
8138
|
path: resolved,
|
|
7208
8139
|
sha256: sha2562,
|
|
7209
8140
|
version,
|
|
7210
8141
|
source: "explicit",
|
|
7211
|
-
verified
|
|
8142
|
+
verified
|
|
7212
8143
|
};
|
|
7213
8144
|
}
|
|
7214
|
-
const cachePath = getPluginAssetCachePath(dataDir, version);
|
|
7215
8145
|
if (existsSync4(cachePath)) {
|
|
7216
8146
|
const sha2562 = computeFileSha256(cachePath);
|
|
7217
|
-
if (
|
|
8147
|
+
if (acceptedShas.length === 0 || acceptedShas.includes(sha2562)) {
|
|
7218
8148
|
return {
|
|
7219
8149
|
path: cachePath,
|
|
7220
8150
|
sha256: sha2562,
|
|
7221
8151
|
version,
|
|
7222
8152
|
source: "cache",
|
|
7223
|
-
verified:
|
|
8153
|
+
verified: acceptedShas.includes(sha2562)
|
|
7224
8154
|
};
|
|
7225
8155
|
}
|
|
7226
8156
|
}
|
|
7227
8157
|
const discoveryPaths = [...options.searchPaths ?? [], ...defaultDiscoveryCandidates()];
|
|
7228
8158
|
for (const candidate of discoveryPaths) {
|
|
7229
8159
|
if (!candidate || !existsSync4(candidate)) continue;
|
|
7230
|
-
const
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
8160
|
+
const rawBytes2 = readFileSync4(candidate);
|
|
8161
|
+
const isZip = rawBytes2.length >= 2 && rawBytes2[0] === 80 && rawBytes2[1] === 75;
|
|
8162
|
+
if (isZip) {
|
|
8163
|
+
try {
|
|
8164
|
+
const extracted = extractPluginDllFromBytes(rawBytes2, acceptedShas);
|
|
8165
|
+
writeAtomicCacheDll(cachePath, extracted.dllBytes);
|
|
8166
|
+
return {
|
|
8167
|
+
path: cachePath,
|
|
8168
|
+
sha256: extracted.sha256,
|
|
8169
|
+
version,
|
|
8170
|
+
source: "local-discovery",
|
|
8171
|
+
verified: true
|
|
8172
|
+
};
|
|
8173
|
+
} catch {
|
|
8174
|
+
continue;
|
|
8175
|
+
}
|
|
8176
|
+
}
|
|
8177
|
+
const sha2562 = computeBufferSha256(rawBytes2);
|
|
8178
|
+
if (acceptedShas.length > 0 && !acceptedShas.includes(sha2562)) continue;
|
|
8179
|
+
writeAtomicCacheDll(cachePath, rawBytes2);
|
|
7236
8180
|
return {
|
|
7237
8181
|
path: cachePath,
|
|
7238
8182
|
sha256: sha2562,
|
|
@@ -7241,9 +8185,46 @@ async function resolvePluginDllAsset(options = {}) {
|
|
|
7241
8185
|
verified: true
|
|
7242
8186
|
};
|
|
7243
8187
|
}
|
|
8188
|
+
if (options.searchDirs && options.searchDirs.length > 0 || options.includeDefaultUserDirs === true) {
|
|
8189
|
+
const folderCandidates = discoverLocalPluginDllCandidates({
|
|
8190
|
+
dataDir,
|
|
8191
|
+
...options.expectedSha256 === void 0 ? {} : { expectedSha256: options.expectedSha256 },
|
|
8192
|
+
version,
|
|
8193
|
+
searchDirs: options.searchDirs ?? [],
|
|
8194
|
+
includeDefaultUserDirs: options.includeDefaultUserDirs === true
|
|
8195
|
+
});
|
|
8196
|
+
for (const candidate of folderCandidates) {
|
|
8197
|
+
try {
|
|
8198
|
+
const rawBytes2 = readFileSync4(candidate.path);
|
|
8199
|
+
if (candidate.kind === "zip") {
|
|
8200
|
+
const extracted = extractPluginDllFromBytes(rawBytes2, acceptedShas);
|
|
8201
|
+
writeAtomicCacheDll(cachePath, extracted.dllBytes);
|
|
8202
|
+
return {
|
|
8203
|
+
path: cachePath,
|
|
8204
|
+
sha256: extracted.sha256,
|
|
8205
|
+
version,
|
|
8206
|
+
source: "local-discovery",
|
|
8207
|
+
verified: true
|
|
8208
|
+
};
|
|
8209
|
+
}
|
|
8210
|
+
const sha2562 = computeBufferSha256(rawBytes2);
|
|
8211
|
+
if (acceptedShas.length > 0 && !acceptedShas.includes(sha2562)) continue;
|
|
8212
|
+
writeAtomicCacheDll(cachePath, rawBytes2);
|
|
8213
|
+
return {
|
|
8214
|
+
path: cachePath,
|
|
8215
|
+
sha256: sha2562,
|
|
8216
|
+
version,
|
|
8217
|
+
source: "local-discovery",
|
|
8218
|
+
verified: true
|
|
8219
|
+
};
|
|
8220
|
+
} catch {
|
|
8221
|
+
continue;
|
|
8222
|
+
}
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
7244
8225
|
if (options.allowDownload === false) {
|
|
7245
8226
|
throw new Error(
|
|
7246
|
-
`Plugin DLL ${PLUGIN_DLL_NAME} is not cached locally (expected SHA-256 ${
|
|
8227
|
+
`Plugin DLL ${PLUGIN_DLL_NAME} is not cached locally (expected SHA-256 ${expectedDisplay}). Run memoq_setup to download or provide MEMOQ_PLUGIN_DLL_PATH.`
|
|
7247
8228
|
);
|
|
7248
8229
|
}
|
|
7249
8230
|
const rawUrl = (options.downloadUrl ?? process.env.MEMOQ_PLUGIN_DLL_URL ?? DEFAULT_PLUGIN_DLL_MANIFEST.downloadUrl).trim();
|
|
@@ -7254,25 +8235,22 @@ async function resolvePluginDllAsset(options = {}) {
|
|
|
7254
8235
|
throw new Error(`Failed to download ${PLUGIN_DLL_NAME} (${response.status} ${response.statusText}).`);
|
|
7255
8236
|
}
|
|
7256
8237
|
const rawBytes = new Uint8Array(await response.arrayBuffer());
|
|
7257
|
-
const { dllBytes, sha256 } = extractPluginDllFromBytes(rawBytes,
|
|
7258
|
-
|
|
7259
|
-
const temp = `${cachePath}.${randomUUID4()}.tmp`;
|
|
7260
|
-
writeFileSync3(temp, dllBytes);
|
|
7261
|
-
renameSync2(temp, cachePath);
|
|
8238
|
+
const { dllBytes, sha256 } = extractPluginDllFromBytes(rawBytes, acceptedShas);
|
|
8239
|
+
writeAtomicCacheDll(cachePath, dllBytes);
|
|
7262
8240
|
return {
|
|
7263
8241
|
path: cachePath,
|
|
7264
8242
|
sha256,
|
|
7265
8243
|
version,
|
|
7266
8244
|
source: "downloaded",
|
|
7267
|
-
verified:
|
|
8245
|
+
verified: acceptedShas.includes(sha256)
|
|
7268
8246
|
};
|
|
7269
8247
|
}
|
|
7270
8248
|
|
|
7271
8249
|
// packages/memoq-bridge/src/dll-installer.ts
|
|
7272
|
-
import { execFile } from "node:child_process";
|
|
8250
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
7273
8251
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
7274
8252
|
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync5, rmSync as rmSync2 } from "node:fs";
|
|
7275
|
-
import { basename, join as join6, win32 } from "node:path";
|
|
8253
|
+
import { basename, join as join6, resolve as resolve4, win32 } from "node:path";
|
|
7276
8254
|
import { promisify } from "node:util";
|
|
7277
8255
|
var execFileAsync = promisify(execFile);
|
|
7278
8256
|
var SUPPORTED_VERSIONS = ["12", "11", "10"];
|
|
@@ -7301,18 +8279,92 @@ function readClientDevConfigState(programDataDir) {
|
|
|
7301
8279
|
return { path: filePath, exists: true, loadUnsignedPluginsEnabled: false };
|
|
7302
8280
|
}
|
|
7303
8281
|
}
|
|
8282
|
+
function discoverWindowsMemoQRoots(helperPath) {
|
|
8283
|
+
if (!helperPath || !existsSync5(helperPath)) {
|
|
8284
|
+
return [];
|
|
8285
|
+
}
|
|
8286
|
+
try {
|
|
8287
|
+
const stdout = execFileSync(helperPath, ["--discover-memoq"], {
|
|
8288
|
+
encoding: "utf8",
|
|
8289
|
+
timeout: 5e3,
|
|
8290
|
+
windowsHide: true
|
|
8291
|
+
});
|
|
8292
|
+
const parsed = JSON.parse(stdout.trim());
|
|
8293
|
+
if (!parsed?.ok || !Array.isArray(parsed.roots)) {
|
|
8294
|
+
return [];
|
|
8295
|
+
}
|
|
8296
|
+
const results = [];
|
|
8297
|
+
for (const entry of parsed.roots) {
|
|
8298
|
+
const rootDir = typeof entry?.rootDir === "string" ? entry.rootDir.trim() : "";
|
|
8299
|
+
if (!rootDir) continue;
|
|
8300
|
+
const version = typeof entry?.version === "string" && entry.version.trim() ? entry.version.trim() : "custom";
|
|
8301
|
+
const srcRaw = typeof entry?.source === "string" ? entry.source.trim() : "";
|
|
8302
|
+
const source = srcRaw === "running-process" || srcRaw === "registry" || srcRaw === "drive-scan" ? srcRaw : "drive-scan";
|
|
8303
|
+
results.push({ version, rootDir, source });
|
|
8304
|
+
}
|
|
8305
|
+
return results;
|
|
8306
|
+
} catch {
|
|
8307
|
+
return [];
|
|
8308
|
+
}
|
|
8309
|
+
}
|
|
8310
|
+
function isProtectedWindowsPath(targetPath, programDataDir) {
|
|
8311
|
+
const checkOne = (raw) => {
|
|
8312
|
+
if (!raw || !raw.trim()) return false;
|
|
8313
|
+
const norm = raw.trim().replace(/\//gu, "\\").toLowerCase();
|
|
8314
|
+
const envProtected = [
|
|
8315
|
+
process.env.ProgramFiles,
|
|
8316
|
+
process.env["ProgramFiles(x86)"],
|
|
8317
|
+
process.env.ProgramData,
|
|
8318
|
+
process.env.SystemRoot,
|
|
8319
|
+
process.env.WINDIR
|
|
8320
|
+
].filter((v) => Boolean(v && v.trim())).map((v) => v.trim().replace(/\//gu, "\\").replace(/\\+$/u, "").toLowerCase());
|
|
8321
|
+
for (const base of envProtected) {
|
|
8322
|
+
if (norm === base || norm.startsWith(`${base}\\`)) {
|
|
8323
|
+
return true;
|
|
8324
|
+
}
|
|
8325
|
+
}
|
|
8326
|
+
return /^[a-z]:\\(?:program files(?: \(x86\))?|programdata|windows)(?:\\|$)/iu.test(norm);
|
|
8327
|
+
};
|
|
8328
|
+
return checkOne(targetPath) || (programDataDir ? checkOne(programDataDir) : false);
|
|
8329
|
+
}
|
|
7304
8330
|
function detectMemoQInstallations(options = {}) {
|
|
7305
|
-
const
|
|
8331
|
+
const platform = options.platform ?? process.platform;
|
|
7306
8332
|
const clientDevConfig = readClientDevConfigState(options.programDataDir);
|
|
7307
8333
|
const candidates = [];
|
|
7308
8334
|
const seen = /* @__PURE__ */ new Set();
|
|
7309
8335
|
if (options.customInstallDir?.trim()) {
|
|
7310
8336
|
const customRoot = options.customInstallDir.trim();
|
|
7311
8337
|
const versionMatch = /memoq[-_\s]?(\d+)/iu.exec(basename(customRoot));
|
|
7312
|
-
candidates.push({ version: versionMatch?.[1] ?? "custom", rootDir: customRoot });
|
|
8338
|
+
candidates.push({ version: versionMatch?.[1] ?? "custom", rootDir: customRoot, source: "custom" });
|
|
7313
8339
|
}
|
|
7314
|
-
|
|
7315
|
-
|
|
8340
|
+
if (options.defaultRoots !== void 0) {
|
|
8341
|
+
for (const item of options.defaultRoots) {
|
|
8342
|
+
candidates.push({ ...item, source: "default" });
|
|
8343
|
+
}
|
|
8344
|
+
} else {
|
|
8345
|
+
if (platform === "win32" && options.skipHostDiscovery !== true) {
|
|
8346
|
+
let helperPath = options.helperExecutablePath ?? null;
|
|
8347
|
+
if (!helperPath) {
|
|
8348
|
+
try {
|
|
8349
|
+
helperPath = ensureRunnableHelperBinary({
|
|
8350
|
+
...options.dataDir === void 0 ? {} : { dataDir: options.dataDir },
|
|
8351
|
+
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot }
|
|
8352
|
+
});
|
|
8353
|
+
} catch {
|
|
8354
|
+
helperPath = null;
|
|
8355
|
+
}
|
|
8356
|
+
}
|
|
8357
|
+
for (const discovered of discoverWindowsMemoQRoots(helperPath)) {
|
|
8358
|
+
candidates.push({
|
|
8359
|
+
version: discovered.version,
|
|
8360
|
+
rootDir: discovered.rootDir,
|
|
8361
|
+
source: discovered.source
|
|
8362
|
+
});
|
|
8363
|
+
}
|
|
8364
|
+
}
|
|
8365
|
+
for (const item of defaultMemoQRooDirs()) {
|
|
8366
|
+
candidates.push({ ...item, source: "default" });
|
|
8367
|
+
}
|
|
7316
8368
|
}
|
|
7317
8369
|
const installations = [];
|
|
7318
8370
|
for (const candidate of candidates) {
|
|
@@ -7327,7 +8379,7 @@ function detectMemoQInstallations(options = {}) {
|
|
|
7327
8379
|
const legacyPluginInstalled = existsSync5(legacyTarget);
|
|
7328
8380
|
const pluginSha256 = pluginInstalled ? computeFileSha256(pluginTarget) : "";
|
|
7329
8381
|
const sha256MatchesExpected = Boolean(
|
|
7330
|
-
pluginInstalled && (options.expectedSha256
|
|
8382
|
+
pluginInstalled && matchesAcceptedSha256(pluginSha256, options.expectedSha256)
|
|
7331
8383
|
);
|
|
7332
8384
|
let status = "not_installed";
|
|
7333
8385
|
if (pluginInstalled && clientDevConfig.loadUnsignedPluginsEnabled && !legacyPluginInstalled) {
|
|
@@ -7345,7 +8397,8 @@ function detectMemoQInstallations(options = {}) {
|
|
|
7345
8397
|
pluginSha256,
|
|
7346
8398
|
sha256MatchesExpected,
|
|
7347
8399
|
legacyPluginInstalled,
|
|
7348
|
-
status
|
|
8400
|
+
status,
|
|
8401
|
+
...candidate.source === void 0 ? {} : { discoverySource: candidate.source }
|
|
7349
8402
|
});
|
|
7350
8403
|
}
|
|
7351
8404
|
return { clientDevConfig, installations };
|
|
@@ -7487,16 +8540,247 @@ async function uninstallPluginWithHelper(options) {
|
|
|
7487
8540
|
}
|
|
7488
8541
|
return result;
|
|
7489
8542
|
}
|
|
8543
|
+
function buildPluginInstallPlan(options = {}) {
|
|
8544
|
+
const integration = getIntegrationStatus(options);
|
|
8545
|
+
const platform = integration.platform;
|
|
8546
|
+
const acceptedShas = acceptedPluginSha256s(options.expectedSha256);
|
|
8547
|
+
const expectedSha256 = acceptedShas[0] ?? integration.expectedPluginSha256;
|
|
8548
|
+
const effectiveProgramData = options.programDataDir ?? process.env.ProgramData ?? "C:\\ProgramData";
|
|
8549
|
+
const extraFilePaths = integration.installations.filter((item) => item.pluginInstalled).map((item) => item.pluginTarget);
|
|
8550
|
+
const discoveredDlls = discoverLocalPluginDllCandidates({
|
|
8551
|
+
...options.dataDir === void 0 ? {} : { dataDir: options.dataDir },
|
|
8552
|
+
...options.dllPath === void 0 ? {} : { dllPath: options.dllPath },
|
|
8553
|
+
...options.expectedSha256 === void 0 ? {} : { expectedSha256: options.expectedSha256 },
|
|
8554
|
+
...options.searchDirs === void 0 ? {} : { searchDirs: options.searchDirs },
|
|
8555
|
+
extraFilePaths,
|
|
8556
|
+
includeDefaultUserDirs: options.includeDefaultUserDirs ?? options.skipHostDiscovery !== true
|
|
8557
|
+
});
|
|
8558
|
+
const explicitDllPath = (options.dllPath ?? process.env.MEMOQ_PLUGIN_DLL_PATH ?? "").trim();
|
|
8559
|
+
const explicitResolved = explicitDllPath ? resolve4(explicitDllPath) : "";
|
|
8560
|
+
const explicitCandidate = explicitResolved ? discoveredDlls.find(
|
|
8561
|
+
(c) => (process.platform === "win32" ? c.path.toLowerCase() === explicitResolved.toLowerCase() : c.path === explicitResolved) || c.source === "explicit"
|
|
8562
|
+
) ?? null : null;
|
|
8563
|
+
const selectedDllCandidate = explicitDllPath ? explicitCandidate : discoveredDlls.find((c) => c.sha256MatchesExpected) ?? discoveredDlls.find((c) => c.kind === "zip" && c.sha256 === "") ?? null;
|
|
8564
|
+
const blockers = [];
|
|
8565
|
+
if (platform !== "win32") {
|
|
8566
|
+
blockers.push(`\u5F53\u524D\u7CFB\u7EDF (${platform}) \u4E0D\u652F\u6301\u5B89\u88C5 memoQ Desktop Windows \u63D2\u4EF6\u3002`);
|
|
8567
|
+
}
|
|
8568
|
+
if (options.customInstallDir?.trim()) {
|
|
8569
|
+
const customAddins = join6(options.customInstallDir.trim(), "Addins");
|
|
8570
|
+
if (!existsSync5(customAddins)) {
|
|
8571
|
+
blockers.push(`\u6307\u5B9A\u7684 memoQ \u76EE\u5F55\u4E0B\u672A\u627E\u5230 Addins \u5B50\u76EE\u5F55: ${customAddins}`);
|
|
8572
|
+
}
|
|
8573
|
+
}
|
|
8574
|
+
if (platform === "win32" && integration.installations.length === 0) {
|
|
8575
|
+
blockers.push(
|
|
8576
|
+
"\u672A\u68C0\u6D4B\u5230 memoQ \u5B89\u88C5\u76EE\u5F55\uFF08\u5DF2\u68C0\u67E5\u8FD0\u884C\u4E2D\u8FDB\u7A0B\u3001\u6CE8\u518C\u8868\u3001\u672C\u5730\u78C1\u76D8\u53CA\u9ED8\u8BA4\u8DEF\u5F84\uFF09\u3002\u8BF7\u63D0\u4F9B customInstallDir \u6216 memoqRoot\u3002"
|
|
8577
|
+
);
|
|
8578
|
+
}
|
|
8579
|
+
if (explicitDllPath) {
|
|
8580
|
+
if (!existsSync5(explicitResolved)) {
|
|
8581
|
+
blockers.push(`\u6307\u5B9A\u7684 DLL / ZIP \u8DEF\u5F84\u4E0D\u5B58\u5728: ${explicitResolved}`);
|
|
8582
|
+
} else if (!explicitCandidate) {
|
|
8583
|
+
blockers.push(`\u6307\u5B9A\u6587\u4EF6\u4E0D\u662F\u6709\u6548\u7684 ${PLUGIN_DLL_NAME} \u6216\u5305\u542B\u8BE5 DLL \u7684 ZIP \u5305: ${explicitResolved}`);
|
|
8584
|
+
} else if (!options.allowUnverifiedLocalDev && explicitCandidate.kind === "dll" && !explicitCandidate.sha256MatchesExpected) {
|
|
8585
|
+
blockers.push(
|
|
8586
|
+
`\u6307\u5B9A DLL \u7684 SHA-256 (${explicitCandidate.sha256}) \u4E0E\u9884\u671F (${acceptedShas.join(" or ")}) \u4E0D\u5339\u914D\u3002`
|
|
8587
|
+
);
|
|
8588
|
+
}
|
|
8589
|
+
} else if (!selectedDllCandidate && options.allowDownload === false) {
|
|
8590
|
+
blockers.push(
|
|
8591
|
+
`\u672C\u673A\u672A\u627E\u5230\u53EF\u7528\u7684 ${PLUGIN_DLL_NAME} \u4E14\u7981\u7528\u4E86\u5728\u7EBF\u4E0B\u8F7D\uFF08\u671F\u671B SHA-256: ${expectedSha256}\uFF09\u3002\u8BF7\u63D0\u4F9B\u672C\u5730 DLL/ZIP \u7684 dllPath\u3002`
|
|
8592
|
+
);
|
|
8593
|
+
}
|
|
8594
|
+
let recommendedInst = null;
|
|
8595
|
+
if (options.customInstallDir?.trim()) {
|
|
8596
|
+
const normCustom = options.customInstallDir.trim().toLowerCase();
|
|
8597
|
+
recommendedInst = integration.installations.find((item) => item.rootDir.toLowerCase() === normCustom) ?? null;
|
|
8598
|
+
}
|
|
8599
|
+
if (!recommendedInst) {
|
|
8600
|
+
recommendedInst = integration.installations.find((item) => item.status === "not_installed" || item.status === "needs_repair") ?? integration.installations[0] ?? null;
|
|
8601
|
+
}
|
|
8602
|
+
const recommendedMemoqRoot = recommendedInst?.rootDir ?? null;
|
|
8603
|
+
const targetDllPath = recommendedInst?.pluginTarget ?? null;
|
|
8604
|
+
const clientDevConfigAction = !integration.clientDevConfig.exists ? "create_new" : integration.clientDevConfig.loadUnsignedPluginsEnabled ? "already_enabled" : "backup_and_merge";
|
|
8605
|
+
const requiresElevation = Boolean(
|
|
8606
|
+
platform === "win32" && recommendedMemoqRoot && isProtectedWindowsPath(recommendedMemoqRoot, effectiveProgramData)
|
|
8607
|
+
);
|
|
8608
|
+
const willDownloadFromRelease = !selectedDllCandidate && !explicitDllPath;
|
|
8609
|
+
return {
|
|
8610
|
+
platform,
|
|
8611
|
+
operation: "copy",
|
|
8612
|
+
preservesOriginalSource: true,
|
|
8613
|
+
readyToInstall: blockers.length === 0 && Boolean(recommendedMemoqRoot),
|
|
8614
|
+
alreadyInstalled: integration.status === "installed",
|
|
8615
|
+
canReuseExisting: integration.canReuseExisting,
|
|
8616
|
+
blockers,
|
|
8617
|
+
expectedPluginDllName: integration.expectedPluginDllName,
|
|
8618
|
+
expectedPluginVersion: integration.expectedPluginVersion,
|
|
8619
|
+
expectedSha256,
|
|
8620
|
+
acceptedSha256s: acceptedShas,
|
|
8621
|
+
recommendedMemoqRoot,
|
|
8622
|
+
installations: integration.installations,
|
|
8623
|
+
discoveredDlls,
|
|
8624
|
+
selectedDllCandidate,
|
|
8625
|
+
willDownloadFromRelease,
|
|
8626
|
+
downloadUrl: DEFAULT_PLUGIN_DLL_MANIFEST.downloadUrl,
|
|
8627
|
+
plannedChanges: {
|
|
8628
|
+
sourceDllPath: selectedDllCandidate?.path ?? null,
|
|
8629
|
+
sourceKind: selectedDllCandidate ? selectedDllCandidate.kind : "release-download",
|
|
8630
|
+
targetDllPath,
|
|
8631
|
+
clientDevConfigPath: integration.clientDevConfig.path,
|
|
8632
|
+
clientDevConfigAction,
|
|
8633
|
+
removesLegacyDll: Boolean(recommendedInst?.legacyPluginInstalled),
|
|
8634
|
+
removesMotw: true,
|
|
8635
|
+
requiresElevation,
|
|
8636
|
+
expectedSha256: selectedDllCandidate?.sha256 || expectedSha256
|
|
8637
|
+
}
|
|
8638
|
+
};
|
|
8639
|
+
}
|
|
8640
|
+
async function executeConfirmedPluginInstall(options = {}) {
|
|
8641
|
+
if (options.confirmed !== true) {
|
|
8642
|
+
throw new Error(
|
|
8643
|
+
"Confirmation required: present plannedChanges to the user and pass confirmed: true after explicit approval."
|
|
8644
|
+
);
|
|
8645
|
+
}
|
|
8646
|
+
const integrationBefore = getIntegrationStatus({
|
|
8647
|
+
...options,
|
|
8648
|
+
...options.memoqRoot?.trim() && !options.customInstallDir?.trim() ? { customInstallDir: options.memoqRoot.trim() } : {}
|
|
8649
|
+
});
|
|
8650
|
+
if (integrationBefore.platform !== "win32") {
|
|
8651
|
+
throw new Error(`memoQ plugin installation is only supported on Windows (current: ${integrationBefore.platform}).`);
|
|
8652
|
+
}
|
|
8653
|
+
let targetRoot = options.memoqRoot?.trim() || options.customInstallDir?.trim() || "";
|
|
8654
|
+
if (targetRoot) {
|
|
8655
|
+
const addins = join6(targetRoot, "Addins");
|
|
8656
|
+
if (!existsSync5(addins)) {
|
|
8657
|
+
throw new Error(`memoQ Addins directory was not found: ${addins}`);
|
|
8658
|
+
}
|
|
8659
|
+
} else if (integrationBefore.installations.length === 1) {
|
|
8660
|
+
targetRoot = integrationBefore.installations[0].rootDir;
|
|
8661
|
+
} else if (integrationBefore.installations.length > 1) {
|
|
8662
|
+
throw new Error(
|
|
8663
|
+
`Detected multiple memoQ installations (${integrationBefore.installations.map((i) => i.rootDir).join(", ")}). Please specify memoqRoot explicitly.`
|
|
8664
|
+
);
|
|
8665
|
+
} else {
|
|
8666
|
+
throw new Error("No memoQ installation directory was found (not_found). Please provide memoqRoot.");
|
|
8667
|
+
}
|
|
8668
|
+
const siblingDllPaths = integrationBefore.installations.filter((item) => item.pluginInstalled).map((item) => item.pluginTarget);
|
|
8669
|
+
const sourceAsset = await resolvePluginDllAsset({
|
|
8670
|
+
...options.dataDir === void 0 ? {} : { dataDir: options.dataDir },
|
|
8671
|
+
...options.dllPath === void 0 ? {} : { dllPath: options.dllPath },
|
|
8672
|
+
...options.downloadUrl === void 0 ? {} : { downloadUrl: options.downloadUrl },
|
|
8673
|
+
...options.expectedSha256 === void 0 ? {} : { expectedSha256: options.expectedSha256 },
|
|
8674
|
+
...options.allowDownload === void 0 ? {} : { allowDownload: options.allowDownload },
|
|
8675
|
+
...options.allowUnverifiedLocalDev === void 0 ? {} : { allowUnverifiedLocalDev: options.allowUnverifiedLocalDev },
|
|
8676
|
+
searchPaths: siblingDllPaths,
|
|
8677
|
+
...options.searchDirs === void 0 ? {} : { searchDirs: options.searchDirs },
|
|
8678
|
+
includeDefaultUserDirs: options.includeDefaultUserDirs ?? options.skipHostDiscovery !== true
|
|
8679
|
+
});
|
|
8680
|
+
const effectiveProgramData = options.programDataDir ?? process.env.ProgramData ?? "C:\\ProgramData";
|
|
8681
|
+
const shouldElevate = options.elevate ?? isProtectedWindowsPath(targetRoot, effectiveProgramData);
|
|
8682
|
+
const baseInstallParams = {
|
|
8683
|
+
memoqRoot: targetRoot,
|
|
8684
|
+
dllSource: sourceAsset.path,
|
|
8685
|
+
dllSha256: sourceAsset.sha256,
|
|
8686
|
+
programDataDir: effectiveProgramData,
|
|
8687
|
+
...options.dataDir === void 0 ? {} : { dataDir: options.dataDir },
|
|
8688
|
+
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
8689
|
+
...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath }
|
|
8690
|
+
};
|
|
8691
|
+
let result;
|
|
8692
|
+
try {
|
|
8693
|
+
result = await installPluginWithHelper({
|
|
8694
|
+
...baseInstallParams,
|
|
8695
|
+
elevate: shouldElevate
|
|
8696
|
+
});
|
|
8697
|
+
} catch (error) {
|
|
8698
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
8699
|
+
if (options.elevate === void 0 && !shouldElevate && /access|denied|unauthorized|permission/iu.test(message)) {
|
|
8700
|
+
result = await installPluginWithHelper({
|
|
8701
|
+
...baseInstallParams,
|
|
8702
|
+
elevate: true
|
|
8703
|
+
});
|
|
8704
|
+
} else {
|
|
8705
|
+
throw error;
|
|
8706
|
+
}
|
|
8707
|
+
}
|
|
8708
|
+
const integrationAfter = getIntegrationStatus({
|
|
8709
|
+
...options,
|
|
8710
|
+
customInstallDir: targetRoot
|
|
8711
|
+
});
|
|
8712
|
+
return {
|
|
8713
|
+
ok: true,
|
|
8714
|
+
operation: "copy",
|
|
8715
|
+
preservesOriginalSource: true,
|
|
8716
|
+
sourceAsset,
|
|
8717
|
+
result,
|
|
8718
|
+
integration: integrationAfter,
|
|
8719
|
+
nextSteps: [
|
|
8720
|
+
"\u5B8C\u5168\u5173\u95ED\u5E76\u91CD\u65B0\u542F\u52A8 memoQ\uFF08memoQ \u4EC5\u5728\u542F\u52A8\u65F6\u626B\u63CF Addins \u76EE\u5F55\uFF09\u3002",
|
|
8721
|
+
"\u5728 memoQ \u4E2D\u6253\u5F00 Options \u2192 Default resources \u2192 MT settings\uFF0C\u52FE\u9009\u542F\u7528 memoQ AI Hub\uFF08\u7AEF\u53E3\u4FDD\u6301 5271\uFF09\u3002"
|
|
8722
|
+
]
|
|
8723
|
+
};
|
|
8724
|
+
}
|
|
8725
|
+
async function executeConfirmedPluginUninstall(options = {}) {
|
|
8726
|
+
if (options.confirmed !== true) {
|
|
8727
|
+
throw new Error(
|
|
8728
|
+
"Confirmation required: pass confirmed: true after explicit user approval to uninstall the memoQ plugin."
|
|
8729
|
+
);
|
|
8730
|
+
}
|
|
8731
|
+
const integrationBefore = getIntegrationStatus({
|
|
8732
|
+
...options,
|
|
8733
|
+
...options.memoqRoot?.trim() && !options.customInstallDir?.trim() ? { customInstallDir: options.memoqRoot.trim() } : {}
|
|
8734
|
+
});
|
|
8735
|
+
if (integrationBefore.platform !== "win32") {
|
|
8736
|
+
throw new Error(`memoQ plugin uninstallation is only supported on Windows (current: ${integrationBefore.platform}).`);
|
|
8737
|
+
}
|
|
8738
|
+
let targetRoot = options.memoqRoot?.trim() || options.customInstallDir?.trim() || "";
|
|
8739
|
+
if (!targetRoot) {
|
|
8740
|
+
const installedRoots = integrationBefore.installations.filter((item) => item.pluginInstalled);
|
|
8741
|
+
if (installedRoots.length === 1) {
|
|
8742
|
+
targetRoot = installedRoots[0].rootDir;
|
|
8743
|
+
} else if (integrationBefore.installations.length === 1) {
|
|
8744
|
+
targetRoot = integrationBefore.installations[0].rootDir;
|
|
8745
|
+
} else if (installedRoots.length > 1) {
|
|
8746
|
+
throw new Error(
|
|
8747
|
+
`Detected multiple installed memoQ copies (${installedRoots.map((i) => i.rootDir).join(", ")}). Please specify memoqRoot explicitly.`
|
|
8748
|
+
);
|
|
8749
|
+
} else {
|
|
8750
|
+
throw new Error("No memoQ installation directory was found (not_found). Please provide memoqRoot.");
|
|
8751
|
+
}
|
|
8752
|
+
}
|
|
8753
|
+
const effectiveProgramData = options.programDataDir ?? process.env.ProgramData ?? "C:\\ProgramData";
|
|
8754
|
+
const shouldElevate = options.elevate ?? isProtectedWindowsPath(targetRoot, effectiveProgramData);
|
|
8755
|
+
const result = await uninstallPluginWithHelper({
|
|
8756
|
+
memoqRoot: targetRoot,
|
|
8757
|
+
programDataDir: effectiveProgramData,
|
|
8758
|
+
elevate: shouldElevate,
|
|
8759
|
+
...options.dataDir === void 0 ? {} : { dataDir: options.dataDir },
|
|
8760
|
+
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
8761
|
+
...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath }
|
|
8762
|
+
});
|
|
8763
|
+
const integrationAfter = getIntegrationStatus({
|
|
8764
|
+
...options,
|
|
8765
|
+
customInstallDir: targetRoot
|
|
8766
|
+
});
|
|
8767
|
+
return {
|
|
8768
|
+
ok: true,
|
|
8769
|
+
result,
|
|
8770
|
+
integration: integrationAfter
|
|
8771
|
+
};
|
|
8772
|
+
}
|
|
7490
8773
|
|
|
7491
8774
|
// packages/memoq-bridge/src/setup-page.ts
|
|
7492
8775
|
import { spawn as spawn2 } from "node:child_process";
|
|
7493
|
-
import { randomBytes as
|
|
8776
|
+
import { randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
7494
8777
|
import { existsSync as existsSync7, mkdirSync as mkdirSync5 } from "node:fs";
|
|
7495
8778
|
import { createServer as createServer2 } from "node:http";
|
|
7496
|
-
import { dirname as
|
|
8779
|
+
import { dirname as dirname5 } from "node:path";
|
|
7497
8780
|
|
|
7498
8781
|
// packages/memoq-bridge/src/daemon.ts
|
|
7499
|
-
import {
|
|
8782
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
8783
|
+
import { chmodSync, existsSync as existsSync6, readFileSync as readFileSync6, rmSync as rmSync3 } from "node:fs";
|
|
7500
8784
|
import { join as join7 } from "node:path";
|
|
7501
8785
|
async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeoutMs = 1500) {
|
|
7502
8786
|
const url = `http://${host}:${port}`;
|
|
@@ -7535,6 +8819,31 @@ async function probeGatewayPort(port = DEFAULT_PORT, host = DEFAULT_HOST, timeou
|
|
|
7535
8819
|
};
|
|
7536
8820
|
}
|
|
7537
8821
|
}
|
|
8822
|
+
function loadOrCreateReviewToken(dataDir = defaultBridgeDataDir(), excludeToken) {
|
|
8823
|
+
const tokenPath = join7(dataDir, "review-token.json");
|
|
8824
|
+
if (existsSync6(tokenPath)) {
|
|
8825
|
+
try {
|
|
8826
|
+
const parsed = JSON.parse(readFileSync6(tokenPath, "utf8"));
|
|
8827
|
+
const candidate = typeof parsed?.token === "string" ? parsed.token.trim() : "";
|
|
8828
|
+
if (/^[0-9a-f]{48,}$/iu.test(candidate) && candidate !== excludeToken) {
|
|
8829
|
+
return candidate;
|
|
8830
|
+
}
|
|
8831
|
+
} catch {
|
|
8832
|
+
}
|
|
8833
|
+
}
|
|
8834
|
+
let token = randomBytes2(24).toString("hex");
|
|
8835
|
+
while (token === excludeToken) {
|
|
8836
|
+
token = randomBytes2(24).toString("hex");
|
|
8837
|
+
}
|
|
8838
|
+
atomicWriteTextSync(tokenPath, JSON.stringify({ token }, null, 2));
|
|
8839
|
+
if (process.platform !== "win32") {
|
|
8840
|
+
try {
|
|
8841
|
+
chmodSync(tokenPath, 384);
|
|
8842
|
+
} catch {
|
|
8843
|
+
}
|
|
8844
|
+
}
|
|
8845
|
+
return token;
|
|
8846
|
+
}
|
|
7538
8847
|
function getDaemonRecordPath(dataDir = defaultBridgeDataDir()) {
|
|
7539
8848
|
return join7(dataDir, "daemon.json");
|
|
7540
8849
|
}
|
|
@@ -7718,10 +9027,13 @@ async function startBridgeRuntime(options = {}) {
|
|
|
7718
9027
|
...options.packageRoot === void 0 ? {} : { packageRoot: options.packageRoot },
|
|
7719
9028
|
...options.helperExecutablePath === void 0 ? {} : { helperExecutablePath: options.helperExecutablePath }
|
|
7720
9029
|
}));
|
|
9030
|
+
const shouldWriteDaemon = options.writeDaemonFile !== false;
|
|
9031
|
+
const persistedReviewToken = options.reviewToken ?? (shouldWriteDaemon ? loadOrCreateReviewToken(dataDir) : void 0);
|
|
7721
9032
|
const gateway = await createMtGateway({
|
|
7722
9033
|
host,
|
|
7723
9034
|
port: bindPort,
|
|
7724
9035
|
mode: options.mode ?? "staging",
|
|
9036
|
+
...persistedReviewToken ? { reviewToken: persistedReviewToken } : {},
|
|
7725
9037
|
stagingStore,
|
|
7726
9038
|
previewClient,
|
|
7727
9039
|
getIntegrationStatus: integrationFn,
|
|
@@ -7730,7 +9042,6 @@ async function startBridgeRuntime(options = {}) {
|
|
|
7730
9042
|
...options.getLiveConfig === void 0 ? {} : { getLiveConfig: options.getLiveConfig },
|
|
7731
9043
|
...options.updateLiveConfig === void 0 ? {} : { updateLiveConfig: options.updateLiveConfig }
|
|
7732
9044
|
});
|
|
7733
|
-
const shouldWriteDaemon = options.writeDaemonFile !== false;
|
|
7734
9045
|
if (shouldWriteDaemon) {
|
|
7735
9046
|
writeDaemonRecord(
|
|
7736
9047
|
{
|
|
@@ -7859,6 +9170,11 @@ function renderSetupHtml(nonce, token, initialStatus) {
|
|
|
7859
9170
|
<label for="custom-dir" style="font-size: 13px; color: var(--muted);">\u6216\u8F93\u5165\u81EA\u5B9A\u4E49 memoQ \u6839\u76EE\u5F55\uFF08\u5305\u542B Addins \u5B50\u76EE\u5F55\uFF09\uFF1A</label>
|
|
7860
9171
|
<input id="custom-dir" type="text" placeholder="\u4F8B\u5982 C:\\Program Files\\memoQ\\memoQ-12" />
|
|
7861
9172
|
</div>
|
|
9173
|
+
<div style="margin-top: 10px;">
|
|
9174
|
+
<label for="custom-dll" style="font-size: 13px; color: var(--muted);">\u53EF\u9009\uFF1A\u6307\u5B9A\u672C\u5730 DLL \u6216 ZIP \u8DEF\u5F84\uFF08\u7559\u7A7A\u5219\u81EA\u52A8\u67E5\u627E\u6216\u4ECE Release \u4E0B\u8F7D\uFF09\uFF1A</label>
|
|
9175
|
+
<input id="custom-dll" type="text" placeholder="\u4F8B\u5982 C:\\Users\\...\\Downloads\\MemoQ.AI.Hub.Plugin.dll" />
|
|
9176
|
+
<div id="discovered-dlls" style="font-size: 12px; color: var(--muted); margin-top: 6px;"></div>
|
|
9177
|
+
</div>
|
|
7862
9178
|
</section>
|
|
7863
9179
|
|
|
7864
9180
|
<section class="card">
|
|
@@ -7948,6 +9264,25 @@ function renderSetupHtml(nonce, token, initialStatus) {
|
|
|
7948
9264
|
el.addEventListener("change", function (ev) { selectedRoot = ev.target.value; });
|
|
7949
9265
|
});
|
|
7950
9266
|
}
|
|
9267
|
+
|
|
9268
|
+
const dllsEl = document.getElementById("discovered-dlls");
|
|
9269
|
+
const dllList = state.discoveredDlls || [];
|
|
9270
|
+
if (dllsEl) {
|
|
9271
|
+
if (!dllList.length) {
|
|
9272
|
+
dllsEl.textContent = "\u672A\u5728\u672C\u673A\u5E38\u7528\u76EE\u5F55\u9884\u53D1\u73B0 DLL\uFF1B\u70B9\u51FB\u5B89\u88C5\u65F6\u5C06\u6309\u9700\u4ECE\u5B89\u5168 Release \u62C9\u53D6\u5E76\u6821\u9A8C SHA-256\u3002";
|
|
9273
|
+
} else {
|
|
9274
|
+
dllsEl.innerHTML = "\u672C\u673A\u5DF2\u53D1\u73B0\u53EF\u7528\u5305\uFF08\u70B9\u51FB\u53EF\u586B\u5165\u8DEF\u5F84\uFF09\uFF1A" + dllList.slice(0, 4).map(function (c, i) {
|
|
9275
|
+
const ok = c.sha256MatchesExpected ? "\u2705" : "\u26A0\uFE0F";
|
|
9276
|
+
return '<button type="button" class="pick-dll" data-idx="' + i + '" style="margin:4px 6px 0 0;padding:3px 8px;font-size:12px;">' + ok + " " + c.path.replace(/</g, "<") + "</button>";
|
|
9277
|
+
}).join("");
|
|
9278
|
+
dllsEl.querySelectorAll(".pick-dll").forEach(function (btn) {
|
|
9279
|
+
btn.addEventListener("click", function () {
|
|
9280
|
+
const item = dllList[Number(btn.getAttribute("data-idx"))];
|
|
9281
|
+
if (item) document.getElementById("custom-dll").value = item.path;
|
|
9282
|
+
});
|
|
9283
|
+
});
|
|
9284
|
+
}
|
|
9285
|
+
}
|
|
7951
9286
|
}
|
|
7952
9287
|
|
|
7953
9288
|
function showMessage(text, isError) {
|
|
@@ -7991,11 +9326,13 @@ function renderSetupHtml(nonce, token, initialStatus) {
|
|
|
7991
9326
|
document.getElementById("btn-install").addEventListener("click", async function () {
|
|
7992
9327
|
const root = effectiveRoot();
|
|
7993
9328
|
if (!root) { showMessage("\u8BF7\u5148\u9009\u62E9\u6216\u8F93\u5165 memoQ \u5B89\u88C5\u76EE\u5F55\u3002", true); return; }
|
|
9329
|
+
const dllPath = (document.getElementById("custom-dll").value || "").trim();
|
|
7994
9330
|
const btn = document.getElementById("btn-install");
|
|
7995
9331
|
btn.disabled = true;
|
|
7996
9332
|
showMessage("\u6B63\u5728\u51C6\u5907 DLL \u5E76\u7B49\u5F85\u7CFB\u7EDF UAC \u786E\u8BA4\u2026", false);
|
|
7997
9333
|
try {
|
|
7998
|
-
const
|
|
9334
|
+
const payload = dllPath ? { memoqRoot: root, dllPath: dllPath } : { memoqRoot: root };
|
|
9335
|
+
const res = await api("/api/install", "POST", payload);
|
|
7999
9336
|
render(res.status);
|
|
8000
9337
|
showMessage("\u5B89\u88C5\u6210\u529F\uFF01DLL \u6821\u9A8C\u503C " + res.result.dllSha256 + "\u3002\u8BF7\u91CD\u542F memoQ \u5E76\u5728 MT settings \u4E2D\u542F\u7528\u3002", false);
|
|
8001
9338
|
} catch (e) { showMessage("\u5B89\u88C5\u5931\u8D25\uFF1A" + e.message, true); }
|
|
@@ -8023,7 +9360,7 @@ function renderSetupHtml(nonce, token, initialStatus) {
|
|
|
8023
9360
|
async function startSetupServer(options = {}) {
|
|
8024
9361
|
const host = options.host ?? DEFAULT_HOST;
|
|
8025
9362
|
const requestedPort = options.port ?? 0;
|
|
8026
|
-
const token =
|
|
9363
|
+
const token = randomBytes3(24).toString("hex");
|
|
8027
9364
|
const gatewayPort = options.gatewayPort ?? DEFAULT_PORT;
|
|
8028
9365
|
const probeGateway = options.probeGateway ?? ((p) => probeGatewayPort(p ?? gatewayPort));
|
|
8029
9366
|
const resolveDll = options.resolveDll ?? resolvePluginDllAsset;
|
|
@@ -8042,7 +9379,13 @@ async function startSetupServer(options = {}) {
|
|
|
8042
9379
|
Promise.resolve(getIntegrationStatus(detectOpts)),
|
|
8043
9380
|
probeGateway(gatewayPort)
|
|
8044
9381
|
]);
|
|
8045
|
-
|
|
9382
|
+
const discoveredDlls = discoverLocalPluginDllCandidates({
|
|
9383
|
+
dataDir,
|
|
9384
|
+
...options.detectOptions?.expectedSha256 === void 0 ? {} : { expectedSha256: options.detectOptions.expectedSha256 },
|
|
9385
|
+
extraFilePaths: integration.installations.filter((i) => i.pluginInstalled).map((i) => i.pluginTarget),
|
|
9386
|
+
includeDefaultUserDirs: options.detectOptions?.skipHostDiscovery ? false : true
|
|
9387
|
+
});
|
|
9388
|
+
return { integration, gateway, discoveredDlls };
|
|
8046
9389
|
}
|
|
8047
9390
|
let idleTimer;
|
|
8048
9391
|
const server = createServer2((request, response) => {
|
|
@@ -8062,7 +9405,7 @@ async function startSetupServer(options = {}) {
|
|
|
8062
9405
|
return;
|
|
8063
9406
|
}
|
|
8064
9407
|
if (method === "GET" && (url.pathname === "/" || url.pathname === "/setup")) {
|
|
8065
|
-
const nonce =
|
|
9408
|
+
const nonce = randomBytes3(16).toString("base64");
|
|
8066
9409
|
response.setHeader(
|
|
8067
9410
|
"Content-Security-Policy",
|
|
8068
9411
|
`default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none';`
|
|
@@ -8083,12 +9426,14 @@ async function startSetupServer(options = {}) {
|
|
|
8083
9426
|
const body = await readJson(request);
|
|
8084
9427
|
if (url.pathname === "/api/install") {
|
|
8085
9428
|
const memoqRoot = String(body.memoqRoot ?? "").trim();
|
|
9429
|
+
const dllPath = typeof body.dllPath === "string" ? body.dllPath.trim() : "";
|
|
8086
9430
|
if (!memoqRoot) {
|
|
8087
9431
|
sendJson2(response, 400, { error: "memoqRoot \u4E0D\u80FD\u4E3A\u7A7A\u3002" });
|
|
8088
9432
|
return;
|
|
8089
9433
|
}
|
|
8090
9434
|
const resolvedAsset = await resolveDll({
|
|
8091
9435
|
dataDir,
|
|
9436
|
+
...dllPath ? { dllPath } : {},
|
|
8092
9437
|
...options.allowDownload === void 0 ? {} : { allowDownload: options.allowDownload },
|
|
8093
9438
|
...options.detectOptions?.expectedSha256 === void 0 ? {} : { expectedSha256: options.detectOptions.expectedSha256 }
|
|
8094
9439
|
});
|
|
@@ -8127,7 +9472,7 @@ async function startSetupServer(options = {}) {
|
|
|
8127
9472
|
return;
|
|
8128
9473
|
}
|
|
8129
9474
|
if (url.pathname === "/api/open-asset-dir") {
|
|
8130
|
-
const dir =
|
|
9475
|
+
const dir = dirname5(getPluginAssetCachePath(dataDir, DEFAULT_PLUGIN_DLL_MANIFEST.version));
|
|
8131
9476
|
mkdirSync5(dir, { recursive: true });
|
|
8132
9477
|
if (options.allowOpenFolder !== false && process.platform === "win32" && existsSync7(dir)) {
|
|
8133
9478
|
const child = spawn2("explorer.exe", [dir], { detached: true, windowsHide: true, stdio: "ignore" });
|
|
@@ -8141,14 +9486,14 @@ async function startSetupServer(options = {}) {
|
|
|
8141
9486
|
sendJson2(response, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
8142
9487
|
});
|
|
8143
9488
|
});
|
|
8144
|
-
await new Promise((
|
|
9489
|
+
await new Promise((resolve7, reject) => {
|
|
8145
9490
|
const onError = (error) => {
|
|
8146
9491
|
server.off("listening", onListening);
|
|
8147
9492
|
reject(error);
|
|
8148
9493
|
};
|
|
8149
9494
|
const onListening = () => {
|
|
8150
9495
|
server.off("error", onError);
|
|
8151
|
-
|
|
9496
|
+
resolve7();
|
|
8152
9497
|
};
|
|
8153
9498
|
server.once("error", onError);
|
|
8154
9499
|
server.once("listening", onListening);
|
|
@@ -8161,11 +9506,11 @@ async function startSetupServer(options = {}) {
|
|
|
8161
9506
|
actualPort = addr.port;
|
|
8162
9507
|
expectedHost = `${host}:${actualPort}`;
|
|
8163
9508
|
expectedOrigin = `http://${expectedHost}`;
|
|
8164
|
-
const close = () => new Promise((
|
|
9509
|
+
const close = () => new Promise((resolve7) => {
|
|
8165
9510
|
clearTimeout(idleTimer);
|
|
8166
9511
|
server.close(() => {
|
|
8167
9512
|
options.onClose?.();
|
|
8168
|
-
|
|
9513
|
+
resolve7();
|
|
8169
9514
|
});
|
|
8170
9515
|
});
|
|
8171
9516
|
idleTimer = setTimeout(() => {
|
|
@@ -8300,8 +9645,8 @@ async function completeWithDshLlm(options) {
|
|
|
8300
9645
|
}
|
|
8301
9646
|
|
|
8302
9647
|
// packages/dsh-memoq/src/project-assets.ts
|
|
8303
|
-
import { existsSync as existsSync8, readFileSync as readFileSync7, statSync as
|
|
8304
|
-
import { dirname as
|
|
9648
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7, statSync as statSync3 } from "node:fs";
|
|
9649
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join8, resolve as resolve5 } from "node:path";
|
|
8305
9650
|
var MANIFEST_DIR = ".langlink";
|
|
8306
9651
|
var MANIFEST_FILE = "manifest.json";
|
|
8307
9652
|
var assetCache = /* @__PURE__ */ new Map();
|
|
@@ -8309,13 +9654,13 @@ function clearProjectAssetCache() {
|
|
|
8309
9654
|
assetCache.clear();
|
|
8310
9655
|
}
|
|
8311
9656
|
function findManifestPath2(startDir) {
|
|
8312
|
-
let cursor =
|
|
9657
|
+
let cursor = resolve5(startDir?.trim() || process.cwd());
|
|
8313
9658
|
for (let depth = 0; depth < 32; depth += 1) {
|
|
8314
9659
|
const candidate = join8(cursor, MANIFEST_DIR, MANIFEST_FILE);
|
|
8315
9660
|
if (existsSync8(candidate)) {
|
|
8316
9661
|
return candidate;
|
|
8317
9662
|
}
|
|
8318
|
-
const parent =
|
|
9663
|
+
const parent = dirname6(cursor);
|
|
8319
9664
|
if (parent === cursor) break;
|
|
8320
9665
|
cursor = parent;
|
|
8321
9666
|
}
|
|
@@ -8342,7 +9687,7 @@ function loadProjectAssets(startDir) {
|
|
|
8342
9687
|
}
|
|
8343
9688
|
let mtimeMs = 0;
|
|
8344
9689
|
try {
|
|
8345
|
-
mtimeMs =
|
|
9690
|
+
mtimeMs = statSync3(manifestPath).mtimeMs;
|
|
8346
9691
|
} catch {
|
|
8347
9692
|
return emptyLoadedAssets([`Unable to stat project manifest: ${manifestPath}`]);
|
|
8348
9693
|
}
|
|
@@ -8357,14 +9702,14 @@ function loadProjectAssets(startDir) {
|
|
|
8357
9702
|
const msg = error instanceof Error ? error.message : String(error);
|
|
8358
9703
|
return emptyLoadedAssets([`Failed to parse ${manifestPath}: ${msg}`]);
|
|
8359
9704
|
}
|
|
8360
|
-
const root =
|
|
9705
|
+
const root = dirname6(dirname6(manifestPath));
|
|
8361
9706
|
const warnings = [];
|
|
8362
9707
|
const rawTm = [];
|
|
8363
9708
|
const glossary = [];
|
|
8364
9709
|
const assets = [...manifest.assets ?? []].filter((asset) => asset && asset.enabled !== false && typeof asset.path === "string" && asset.path.trim() !== "").sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
|
|
8365
9710
|
for (const asset of assets) {
|
|
8366
9711
|
const relOrAbs = asset.path.trim();
|
|
8367
|
-
const absPath = isAbsolute2(relOrAbs) ? relOrAbs :
|
|
9712
|
+
const absPath = isAbsolute2(relOrAbs) ? relOrAbs : resolve5(root, relOrAbs);
|
|
8368
9713
|
if (!existsSync8(absPath)) {
|
|
8369
9714
|
warnings.push(`Missing project asset: ${relOrAbs}`);
|
|
8370
9715
|
continue;
|
|
@@ -9181,26 +10526,115 @@ function createDshMemoqTools(ctx, controller) {
|
|
|
9181
10526
|
});
|
|
9182
10527
|
const setupTool = defineTool({
|
|
9183
10528
|
name: "memoq_setup",
|
|
9184
|
-
description: "
|
|
10529
|
+
description: "Auto-discover memoQ Desktop installations and local MemoQ.AI.Hub.Plugin.dll / .zip packages (action='plan', read-only), present exact copy targets & SHA-256 for user confirmation, and execute verified helper copy + ClientDevConfig.xml merge once confirmed=true (with local visual wizard fallback).",
|
|
9185
10530
|
parameters: {
|
|
9186
|
-
|
|
10531
|
+
action: {
|
|
10532
|
+
type: "string",
|
|
10533
|
+
enum: ["plan", "install", "uninstall"],
|
|
10534
|
+
description: "Mode: 'plan' (default, read-only), 'install' (requires confirmed=true), or 'uninstall' (requires confirmed=true)."
|
|
10535
|
+
},
|
|
10536
|
+
customInstallDir: { type: "string", description: "Optional custom memoQ installation directory to inspect." },
|
|
10537
|
+
memoqRoot: { type: "string", description: "Target memoQ root directory for install/uninstall." },
|
|
10538
|
+
dllPath: { type: "string", description: "Optional local path to MemoQ.AI.Hub.Plugin.dll or release .zip package." },
|
|
10539
|
+
searchDirs: {
|
|
10540
|
+
type: "array",
|
|
10541
|
+
items: { type: "string" },
|
|
10542
|
+
description: "Optional extra local directories to scan for DLL/ZIP packages."
|
|
10543
|
+
},
|
|
10544
|
+
confirmed: { type: "boolean", description: "Must be true only after the user explicitly confirms plannedChanges in chat." },
|
|
10545
|
+
openWizard: { type: "boolean", description: "Whether to also launch the local setup web UI in 'plan' mode (default true)." }
|
|
9187
10546
|
},
|
|
9188
10547
|
output: asTextOutput(),
|
|
9189
10548
|
async execute(args) {
|
|
10549
|
+
const effectiveAction = args.action === "install" || args.action === "uninstall" ? args.action : "plan";
|
|
10550
|
+
const customInstallDir = typeof args.customInstallDir === "string" ? args.customInstallDir : void 0;
|
|
10551
|
+
const memoqRoot = typeof args.memoqRoot === "string" ? args.memoqRoot : void 0;
|
|
10552
|
+
const dllPath = typeof args.dllPath === "string" ? args.dllPath : void 0;
|
|
10553
|
+
const searchDirs = Array.isArray(args.searchDirs) ? args.searchDirs.filter((v) => typeof v === "string") : void 0;
|
|
10554
|
+
const confirmed = args.confirmed === true;
|
|
10555
|
+
const openWizard = args.openWizard !== false;
|
|
10556
|
+
const targetCustomDir = customInstallDir ?? memoqRoot;
|
|
10557
|
+
const planFn = controller.buildInstallPlan ?? buildPluginInstallPlan;
|
|
10558
|
+
const installFn = controller.installPlugin ?? executeConfirmedPluginInstall;
|
|
10559
|
+
const uninstallFn = controller.uninstallPlugin ?? executeConfirmedPluginUninstall;
|
|
10560
|
+
if (effectiveAction === "install") {
|
|
10561
|
+
if (!confirmed) {
|
|
10562
|
+
const plan2 = planFn({
|
|
10563
|
+
packageRoot: controller.getPackageRoot(),
|
|
10564
|
+
dataDir: controller.getDataDir(),
|
|
10565
|
+
...targetCustomDir === void 0 ? {} : { customInstallDir: targetCustomDir },
|
|
10566
|
+
...dllPath === void 0 ? {} : { dllPath },
|
|
10567
|
+
...searchDirs === void 0 ? {} : { searchDirs }
|
|
10568
|
+
});
|
|
10569
|
+
return JSON.stringify({
|
|
10570
|
+
action: "install",
|
|
10571
|
+
installed: false,
|
|
10572
|
+
confirmationRequired: true,
|
|
10573
|
+
plan: plan2,
|
|
10574
|
+
error: "\u5FC5\u987B\u5148\u5411\u7528\u6237\u5C55\u793A\u62DF\u53D8\u66F4\u6E05\u5355\uFF08plan.plannedChanges\uFF1A\u6E90 DLL\u3001\u76EE\u6807 Addins \u590D\u5236\u8DEF\u5F84\u3001ClientDevConfig.xml \u53CA\u662F\u5426\u89E6\u53D1 UAC\uFF09\uFF0C\u5E76\u5728\u7528\u6237\u660E\u786E\u786E\u8BA4\u540E\u518D\u4F20 confirmed: true \u6267\u884C\u5B89\u88C5\u3002"
|
|
10575
|
+
});
|
|
10576
|
+
}
|
|
10577
|
+
const installResult = await installFn({
|
|
10578
|
+
packageRoot: controller.getPackageRoot(),
|
|
10579
|
+
dataDir: controller.getDataDir(),
|
|
10580
|
+
...customInstallDir === void 0 ? {} : { customInstallDir },
|
|
10581
|
+
...memoqRoot === void 0 ? {} : { memoqRoot },
|
|
10582
|
+
...dllPath === void 0 ? {} : { dllPath },
|
|
10583
|
+
...searchDirs === void 0 ? {} : { searchDirs },
|
|
10584
|
+
confirmed: true
|
|
10585
|
+
});
|
|
10586
|
+
return JSON.stringify({
|
|
10587
|
+
action: "install",
|
|
10588
|
+
installed: true,
|
|
10589
|
+
...installResult
|
|
10590
|
+
});
|
|
10591
|
+
}
|
|
10592
|
+
if (effectiveAction === "uninstall") {
|
|
10593
|
+
if (!confirmed) {
|
|
10594
|
+
return JSON.stringify({
|
|
10595
|
+
action: "uninstall",
|
|
10596
|
+
uninstalled: false,
|
|
10597
|
+
confirmationRequired: true,
|
|
10598
|
+
error: "\u5FC5\u987B\u5148\u83B7\u7528\u6237\u660E\u786E\u786E\u8BA4\u540E\u518D\u4F20 confirmed: true \u624D\u80FD\u5378\u8F7D memoQ \u63D2\u4EF6\u3002"
|
|
10599
|
+
});
|
|
10600
|
+
}
|
|
10601
|
+
const uninstallResult = await uninstallFn({
|
|
10602
|
+
packageRoot: controller.getPackageRoot(),
|
|
10603
|
+
dataDir: controller.getDataDir(),
|
|
10604
|
+
...customInstallDir === void 0 ? {} : { customInstallDir },
|
|
10605
|
+
...memoqRoot === void 0 ? {} : { memoqRoot },
|
|
10606
|
+
confirmed: true
|
|
10607
|
+
});
|
|
10608
|
+
return JSON.stringify({
|
|
10609
|
+
action: "uninstall",
|
|
10610
|
+
uninstalled: true,
|
|
10611
|
+
...uninstallResult
|
|
10612
|
+
});
|
|
10613
|
+
}
|
|
9190
10614
|
const integration = getIntegrationStatus({
|
|
9191
10615
|
packageRoot: controller.getPackageRoot(),
|
|
9192
10616
|
dataDir: controller.getDataDir(),
|
|
9193
|
-
...
|
|
10617
|
+
...targetCustomDir === void 0 ? {} : { customInstallDir: targetCustomDir }
|
|
10618
|
+
});
|
|
10619
|
+
const plan = planFn({
|
|
10620
|
+
packageRoot: controller.getPackageRoot(),
|
|
10621
|
+
dataDir: controller.getDataDir(),
|
|
10622
|
+
...targetCustomDir === void 0 ? {} : { customInstallDir: targetCustomDir },
|
|
10623
|
+
...dllPath === void 0 ? {} : { dllPath },
|
|
10624
|
+
...searchDirs === void 0 ? {} : { searchDirs }
|
|
9194
10625
|
});
|
|
9195
10626
|
const probePort = controller.getPreferredPort() || DEFAULT_PORT;
|
|
9196
10627
|
const probe = await probeGatewayPort(probePort);
|
|
9197
|
-
const url = await controller.ensureSetupUrl(
|
|
10628
|
+
const url = openWizard ? await controller.ensureSetupUrl(targetCustomDir) : "";
|
|
9198
10629
|
return JSON.stringify({
|
|
9199
|
-
|
|
9200
|
-
link: `[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})
|
|
10630
|
+
action: "plan",
|
|
10631
|
+
...url ? { url, link: `[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` } : {},
|
|
9201
10632
|
integration,
|
|
10633
|
+
plan,
|
|
9202
10634
|
gateway: probe,
|
|
9203
|
-
|
|
10635
|
+
confirmationRequired: true,
|
|
10636
|
+
nextStep: integration.canReuseExisting ? "\u68C0\u6D4B\u5230\u5DF2\u5B89\u88C5\u7684\u517C\u5BB9\u63D2\u4EF6\u53EF\u76F4\u63A5\u590D\u7528\u3002\u5982\u9700\u4FEE\u590D\u6216\u5B89\u88C5\u5230\u5176\u4ED6\u7248\u672C\uFF0C\u8BF7\u5411\u7528\u6237\u5C55\u793A plan.plannedChanges \u5E76\u83B7\u660E\u786E\u786E\u8BA4\u540E\u8C03\u7528 memoq_setup({ action: 'install', confirmed: true, memoqRoot, dllPath })\u3002" : plan.readyToInstall ? "\u5DF2\u5B9A\u4F4D\u76EE\u6807 memoQ \u76EE\u5F55\u4E0E\u6E90 DLL\u3002\u8BF7\u5148\u5728\u5BF9\u8BDD\u4E2D\u5217\u51FA plan.plannedChanges\uFF08\u6E90\u8DEF\u5F84\u3001\u590D\u5236\u76EE\u6807\u8DEF\u5F84\u3001SHA-256\u3001ClientDevConfig.xml \u5907\u4EFD\u5408\u5E76\u8BA1\u5212\u3001\u662F\u5426\u5F39 UAC\uFF09\uFF0C\u7B49\u7528\u6237\u786E\u8BA4\u540E\u518D\u8C03\u7528 memoq_setup({ action: 'install', confirmed: true, memoqRoot: plan.recommendedMemoqRoot, dllPath: plan.plannedChanges.sourceDllPath })\u3002" : `\u5C1A\u672A\u5C31\u7EEA\uFF1A${plan.blockers.join("\uFF1B")}\u3002\u8BF7\u5411\u7528\u6237\u786E\u8BA4 memoQ \u76EE\u5F55 (customInstallDir) \u6216\u672C\u5730 DLL/ZIP \u8DEF\u5F84 (dllPath)\uFF0C\u6216\u4F7F\u7528\u672C\u5730\u53EF\u89C6\u5316\u5411\u5BFC\u3002`,
|
|
10637
|
+
message: integration.canReuseExisting ? `\u68C0\u6D4B\u5230\u5DF2\u5B89\u88C5\u7684 memoQ \u63D2\u4EF6\u53EF\u76F4\u63A5\u590D\u7528\u3002${url ? `\u5982\u9700\u67E5\u770B\u8BE6\u60C5\u6216\u4FEE\u590D\uFF0C\u8BF7\u6253\u5F00\uFF1A[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` : ""}` : plan.readyToInstall ? `\u5DF2\u627E\u5230\u5B89\u88C5\u8DEF\u5F84\u4E0E\u63D2\u4EF6\u6587\u4EF6\uFF08\u5C06\u590D\u5236\u5E76\u4FDD\u7559\u539F\u4EF6\uFF09\u3002\u8BF7\u5728\u4E0E\u7528\u6237\u786E\u8BA4\u5177\u4F53\u53D8\u66F4\u8DEF\u5F84\u540E\u8C03\u7528 memoq_setup({ action: "install", confirmed: true, ... }) \u5B8C\u6210\u5B89\u88C5${url ? `\uFF0C\u6216\u6253\u5F00\u53EF\u89C6\u5316\u5411\u5BFC\uFF1A[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` : ""}\u3002` : `\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00\u672C\u5730\u8BBE\u7F6E\u5411\u5BFC\u67E5\u770B\u5C06\u8981\u5199\u5165\u7684 2 \u4E2A\u8DEF\u5F84\u5E76\u70B9\u51FB\u5B89\u88C5${url ? `\uFF1A[\u6253\u5F00 memoQ \u8FDE\u63A5\u5668\u5B89\u88C5\u4E0E\u8BCA\u65AD\u5411\u5BFC](${url})` : ""}`
|
|
9204
10638
|
});
|
|
9205
10639
|
}
|
|
9206
10640
|
});
|
|
@@ -9306,9 +10740,9 @@ var DEFAULT_LIVE_CONFIG = {
|
|
|
9306
10740
|
concurrency: 2
|
|
9307
10741
|
};
|
|
9308
10742
|
function resolvePluginPackageRoot(configuredRoot) {
|
|
9309
|
-
if (configuredRoot) return
|
|
9310
|
-
const here =
|
|
9311
|
-
const candidateParent =
|
|
10743
|
+
if (configuredRoot) return resolve6(configuredRoot);
|
|
10744
|
+
const here = dirname7(fileURLToPath2(import.meta.url));
|
|
10745
|
+
const candidateParent = resolve6(here, "..");
|
|
9312
10746
|
if (existsSync9(join9(candidateParent, "bin", "MemoQ.Bridge.Helper.exe"))) {
|
|
9313
10747
|
return candidateParent;
|
|
9314
10748
|
}
|
|
@@ -9374,7 +10808,7 @@ function sanitizeLiveConfigPatch(current, patch) {
|
|
|
9374
10808
|
return next;
|
|
9375
10809
|
}
|
|
9376
10810
|
function persistLiveConfig(configPath, config) {
|
|
9377
|
-
mkdirSync6(
|
|
10811
|
+
mkdirSync6(dirname7(configPath), { recursive: true });
|
|
9378
10812
|
const temp = `${configPath}.${process.pid}.${Date.now()}.tmp`;
|
|
9379
10813
|
writeFileSync4(temp, JSON.stringify(config, null, 2), "utf8");
|
|
9380
10814
|
renameSync3(temp, configPath);
|