@2kog/kacha 0.1.1 → 0.2.0

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.
@@ -0,0 +1,486 @@
1
+ <script>
2
+ import { h } from 'vue'
3
+ import { ElCheckbox, ElNotification, ElProgress, ElRadioButton, ElRadioGroup } from 'element-plus'
4
+ import 'element-plus/es/components/checkbox/style/css'
5
+ import 'element-plus/es/components/progress/style/css'
6
+ import 'element-plus/es/components/radio-button/style/css'
7
+ import 'element-plus/es/components/radio-group/style/css'
8
+ import 'element-plus/es/components/notification/style/css'
9
+ import { CircleAlert, CircleCheck, CloudDownload, CloudUpload, LoaderCircle, RefreshCw, X } from 'lucide-vue-next'
10
+
11
+ const endpoint = '/api/project-oss-sync'
12
+ const settingsErrors = ['OSS_NOT_CONFIGURED', 'OSS_INVALID_CONFIG']
13
+ const fileErrors = {
14
+ OSS_SYNC_FILE_CHANGED: '文件在同步期间发生变化',
15
+ OSS_SYNC_FILE_UNREADABLE: '无法读取文件',
16
+ OSS_SYNC_UPLOAD_FAILED: '文件上传失败',
17
+ OSS_SYNC_DOWNLOAD_FAILED: '文件下载失败',
18
+ OSS_SYNC_HASH_MISMATCH: '下载文件校验失败',
19
+ OSS_SYNC_REMOVE_FAILED: '无法移除文件',
20
+ }
21
+ const syncErrors = {
22
+ OSS_SYNC_BUSY: '另一个工作台实例正在同步',
23
+ OSS_SYNC_SCAN_FAILED: '无法扫描项目文件',
24
+ OSS_SYNC_STATE_FAILED: '无法保存同步进度',
25
+ OSS_COLLAB_PREVIEW_STALE: '项目或云端版本已变化,请重新预览',
26
+ OSS_COLLAB_RESOLUTION_REQUIRED: '请选择每个冲突文件的处理方式',
27
+ OSS_COLLAB_DELETE_CONFIRMATION_REQUIRED: '请确认本次移除操作',
28
+ OSS_COLLAB_PROJECT_MISMATCH: '本地项目与云端项目不一致',
29
+ OSS_COLLAB_REMOTE_CHANGED: '同事已发布新版本,请重新预览',
30
+ OSS_COLLAB_REMOTE_INVALID: '云端项目清单无效',
31
+ OSS_COLLAB_REMOTE_IO: '无法读取或写入云端项目',
32
+ OSS_COLLAB_LEGACY_LOCAL_REQUIRED: '需要原项目文件才能迁移旧版备份',
33
+ OSS_SYNC_BASELINE_INVALID: '本地同步清单无效',
34
+ OSS_COLLAB_EMPTY_PROJECT: '当前项目没有可同步的文件',
35
+ OSS_COLLAB_PATH_COLLISION: '本地和云端存在冲突路径,请调整文件名后重新预览',
36
+ OSS_SYNC_FILE_CHANGED: '文件在同步期间发生变化',
37
+ OSS_SYNC_FILE_UNREADABLE: '无法读取文件',
38
+ }
39
+
40
+ export default {
41
+ components: {
42
+ CircleAlert, CircleCheck, CloudDownload, CloudUpload, ElCheckbox, ElProgress, ElRadioButton,
43
+ ElRadioGroup, LoaderCircle, RefreshCw, X,
44
+ },
45
+ emits: ['configure-storage'],
46
+ data() {
47
+ return {
48
+ status: { state: 'idle' },
49
+ fileErrors,
50
+ starting: false,
51
+ connectionError: false,
52
+ timer: null,
53
+ request: null,
54
+ notificationTarget: 'body',
55
+ modalObserver: null,
56
+ failureReport: null,
57
+ plan: null,
58
+ planRequest: null,
59
+ planLoading: false,
60
+ planError: '',
61
+ resolutions: Object.create(null),
62
+ confirmDeletes: false,
63
+ }
64
+ },
65
+ computed: {
66
+ running() {
67
+ return this.starting || this.status.state === 'running'
68
+ },
69
+ showTopbarCount() {
70
+ return this.running && !this.starting && this.status.total > 0
71
+ },
72
+ triggerLabel() {
73
+ if (!this.running) return this.$t('同步到 OSS')
74
+ if (!this.showTopbarCount) return this.$t(this.statusLabel)
75
+ return this.$t('已处理 {count} / {total} 个文件', {
76
+ count: this.counts.processed,
77
+ total: this.status.total,
78
+ })
79
+ },
80
+ configRequired() {
81
+ return settingsErrors.includes(this.planError) ||
82
+ (!this.plan && !this.planLoading && settingsErrors.includes(this.status.error))
83
+ },
84
+ target() {
85
+ return this.running ? this.status.target : (this.plan?.target || this.status.target)
86
+ },
87
+ counts() {
88
+ const { uploaded = 0, downloaded = 0, removed = 0, skipped = 0, failed = 0 } = this.status
89
+ return { uploaded, downloaded, removed, skipped, failed, processed: uploaded + downloaded + removed + skipped + failed }
90
+ },
91
+ resultStats() {
92
+ const { uploaded, downloaded, removed, skipped, failed } = this.counts
93
+ return [
94
+ { label: '已上传', count: uploaded },
95
+ { label: '已下载', count: downloaded },
96
+ { label: '已移除', count: removed },
97
+ { label: '已跳过', count: skipped },
98
+ { label: '失败', count: failed },
99
+ ]
100
+ },
101
+ percentage() {
102
+ if (this.status.state === 'completed') return 100
103
+ const { currentPercent = 0, total = 0 } = this.status
104
+ if (!total) return 0
105
+ return Math.min(100, Math.floor((this.counts.processed + currentPercent / 100) / total * 100))
106
+ },
107
+ statusLabel() {
108
+ if (this.starting) return '正在启动同步'
109
+ if (this.planLoading) return '正在生成同步预览'
110
+ if (this.configRequired) return '请先保存 OSS 存储设置'
111
+ if (this.planError) return syncErrors[this.planError] || '无法生成同步预览'
112
+ if (!this.running && this.plan) return this.plan.mode === 'noop' ? '本地与云端已同步' : '同步预览'
113
+ if (syncErrors[this.status.error]) return syncErrors[this.status.error]
114
+ switch (this.status.state) {
115
+ case 'running':
116
+ if (this.status.phase === 'scanning') return '正在扫描项目'
117
+ if (this.status.phase === 'publishing') return '正在发布云端版本'
118
+ if (this.status.phase === 'downloading' || this.status.action === 'download') return '正在下载项目'
119
+ return '正在同步项目'
120
+ case 'completed':
121
+ return this.status.action === 'download' ? '下载完成' : '同步完成'
122
+ case 'failed':
123
+ return this.status.failed ? '有文件未同步' : '同步失败'
124
+ case 'interrupted':
125
+ return '同步已中断'
126
+ default:
127
+ return '等待同步'
128
+ }
129
+ },
130
+ statusIcon() {
131
+ if (this.running || this.planLoading) return 'LoaderCircle'
132
+ if (this.planError || this.configRequired) return 'CircleAlert'
133
+ if (this.plan) return this.plan.mode === 'noop' ? 'CircleCheck' : 'CloudUpload'
134
+ if (this.status.state === 'completed') return 'CircleCheck'
135
+ if (this.status.state === 'idle' && !this.configRequired) return 'CloudUpload'
136
+ return 'CircleAlert'
137
+ },
138
+ dialogState() {
139
+ if (this.running || this.planLoading) return 'running'
140
+ if (this.configRequired || this.planError) return 'failed'
141
+ if (this.plan) return this.plan.mode === 'noop' ? 'completed' : 'idle'
142
+ return this.status.state
143
+ },
144
+ canDownload() {
145
+ const p = this.plan
146
+ return Boolean(p?.revision && (p.mode === 'download' || p.download?.length || p.removeLocal?.length || p.conflicts?.length))
147
+ },
148
+ canSync() {
149
+ return ['initialize', 'migrate', 'sync'].includes(this.plan?.mode)
150
+ },
151
+ unresolvedConflicts() {
152
+ return this.plan?.conflicts?.filter(({ file }) => !this.resolutions[file]).length || 0
153
+ },
154
+ downloadDeletes() {
155
+ return Boolean(this.plan?.removeLocal?.length || this.plan?.conflicts?.some(({ file, remote }) => !remote && this.resolutions[file] === 'remote'))
156
+ },
157
+ syncDeletes() {
158
+ return Boolean(this.downloadDeletes || this.plan?.removeRemote?.length ||
159
+ this.plan?.conflicts?.some(({ file, local }) => !local && this.resolutions[file] === 'local'))
160
+ },
161
+ deletionConfirmationVisible() {
162
+ return (this.canDownload && this.downloadDeletes) || (this.canSync && this.syncDeletes)
163
+ },
164
+ planGroups() {
165
+ if (!this.plan) return []
166
+ const { upload, download, removeLocal, removeRemote } = this.plan
167
+ return [
168
+ { label: '待下载', files: download },
169
+ { label: '待上传', files: upload },
170
+ { label: '从本地移除', files: removeLocal },
171
+ { label: '从云端版本移除', files: removeRemote },
172
+ ].filter(group => group.files?.length)
173
+ },
174
+ syncActionLabel() {
175
+ if (this.plan?.mode === 'initialize') return '发布初始版本'
176
+ if (this.plan?.mode === 'migrate') return '迁移并发布'
177
+ return '开始同步'
178
+ },
179
+ },
180
+ mounted() {
181
+ const updateNotificationTarget = () => {
182
+ this.notificationTarget = Array.from(document.querySelectorAll('dialog:modal')).at(-1) || 'body'
183
+ }
184
+ this.modalObserver = new MutationObserver(updateNotificationTarget)
185
+ this.modalObserver.observe(document.body, { subtree: true, attributes: true, attributeFilter: ['open'] })
186
+ updateNotificationTarget()
187
+ this.updateStatus()
188
+ },
189
+ beforeUnmount() {
190
+ this.modalObserver?.disconnect()
191
+ window.clearTimeout(this.timer)
192
+ this.request?.abort()
193
+ this.planRequest?.abort()
194
+ },
195
+ methods: {
196
+ open() {
197
+ if (this.$refs.dialog.open) return
198
+ this.$refs.dialog.showModal()
199
+ if (!this.running) this.loadPlan()
200
+ },
201
+ async loadPlan() {
202
+ if (this.running) return
203
+ this.planRequest?.abort()
204
+ const request = new AbortController()
205
+ this.planRequest = request
206
+ this.plan = null
207
+ this.resolutions = Object.create(null)
208
+ this.confirmDeletes = false
209
+ this.planError = ''
210
+ this.planLoading = true
211
+ try {
212
+ const response = await fetch(endpoint + '/plan', { signal: request.signal, cache: 'no-store' })
213
+ const plan = await response.json()
214
+ if (request.signal.aborted) return
215
+ if (!response.ok || typeof plan?.id !== 'string') {
216
+ this.planError = plan?.error || 'OSS_SYNC_PLAN_FAILED'
217
+ return
218
+ }
219
+ this.plan = plan
220
+ } catch {
221
+ if (!request.signal.aborted) this.planError = 'OSS_SYNC_PLAN_FAILED'
222
+ } finally {
223
+ if (!request.signal.aborted) {
224
+ this.planLoading = false
225
+ this.planRequest = null
226
+ }
227
+ }
228
+ },
229
+ openStorage() {
230
+ this.$refs.dialog.close()
231
+ this.$emit('configure-storage')
232
+ },
233
+ resolveConflict(file, choice) {
234
+ this.resolutions[file] = choice
235
+ this.confirmDeletes = false
236
+ },
237
+ formatSize(size) {
238
+ if (size < 1024) return size + ' B'
239
+ const units = ['KiB', 'MiB', 'GiB', 'TiB']
240
+ let unit = 0
241
+ for (size /= 1024; size >= 1024 && unit < units.length - 1; unit++) size /= 1024
242
+ return size.toLocaleString(undefined, { maximumFractionDigits: 1 }) + ' ' + units[unit]
243
+ },
244
+ start(action) {
245
+ const downloadOnly = action === 'download'
246
+ if (this.running || this.planLoading || !this.plan || this.configRequired || this.unresolvedConflicts) return
247
+ if (downloadOnly ? !this.canDownload : !this.canSync) return
248
+ if ((downloadOnly ? this.downloadDeletes : this.syncDeletes) && !this.confirmDeletes) return
249
+ this.updateStatus({
250
+ planId: this.plan.id,
251
+ action,
252
+ resolutions: this.resolutions,
253
+ confirmDeletes: this.confirmDeletes,
254
+ })
255
+ },
256
+ openFailureReport(report) {
257
+ this.failureReport = report
258
+ if (!this.$refs.failureDialog.open) this.$refs.failureDialog.showModal()
259
+ },
260
+ notifyResult() {
261
+ const complete = this.status.state === 'completed'
262
+ const title = this.$t(this.statusLabel)
263
+ const summary = this.$t(complete
264
+ ? '已上传 {uploaded},下载 {downloaded},移除 {removed},跳过 {skipped}。'
265
+ : '已上传 {uploaded},下载 {downloaded},移除 {removed},跳过 {skipped},失败 {failed}。', this.counts)
266
+ const report = {
267
+ title,
268
+ summary,
269
+ failures: [...(this.status.failures || [])],
270
+ }
271
+ const openReport = () => this.openFailureReport(report)
272
+ ElNotification({
273
+ title,
274
+ message: complete ? summary : () => h('div', [
275
+ h('span', summary),
276
+ h('button', {
277
+ type: 'button',
278
+ class: 'oss-sync-notice-details',
279
+ onClick: event => {
280
+ event.stopPropagation()
281
+ openReport()
282
+ },
283
+ }, this.$t('查看失败文件')),
284
+ ]),
285
+ type: complete ? 'success' : 'warning',
286
+ duration: 0,
287
+ offset: 56,
288
+ showClose: true,
289
+ appendTo: this.$refs.notificationHost,
290
+ customClass: complete ? 'oss-sync-notification' : 'oss-sync-notification oss-sync-notification--clickable',
291
+ onClick: complete ? undefined : openReport,
292
+ })
293
+ },
294
+ async updateStatus(payload) {
295
+ window.clearTimeout(this.timer)
296
+ this.request?.abort()
297
+ const request = new AbortController()
298
+ this.request = request
299
+ if (payload) {
300
+ this.starting = true
301
+ this.connectionError = false
302
+ this.planError = ''
303
+ }
304
+ try {
305
+ const response = await fetch(endpoint, {
306
+ method: payload ? 'POST' : 'GET',
307
+ headers: payload ? { 'Content-Type': 'application/json' } : undefined,
308
+ body: payload ? JSON.stringify(payload) : undefined,
309
+ signal: request.signal,
310
+ cache: 'no-store',
311
+ })
312
+ const status = await response.json()
313
+ if (request.signal.aborted) return
314
+ if (payload && !response.ok) {
315
+ this.planError = status?.error || 'OSS_SYNC_PLAN_FAILED'
316
+ this.plan = null
317
+ return
318
+ }
319
+ if (!status?.state) throw new Error()
320
+ if (payload || status.state === 'running') this.plan = null
321
+ const wasRunning = this.status.state === 'running'
322
+ this.status = status
323
+ this.starting = false
324
+ this.connectionError = false
325
+ if ((payload || wasRunning) && (status.state === 'completed' || (status.state === 'failed' && !this.configRequired))) {
326
+ this.notifyResult()
327
+ }
328
+ } catch {
329
+ if (!request.signal.aborted) this.connectionError = true
330
+ } finally {
331
+ if (!request.signal.aborted) {
332
+ this.starting = false
333
+ this.request = null
334
+ if (this.status.state === 'running' || (payload && this.connectionError)) {
335
+ this.timer = window.setTimeout(() => this.updateStatus(), this.connectionError ? 2600 : 1000)
336
+ }
337
+ }
338
+ }
339
+ },
340
+ },
341
+ }
342
+ </script>
343
+
344
+ <template>
345
+ <button type="button" class="topbar-icon-button oss-sync-trigger"
346
+ :class="{ 'is-running': running, 'has-count': showTopbarCount }"
347
+ :aria-label="triggerLabel" :title="triggerLabel" aria-haspopup="dialog" @click="open">
348
+ <span class="oss-sync-cloud" aria-hidden="true">
349
+ <span v-if="running" class="oss-sync-ring" :class="{ 'is-scanning': !showTopbarCount }"
350
+ :style="{ '--oss-sync-progress': (showTopbarCount ? percentage : 26) + '%' }"></span>
351
+ <CloudUpload :size="19" />
352
+ </span>
353
+ <span v-if="showTopbarCount" class="oss-sync-topbar-count" aria-hidden="true">{{ counts.processed }}/{{ status.total }}</span>
354
+ </button>
355
+ <Teleport to="body">
356
+ <dialog ref="dialog" class="dialog oss-sync-dialog oss-sync-plan-dialog" aria-labelledby="oss-sync-title">
357
+ <header class="dialog-head">
358
+ <h2 id="oss-sync-title">{{ $t('同步到 OSS') }}</h2>
359
+ <button type="button" class="icon-button" :aria-label="$t('关闭')" @click="$refs.dialog.close()"><X :size="20" aria-hidden="true" /></button>
360
+ </header>
361
+ <div class="dialog-body oss-sync-body">
362
+ <div class="oss-sync-status" :data-state="dialogState" role="status">
363
+ <component :is="statusIcon" class="oss-sync-status-icon" :size="18" aria-hidden="true" />
364
+ <strong>{{ $t(statusLabel) }}</strong>
365
+ </div>
366
+ <p v-if="target && !starting" class="oss-sync-note">{{ $t('目标') }} <code>{{ target }}</code></p>
367
+ <p v-if="connectionError" class="project-config-error" role="status">{{ $t('暂时无法获取同步状态') }}</p>
368
+
369
+ <template v-if="!running && plan">
370
+ <p v-if="plan.revision" class="oss-sync-note">
371
+ {{ $t('云端版本') }} <code :title="plan.revision">{{ plan.revision.slice(0, 8) }}</code>
372
+ </p>
373
+ <p v-if="plan.mode === 'migrate'" class="oss-sync-note">
374
+ {{ $t('迁移会使用当前项目建立协作版本,原 OSS 备份将保留。') }}
375
+ </p>
376
+ <p v-if="plan.mode === 'migrate'" class="oss-sync-note">
377
+ {{ $t('发现 {legacy} 个旧对象,其中 {reuse} 个可尝试校验后复用。', { legacy: plan.legacyCount, reuse: plan.legacyReuseCandidates }) }}
378
+ </p>
379
+ <p v-if="plan.mode === 'initialize'" class="oss-sync-note">
380
+ {{ $t('发布后,同事可从 OSS 下载这个项目。') }}
381
+ </p>
382
+ <div v-if="planGroups.length" class="oss-sync-plan-groups">
383
+ <details v-for="group in planGroups" :key="group.label" class="oss-sync-plan-group">
384
+ <summary>
385
+ <span>{{ $t(group.label) }}</span>
386
+ <strong>{{ group.files.length }}</strong>
387
+ </summary>
388
+ <ul class="oss-sync-plan-files">
389
+ <li v-for="entry in group.files" :key="entry.file">
390
+ <code>{{ entry.file }}</code>
391
+ <small v-if="Number.isFinite(entry.size)">{{ formatSize(entry.size) }}</small>
392
+ </li>
393
+ </ul>
394
+ </details>
395
+ </div>
396
+ <section v-if="plan.conflicts?.length" class="oss-sync-conflicts" aria-labelledby="oss-conflicts-title">
397
+ <h3 id="oss-conflicts-title">{{ $t('文件冲突({count})', { count: plan.conflicts.length }) }}</h3>
398
+ <p class="oss-sync-note">{{ $t('请逐个选择。采用云端内容时,原本地文件会先备份。') }}</p>
399
+ <ul class="oss-sync-conflict-files">
400
+ <li v-for="conflict in plan.conflicts" :key="conflict.file">
401
+ <code>{{ conflict.file }}</code>
402
+ <ElRadioGroup :model-value="resolutions[conflict.file]" :aria-label="conflict.file"
403
+ @update:model-value="resolveConflict(conflict.file, $event)">
404
+ <ElRadioButton value="local">{{ $t(conflict.local ? '保留本地' : '保留本地删除') }}</ElRadioButton>
405
+ <ElRadioButton value="remote">{{ $t(conflict.remote ? '采用云端' : '采用云端删除') }}</ElRadioButton>
406
+ </ElRadioGroup>
407
+ </li>
408
+ </ul>
409
+ </section>
410
+ <ElCheckbox v-if="deletionConfirmationVisible" v-model="confirmDeletes" class="oss-sync-delete-confirmation">
411
+ {{ $t('确认移除本次操作中列出的文件') }}
412
+ </ElCheckbox>
413
+ </template>
414
+
415
+ <template v-if="!starting && !plan && !planLoading && !planError && (status.total > 0 || status.state === 'completed')">
416
+ <div class="oss-sync-progress">
417
+ <span>{{ $t('已处理 {count} / {total} 个文件', { count: counts.processed, total: status.total }) }}</span>
418
+ <strong>{{ percentage }}%</strong>
419
+ </div>
420
+ <ElProgress :percentage="percentage" :show-text="false" :stroke-width="8" :aria-label="$t('同步进度')" />
421
+ <p v-if="status.currentFile" class="oss-sync-file">
422
+ <code>{{ status.currentFile }}</code>
423
+ <span v-if="status.currentPercent > 0">{{ status.currentPercent }}%</span>
424
+ </p>
425
+ <dl class="oss-sync-counts">
426
+ <div v-for="item in resultStats" :key="item.label"><dt>{{ $t(item.label) }}</dt><dd>{{ item.count }}</dd></div>
427
+ </dl>
428
+ </template>
429
+
430
+ <details v-if="!starting && !plan && !planLoading && !planError && status.failures?.length" class="oss-sync-failures">
431
+ <summary>{{ $t('查看失败文件') }}</summary>
432
+ <ul>
433
+ <li v-for="failure in status.failures" :key="failure.file">
434
+ <code>{{ failure.file }}</code>
435
+ <small>{{ $t(fileErrors[failure.code] || '文件上传失败') }}</small>
436
+ </li>
437
+ </ul>
438
+ </details>
439
+ </div>
440
+ <footer class="dialog-footer oss-sync-actions">
441
+ <button v-if="!running && !configRequired" type="button" class="secondary oss-sync-refresh"
442
+ :disabled="planLoading" @click="loadPlan">
443
+ <RefreshCw :size="15" aria-hidden="true" /> {{ $t('重新预览') }}
444
+ </button>
445
+ <button type="button" class="secondary" @click="$refs.dialog.close()">{{ $t('关闭') }}</button>
446
+ <button v-if="!running && configRequired" type="button" class="primary" @click="openStorage">{{ $t('存储设置') }}</button>
447
+ <button v-if="!running && canDownload" type="button" :class="canSync ? 'secondary' : 'primary'"
448
+ :disabled="unresolvedConflicts > 0 || (downloadDeletes && !confirmDeletes)" @click="start('download')">
449
+ <CloudDownload :size="16" aria-hidden="true" /> {{ $t(plan.mode === 'download' ? '下载项目' : '仅下载更新') }}
450
+ </button>
451
+ <button v-if="!running && canSync" type="button" class="primary"
452
+ :disabled="unresolvedConflicts > 0 || (syncDeletes && !confirmDeletes)" @click="start('sync')">
453
+ {{ $t(syncActionLabel) }}
454
+ </button>
455
+ </footer>
456
+ </dialog>
457
+ <dialog ref="failureDialog" class="dialog oss-sync-dialog" aria-labelledby="oss-sync-failure-title">
458
+ <header class="dialog-head">
459
+ <h2 id="oss-sync-failure-title">{{ $t('同步失败详情') }}</h2>
460
+ <button type="button" class="icon-button" :aria-label="$t('关闭')" @click="$refs.failureDialog.close()"><X :size="20" aria-hidden="true" /></button>
461
+ </header>
462
+ <div v-if="failureReport" class="dialog-body oss-sync-body">
463
+ <div class="oss-sync-status" data-state="failed">
464
+ <CircleAlert :size="18" aria-hidden="true" />
465
+ <strong>{{ failureReport.title }}</strong>
466
+ </div>
467
+ <p class="oss-sync-note">{{ failureReport.summary }}</p>
468
+ <ul v-if="failureReport.failures.length" class="oss-sync-failure-list">
469
+ <li v-for="failure in failureReport.failures" :key="failure.file">
470
+ <code>{{ failure.file }}</code>
471
+ <small>
472
+ {{ $t(fileErrors[failure.code] || '文件上传失败') }}
473
+ <span v-if="failure.status">(HTTP {{ failure.status }})</span>
474
+ </small>
475
+ </li>
476
+ </ul>
477
+ </div>
478
+ <footer class="dialog-footer">
479
+ <button type="button" class="secondary" @click="$refs.failureDialog.close()">{{ $t('关闭') }}</button>
480
+ </footer>
481
+ </dialog>
482
+ </Teleport>
483
+ <Teleport :to="notificationTarget">
484
+ <div ref="notificationHost"></div>
485
+ </Teleport>
486
+ </template>
package/src/i18n/en.json CHANGED
@@ -1,4 +1,112 @@
1
1
  {
2
+ "Git LFS 存储目标": "Git LFS Storage Destination",
3
+ "Git LFS 使用这里保存的 OSS 配置直传和下载媒体。": "Git LFS uploads and downloads media directly using the OSS settings saved here.",
4
+ "当前项目没有可同步的文件": "This project has no files to sync",
5
+ "本地和云端存在冲突路径,请调整文件名后重新预览": "Local and cloud paths collide. Rename the affected files and preview again.",
6
+ "发现 {legacy} 个旧对象,其中 {reuse} 个可尝试校验后复用。": "Found {legacy} legacy objects. {reuse} are candidates for verification and reuse.",
7
+ "文件下载失败": "File download failed",
8
+ "下载文件校验失败": "Downloaded file failed verification",
9
+ "无法移除文件": "Unable to remove the file",
10
+ "项目或云端版本已变化,请重新预览": "The local files or cloud revision changed. Refresh the preview.",
11
+ "请选择每个冲突文件的处理方式": "Choose how to handle each conflicting file",
12
+ "请确认本次移除操作": "Confirm file removals for this operation",
13
+ "本地项目与云端项目不一致": "This local project does not match the project in OSS",
14
+ "同事已发布新版本,请重新预览": "A newer revision was published. Refresh the preview.",
15
+ "云端项目清单无效": "The cloud project manifest is invalid",
16
+ "无法读取或写入云端项目": "Unable to read or write the cloud project",
17
+ "需要原项目文件才能迁移旧版备份": "Use the original project files to migrate the legacy backup",
18
+ "本地同步清单无效": "The local sync manifest is invalid",
19
+ "已下载": "Downloaded",
20
+ "已移除": "Removed",
21
+ "正在生成同步预览": "Preparing sync preview",
22
+ "无法生成同步预览": "Unable to prepare a sync preview",
23
+ "本地与云端已同步": "Local and cloud files are up to date",
24
+ "同步预览": "Sync Preview",
25
+ "正在发布云端版本": "Publishing cloud revision",
26
+ "正在下载项目": "Downloading project files",
27
+ "下载完成": "Download complete",
28
+ "待下载": "To download",
29
+ "待上传": "To upload",
30
+ "从本地移除": "Remove locally",
31
+ "从云端版本移除": "Remove from cloud revision",
32
+ "发布初始版本": "Publish Initial Revision",
33
+ "迁移并发布": "Migrate and Publish",
34
+ "已上传 {uploaded},下载 {downloaded},移除 {removed},跳过 {skipped}。": "Uploaded {uploaded}, downloaded {downloaded}, removed {removed}, and skipped {skipped}.",
35
+ "已上传 {uploaded},下载 {downloaded},移除 {removed},跳过 {skipped},失败 {failed}。": "Uploaded {uploaded}, downloaded {downloaded}, removed {removed}, skipped {skipped}, and failed {failed}.",
36
+ "云端版本": "Cloud revision",
37
+ "迁移会使用当前项目建立协作版本,原 OSS 备份将保留。": "Migration publishes a collaboration revision from this project and keeps the original OSS backup.",
38
+ "发布后,同事可从 OSS 下载这个项目。": "Your teammates can download this project from OSS once it is published.",
39
+ "文件冲突({count})": "File conflicts ({count})",
40
+ "请逐个选择。采用云端内容时,原本地文件会先备份。": "Choose for each file. Using the cloud version creates a backup of the original local file.",
41
+ "保留本地": "Keep Local",
42
+ "保留本地删除": "Keep Local Deletion",
43
+ "采用云端": "Use Cloud",
44
+ "采用云端删除": "Apply Cloud Deletion",
45
+ "确认移除本次操作中列出的文件": "Confirm removal of the files listed for this operation",
46
+ "重新预览": "Refresh Preview",
47
+ "下载项目": "Download Project",
48
+ "仅下载更新": "Download Updates Only",
49
+ "同步失败详情": "Sync failure details",
50
+ "已处理 {count} / {total} 个文件,已上传 {uploaded} 个": "{count} of {total} files processed, {uploaded} uploaded",
51
+ "已上传 {uploaded} 个文件,跳过 {skipped} 个。": "Uploaded {uploaded} files and skipped {skipped}.",
52
+ "已上传 {uploaded} 个文件,跳过 {skipped} 个,失败 {failed} 个。": "Uploaded {uploaded} files, skipped {skipped}, and failed to upload {failed}.",
53
+ "目标": "Destination",
54
+ "文件在同步期间发生变化": "The file changed during sync",
55
+ "无法读取文件": "Unable to read the file",
56
+ "文件上传失败": "File upload failed",
57
+ "无法扫描项目文件": "Unable to scan project files",
58
+ "无法保存同步进度": "Unable to save sync progress",
59
+ "同步到 OSS": "Sync to OSS",
60
+ "查看同步进度": "View Sync Progress",
61
+ "正在启动同步": "Starting sync",
62
+ "请先保存 OSS 存储设置": "Save OSS settings before syncing",
63
+ "另一个工作台实例正在同步": "Another workbench instance is syncing",
64
+ "正在扫描项目": "Scanning project files",
65
+ "正在同步项目": "Syncing project files",
66
+ "同步完成": "Sync complete",
67
+ "有文件未同步": "Some files could not be synced",
68
+ "同步失败": "Sync failed",
69
+ "同步已中断": "Sync interrupted",
70
+ "等待同步": "Ready to sync",
71
+ "继续同步": "Resume Sync",
72
+ "重试同步": "Retry Sync",
73
+ "再次同步": "Sync Again",
74
+ "开始同步": "Start Sync",
75
+ "暂时无法获取同步状态": "Sync status is temporarily unavailable",
76
+ "已处理 {count} / {total} 个文件": "{count} of {total} files processed",
77
+ "同步进度": "Sync progress",
78
+ "已上传": "Uploaded",
79
+ "已跳过": "Skipped",
80
+ "失败": "Failed",
81
+ "查看失败文件": "Show files that failed",
82
+ "再次同步会跳过未改动的文件,并续传未完成的分片。": "Syncing again skips unchanged files and resumes incomplete multipart uploads.",
83
+ "测试连接": "Test Connection",
84
+ "正在测试…": "Testing…",
85
+ "上传成功,读回内容一致。": "Uploaded successfully and verified the file contents.",
86
+ "无法使用已保存的 OSS 配置,请检查设置。": "Check the saved OSS settings.",
87
+ "OSS 测试文件上传失败。": "Unable to upload the OSS test file.",
88
+ "测试文件已上传,但无法读回。": "The test file was uploaded, but could not be read back.",
89
+ "读回内容与测试文件不一致。": "The downloaded content does not match the test file.",
90
+ "测试连接失败。": "Connection test failed.",
91
+ "留空使用 Bucket 根目录": "Leave blank to use the bucket root",
92
+ "路径": "Path",
93
+ "其它设置": "Other Settings",
94
+ "无法保存语言设置": "Unable to save language settings",
95
+ "存储设置": "Storage Settings",
96
+ "OSS 地址": "OSS Endpoint",
97
+ "Bucket 名称": "Bucket Name",
98
+ "已配置,留空保留": "Configured. Leave blank to keep.",
99
+ "无法读取存储设置": "Unable to load storage settings",
100
+ "无法保存存储设置": "Unable to save storage settings",
101
+ "请检查 OSS 地址、Bucket 和访问凭据": "Check the OSS endpoint, bucket and access credentials",
102
+ "基本信息": "Basic Information",
103
+ "项目 Logo": "Project Logo",
104
+ "更换 Logo": "Change Logo",
105
+ "请选择 2 MB 以内的受支持图片": "Choose a supported image up to 2 MB",
106
+ "全局设置": "Project Settings",
107
+ "项目名称": "Project Name",
108
+ "项目描述": "Project Description",
109
+ "无法保存项目设置": "Unable to save project settings",
2
110
  "语言": "Language",
3
111
  "制作工作台": "Production Workbench",
4
112
  "制作项目": "Production Project",
@@ -44,6 +152,16 @@
44
152
  "{count} 个角色": "Characters: {count}",
45
153
  "新建角色": "New Character",
46
154
  "搜索名称或标签": "Search by name or tag",
155
+ "已选 {count} 个": "{count} selected",
156
+ "取消全选": "Deselect all",
157
+ "全选": "Select all",
158
+ "清空": "Clear",
159
+ "退出": "Exit",
160
+ "批量操作": "Batch actions",
161
+ "设为 2D 主图": "Set 2D cover",
162
+ "设为 3D 主图": "Set 3D cover",
163
+ "批量选择": "Select characters",
164
+ "用 Codex 同步到即梦": "Sync to Jimeng with Codex",
47
165
  "音色缺失": "Missing voice",
48
166
  "切换全部角色封面图": "Switch all character covers",
49
167
  "封面图": "Cover",
package/src/i18n/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { reactive, watch } from 'vue'
2
+ import projectGlobal from 'virtual:project-global'
2
3
  import en from './en.json'
3
4
 
4
5
  const storageKey = 'workbench.locale'
@@ -6,6 +7,7 @@ const defaultLocale = 'zh-CN'
6
7
  export const languages = Object.freeze({ 'zh-CN': '简体中文', en: 'English' })
7
8
 
8
9
  function readLocale() {
10
+ if (Object.hasOwn(languages, projectGlobal.locale)) return projectGlobal.locale
9
11
  try {
10
12
  const saved = localStorage.getItem(storageKey)
11
13
  if (Object.hasOwn(languages, saved)) return saved
@@ -30,11 +32,6 @@ export const i18n = {
30
32
  app.config.globalProperties.$t = translate
31
33
  watch(() => language.locale, locale => {
32
34
  document.documentElement.lang = locale
33
- try {
34
- localStorage.setItem(storageKey, locale)
35
- } catch {
36
- // Keep the current selection in memory.
37
- }
38
35
  }, { immediate: true, flush: 'sync' })
39
36
  },
40
37
  }