dsh-ai-subtitle 0.3.1 → 0.3.2

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.en.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![npm](https://img.shields.io/npm/v/dsh-ai-subtitle.svg)](https://www.npmjs.com/package/dsh-ai-subtitle)
8
8
  [![Node](https://img.shields.io/badge/Node-22%2B-brightgreen.svg)](https://nodejs.org/)
9
9
 
10
- <!-- translated-from: README.md sha256:18d65a239037 -->
10
+ <!-- translated-from: README.md sha256:f3562069ca01 -->
11
11
 
12
12
  A subtitle plugin for DeepSeek Harness (DSH) that turns Japanese video into bilingual
13
13
  Japanese/Chinese SRT files. The plugin installs every runtime component it needs
@@ -79,6 +79,8 @@ and exports the same format.
79
79
  - projects default to `Documents\\DshSubtitle\\projects` and can be changed or opened from
80
80
  the panel;
81
81
  - hour-long videos take a while to transcribe; transcribe first, then translate in batches;
82
+ - the panel API accepts only same-origin requests from the DSH page; another program calling
83
+ it directly is refused;
82
84
  - deleting a project offers "remove from list" or "delete the local files"; the second
83
85
  cannot be undone.
84
86
 
package/README.ja.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![npm](https://img.shields.io/npm/v/dsh-ai-subtitle.svg)](https://www.npmjs.com/package/dsh-ai-subtitle)
8
8
  [![Node](https://img.shields.io/badge/Node-22%2B-brightgreen.svg)](https://nodejs.org/)
9
9
 
10
- <!-- translated-from: README.md sha256:18d65a239037 -->
10
+ <!-- translated-from: README.md sha256:f3562069ca01 -->
11
11
 
12
12
  DeepSeek Harness(DSH)の字幕プラグインです。日本語動画を日中バイリンガルの SRT に変換します。必要なランタイム(ffmpeg、CPython、PyTorch、transformers)は指定ディレクトリにすべて導入されるため、Python・ffmpeg・モデルを事前に用意する必要はありません。
13
13
 
@@ -54,6 +54,7 @@ DeepSeek Harness(DSH)の字幕プラグインです。日本語動画を日
54
54
  - API key は保存しません(認証情報は DSH が管理);
55
55
  - プロジェクトは既定で「ドキュメント\\DshSubtitle\\projects」。パネルから変更・オープンできます;
56
56
  - 数時間の動画は時間がかかるため、先に文字起こしを済ませてから分割して翻訳するのがおすすめです;
57
+ - パネルの API は DSH ページからの同一オリジン要求のみ受け付けます。他のプログラムからの直接呼び出しは拒否されます。
57
58
  - プロジェクト削除は「一覧から外す」と「ローカルファイルも削除」を選べます。後者は元に戻せません。
58
59
 
59
60
  ## 導入
package/README.ko.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![npm](https://img.shields.io/npm/v/dsh-ai-subtitle.svg)](https://www.npmjs.com/package/dsh-ai-subtitle)
8
8
  [![Node](https://img.shields.io/badge/Node-22%2B-brightgreen.svg)](https://nodejs.org/)
9
9
 
10
- <!-- translated-from: README.md sha256:18d65a239037 -->
10
+ <!-- translated-from: README.md sha256:f3562069ca01 -->
11
11
 
12
12
  DeepSeek Harness(DSH)용 자막 플러그인으로, 일본어 영상을 일중 이중 언어 SRT로 변환합니다. 필요한 런타임(ffmpeg, CPython, PyTorch, transformers)은 지정한 디렉터리에 모두 설치되므로 Python, ffmpeg, 모델을 미리 준비할 필요가 없습니다.
13
13
 
@@ -54,6 +54,7 @@ DeepSeek Harness(DSH)용 자막 플러그인으로, 일본어 영상을 일중
54
54
  - API key를 저장하지 않습니다(자격 증명은 DSH가 관리);
55
55
  - 프로젝트 기본 위치는 「문서\\DshSubtitle\\projects」이며 패널에서 변경하거나 열 수 있습니다;
56
56
  - 몇 시간짜리 영상은 전사에 시간이 걸리므로 먼저 전사한 뒤 여러 배치로 나눠 번역하는 편이 좋습니다;
57
+ - 패널 API는 DSH 페이지의 동일 출처 요청만 허용합니다. 다른 프로그램이 직접 호출하면 거부됩니다.
57
58
  - 프로젝트 삭제 시 「목록에서 제거」와 「로컬 파일까지 삭제」를 고를 수 있으며 후자는 되돌릴 수 없습니다.
58
59
 
59
60
  ## 설치
package/README.md CHANGED
@@ -52,6 +52,7 @@ DeepSeek Harness(DSH)的字幕插件,把日语视频转成中日双语 SRT
52
52
  - 插件不保存 API key,模型凭证由 DSH 管理;
53
53
  - 项目默认在「文档\\DshSubtitle\\projects」,可在面板里更改或直接打开;
54
54
  - 数小时的视频转写较慢,建议先转写完再分几批翻译;
55
+ - 面板接口只接受来自 DSH 页面的同源请求,其他程序直接调用会被拒绝;
55
56
  - 删除项目时可选「仅从列表移除」或「连本地文件一起删除」,后者不可撤销。
56
57
 
57
58
  ## 安装
package/index.js CHANGED
@@ -66,10 +66,23 @@ export function apply(ctx, config = {}) {
66
66
  return llmCtx
67
67
  }
68
68
 
69
+ // The panel routes must not be reachable from another origin, so the API
70
+ // defers to the Host's connection admission when the composition provides it.
71
+ let connectionCtx = null
72
+ ctx.inject(['connection'], (scoped) => {
73
+ scoped.effect(() => {
74
+ connectionCtx = scoped
75
+ return () => {
76
+ connectionCtx = null
77
+ }
78
+ })
79
+ })
80
+ const connectionService = () => (connectionCtx ? connectionCtx.connection : undefined)
81
+
69
82
  // The sidebar panel talks to the Host over these local JSON routes. The
70
83
  // plugin still works without a web server (headless profiles just skip it).
71
84
  ctx.inject(['webServer'], (scoped) => {
72
- scoped.effect(() => registerApi(scoped, runtimeFor, modelContext))
85
+ scoped.effect(() => registerApi(scoped, runtimeFor, modelContext, connectionService))
73
86
  })
74
87
 
75
88
  ctx.tools.register(defineTool({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ai-subtitle",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Japanese video to bilingual JP/zh subtitles inside DeepSeek Harness: a self-installing ffmpeg, Python and Whisper runtime, cue editing and SRT export.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Admission guard for the panel's HTTP routes.
3
+ *
4
+ * The routes live on the same origin as the DSH web GUI, so the browser sends
5
+ * the host's auth cookie with every panel request. `ctx.connection` owns that
6
+ * check (Host/Origin trust plus browser authentication); when a host exposes
7
+ * it, the plugin defers to it. Older or headless compositions without the
8
+ * service fall back to the request-header checks below, which stop a page on
9
+ * another origin from driving the routes through the browser.
10
+ */
11
+
12
+ /**
13
+ * Fallback rejection for hosts without `connection.requestRejection`.
14
+ * @param headers - request headers (node:http lower-cased record or Headers).
15
+ * @returns 403 for a cross-site or foreign-origin request, undefined otherwise.
16
+ */
17
+ export function fallbackRejection(headers) {
18
+ const read = (name) => {
19
+ if (!headers) return undefined
20
+ if (typeof headers.get === 'function') return headers.get(name)
21
+ const value = headers[name]
22
+ return Array.isArray(value) ? value[0] : value
23
+ }
24
+ const site = String(read('sec-fetch-site') || '').toLowerCase()
25
+ if (site === 'cross-site') return 403
26
+ const origin = read('origin')
27
+ if (origin) {
28
+ const host = read('host')
29
+ if (!host) return 403
30
+ try {
31
+ if (new URL(origin).host !== host) return 403
32
+ } catch {
33
+ return 403
34
+ }
35
+ }
36
+ return undefined
37
+ }
38
+
39
+ /**
40
+ * Decide whether one request may reach the panel API.
41
+ * @param connection - `ctx.connection`, when the composition provides it.
42
+ * @param request - node:http request carrying headers.
43
+ * @returns rejection status (401/403) or null when the request may proceed.
44
+ */
45
+ export function rejectRequest(connection, request) {
46
+ if (connection && typeof connection.requestRejection === 'function') {
47
+ try {
48
+ const status = connection.requestRejection(request)
49
+ return status === undefined ? null : status
50
+ } catch {
51
+ // A failing trust check must never fail open.
52
+ return 403
53
+ }
54
+ }
55
+ const status = fallbackRejection(request && request.headers ? request.headers : undefined)
56
+ return status === undefined ? null : status
57
+ }
package/src/api.js CHANGED
@@ -7,6 +7,7 @@ import { DEFAULT_MODEL } from './installer.js'
7
7
  import { buildRows, cueStats, deriveCueTimes, describeCoverageErrors, toSrt, validateCues } from './cues.js'
8
8
  import { forgetProject, loadRegistry, patchProject } from './registry.js'
9
9
  import { defaultProjectsDir } from './paths.js'
10
+ import { rejectRequest } from './admission.js'
10
11
  import { recentMedia, rememberMedia } from './recent.js'
11
12
  import { chooseSources, sourcesFromState } from './sources.js'
12
13
  import { applyBatch, batchState, loadProject, nextBatch, planBatches, renderBatch, reviewStatus } from './review.js'
@@ -357,8 +358,19 @@ function projectDetail(dir, limit = 300) {
357
358
  * Local JSON API for the studio panel. Registered as a handler route because the
358
359
  * panel needs POST for install, transcribe, import, save and export.
359
360
  */
360
- export function registerApi(ctx, runtimeFor, modelContext) {
361
+ export function registerApi(ctx, runtimeFor, modelContext, connectionFor) {
361
362
  const handler = async (request, response) => {
363
+ // Same-origin panel requests carry the host's auth cookie; anything else is
364
+ // refused before it can reach a route that changes files.
365
+ const connection = typeof connectionFor === 'function'
366
+ ? connectionFor()
367
+ : typeof ctx.get === 'function' ? ctx.get('connection') : undefined
368
+ const rejection = rejectRequest(connection, request)
369
+ if (rejection !== null) {
370
+ response.writeHead(rejection, { 'content-type': 'text/plain; charset=utf-8' })
371
+ response.end(rejection === 401 ? 'unauthorized' : 'forbidden')
372
+ return
373
+ }
362
374
  const url = new URL(request.url || '/', 'http://local')
363
375
  const path = url.pathname.slice(PREFIX.length) || '/'
364
376
  const runtime = runtimeFor(url.searchParams.get('installDir') || undefined)