javdict 1.3.0 → 1.3.1

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/index.js CHANGED
@@ -24,29 +24,32 @@ program
24
24
  .option('-l, --lang <lang>', '显示语言 zh/en/jp/kr/de', 'zh')
25
25
  .action(async (id, options) => {
26
26
 
27
+ const lang = options.lang || 'zh';
28
+ const t = getLang(lang); // 统一获取语言包
29
+
27
30
  if (options.setup) {
28
31
  console.log('');
29
- console.log(chalk.yellow('=== 配置 JAVDB Cookie(可选)==='));
32
+ console.log(chalk.yellow('=== ' + (t.setupTitle || '配置 JAVDB Cookie(可选)') + ' ==='));
30
33
  console.log('');
31
- console.log('不配置也可以正常使用,配置后覆盖率更高。');
34
+ console.log(t.setupDesc || '不配置也可以正常使用,配置后覆盖率更高。');
32
35
  console.log('');
33
- console.log('获取步骤:');
34
- console.log(' 1. Chrome 打开 https://javdb.com 并登录账号');
35
- console.log(' 2. 安装插件 "Get cookies.txt LOCALLY"');
36
- console.log(' 3. 导出 Cookie 文件,找到 _jdb_session 那行');
37
- console.log(' 4. 复制最后一列的值粘贴到下面');
36
+ console.log(t.setupSteps || '获取步骤:');
37
+ console.log(' 1. ' + (t.setupStep1 || 'Chrome 打开 https://javdb.com 并登录账号'));
38
+ console.log(' 2. ' + (t.setupStep2 || '安装插件 "Get cookies.txt LOCALLY"'));
39
+ console.log(' 3. ' + (t.setupStep3 || '导出 Cookie 文件,找到 _jdb_session 那行'));
40
+ console.log(' 4. ' + (t.setupStep4 || '复制最后一列的值粘贴到下面'));
38
41
  console.log('');
39
42
 
40
43
  const rl = createInterface({ input: process.stdin, output: process.stdout });
41
44
  await new Promise((resolve) => {
42
- rl.question(chalk.cyan('请粘贴 _jdb_session 的值(直接回车跳过): '), (session) => {
45
+ rl.question(chalk.cyan((t.setupPrompt || '请粘贴 _jdb_session 的值(直接回车跳过): ')), (session) => {
43
46
  rl.close();
44
47
  if (!session.trim()) {
45
- console.log(chalk.gray('\n已跳过,使用 JAVBUS + JavLibrary 作为数据源。'));
48
+ console.log(chalk.gray('\n' + (t.setupSkipped || '已跳过,使用 JAVBUS + JavLibrary 作为数据源。')));
46
49
  } else {
47
50
  setConfig({ session: session.trim() });
48
- console.log(chalk.green('\n✅ 配置保存成功!'));
49
- console.log(chalk.gray('保存位置: ~/.config/javinfo/config.json'));
51
+ console.log(chalk.green('\n✅ ' + (t.setupSuccess || '配置保存成功!')));
52
+ console.log(chalk.gray((t.setupSavePath || '保存位置: ~/.config/javinfo/config.json')));
50
53
  }
51
54
  console.log('');
52
55
  resolve();
@@ -56,7 +59,7 @@ program
56
59
  }
57
60
 
58
61
  if (options.clearCache) {
59
- clearCache();
62
+ clearCache(lang);
60
63
  process.exit(0);
61
64
  }
62
65
 
@@ -65,11 +68,10 @@ program
65
68
  process.exit(0);
66
69
  }
67
70
 
68
- const t = getLang(options.lang || 'zh');
69
71
  const spinner = ora(`${t.searching} ${id.toUpperCase()} ...`).start();
70
72
 
71
73
  try {
72
- const result = await search(id.toUpperCase());
74
+ const result = await search(id.toUpperCase(), lang);
73
75
  spinner.stop();
74
76
 
75
77
  if (!result) {
@@ -81,7 +83,7 @@ program
81
83
  process.exit(1);
82
84
  }
83
85
 
84
- display(result, options.raw, options.lang || 'zh');
86
+ display(result, options.raw, lang);
85
87
  } catch (err) {
86
88
  spinner.stop();
87
89
  console.error(`\n${t.queryFailed}:`, err.message);
package/lib/cache.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
2
2
  import { homedir } from 'os';
3
3
  import { join } from 'path';
4
+ import { getLang } from './i18n.js';
4
5
 
5
6
  // 缓存文件存放在用户主目录下,和 yddict 的做法一致
6
7
  const CACHE_DIR = join(homedir(), '.config', 'javinfo');
@@ -14,7 +15,6 @@ function loadCache() {
14
15
  try {
15
16
  return JSON.parse(readFileSync(CACHE_FILE, 'utf-8'));
16
17
  } catch {
17
- // 文件损坏就当缓存不存在
18
18
  return {};
19
19
  }
20
20
  }
@@ -31,7 +31,6 @@ export function getCache(id) {
31
31
  const entry = cache[id];
32
32
  if (!entry) return null;
33
33
 
34
- // 检查是否过期
35
34
  const isExpired = Date.now() - entry.cachedAt > TTL;
36
35
  if (isExpired) return null;
37
36
 
@@ -47,10 +46,20 @@ export function setCache(id, data) {
47
46
  saveCache(cache);
48
47
  }
49
48
 
50
- export function clearCache() {
51
- if (existsSync(CACHE_FILE)) {
52
- writeFileSync(CACHE_FILE, '{}', 'utf-8');
53
- console.log('缓存已清空');
49
+ // 清空缓存(已支持多语言)
50
+ export function clearCache(lang = 'zh') {
51
+ const t = getLang(lang);
52
+
53
+ try {
54
+ if (existsSync(CACHE_FILE)) {
55
+ writeFileSync(CACHE_FILE, '{}', 'utf-8');
56
+ console.log(t.cacheCleared);
57
+ } else {
58
+ console.log(t.cacheCleared);
59
+ }
60
+ } catch (err) {
61
+ console.error(`${t.cacheClearFailed}: ${err.message}`);
62
+ console.error(`${t.cachePath}: ${CACHE_FILE}`);
54
63
  }
55
64
  }
56
65
 
package/lib/fetcher.js CHANGED
@@ -2,6 +2,7 @@ import { execSync } from 'child_process';
2
2
  import * as cheerio from 'cheerio';
3
3
  import { getCache, setCache, getConfig } from './cache.js';
4
4
  import chalk from 'chalk';
5
+ import {getLang} from "./i18n.js";
5
6
 
6
7
  // ─── 通用请求函数(JAVBUS / JavLibrary 使用)────────────
7
8
  function fetchHtml(url, cookie = '') {
@@ -322,13 +323,15 @@ function parseJavdb(html, queryId) {
322
323
  return result.title ? result : null;
323
324
  }
324
325
 
325
- // ─── 主入口:依次尝试三个数据源 ─────────────────────────
326
- export async function search(id) {
327
- // FC2 格式识别:031926-100 → 031926_100(JAVDB 存储格式)
326
+ // ─── 主入口:依次尝试数据源 ─────────────────────────
327
+ export async function search(id, lang = 'zh') {
328
+ const t = getLang(lang);
329
+
330
+ // FC2 格式识别:031926-100 → 031926_100
328
331
  let searchId = id;
329
332
  if (/^\d{5,6}-\d+$/.test(id)) {
330
- searchId = id.replace(/-/g, '_'); // 全局替换,更安全
331
- console.log(chalk.gray(` 识别为FC2格式的车牌号: ${id}`));
333
+ searchId = id.replace(/-/g, '_');
334
+ console.log(chalk.gray(` ${t.fc2Detected}: ${id} → ${searchId}`));
332
335
  }
333
336
 
334
337
  const cached = getCache(id);
package/lib/i18n.js CHANGED
@@ -17,8 +17,21 @@ export const messages = {
17
17
  notFound: '未找到番号',
18
18
  queryFailed: '查询失败',
19
19
  cacheCleared: '缓存已清空',
20
- fc2Detected: 'FC2番号已转换为',
20
+ cacheClearFailed: '清空缓存失败',
21
+ cachePath: '缓存路径',
22
+ fc2Detected: '识别为FC2格式的车牌号',
21
23
  windowsHint: '温馨提示: 此番号需要JAVDB数据源,Windows暂不支持~',
24
+ setupTitle: '配置 JAVDB Cookie(可选)',
25
+ setupDesc: '不配置也可以正常使用,配置后覆盖率更高。',
26
+ setupSteps: '获取步骤:',
27
+ setupStep1: 'Chrome 打开 https://javdb.com 并登录账号',
28
+ setupStep2: '安装插件 "Get cookies.txt LOCALLY"',
29
+ setupStep3: '导出 Cookie 文件,找到 _jdb_session 那行',
30
+ setupStep4: '复制最后一列的值粘贴到下面',
31
+ setupPrompt: '请粘贴 _jdb_session 的值(直接回车跳过): ',
32
+ setupSkipped: '已跳过,使用 JAVBUS + JavLibrary 作为数据源。',
33
+ setupSuccess: '配置保存成功!',
34
+ setupSavePath: '保存位置: ~/.config/javinfo/config.json',
22
35
  },
23
36
  en: {
24
37
  actress: 'Actress',
@@ -38,8 +51,21 @@ export const messages = {
38
51
  notFound: 'Title not found',
39
52
  queryFailed: 'Query failed',
40
53
  cacheCleared: 'Cache cleared',
54
+ cacheClearFailed: 'Failed to clear cache',
55
+ cachePath: 'Cache path',
41
56
  fc2Detected: 'FC2 format detected',
42
57
  windowsHint: 'Note: This title requires JAVDB, which is unavailable on Windows.',
58
+ setupTitle: 'Setup JAVDB Cookie (Optional)',
59
+ setupDesc: 'You can use without configuration, but adding it improves coverage.',
60
+ setupSteps: 'Steps to get cookie:',
61
+ setupStep1: 'Open https://javdb.com in Chrome and log in',
62
+ setupStep2: 'Install extension "Get cookies.txt LOCALLY"',
63
+ setupStep3: 'Export cookies and find the _jdb_session line',
64
+ setupStep4: 'Copy the last column value and paste below',
65
+ setupPrompt: 'Paste the value of _jdb_session (press Enter to skip): ',
66
+ setupSkipped: 'Skipped. Using JAVBUS + JavLibrary as data sources.',
67
+ setupSuccess: 'Configuration saved successfully!',
68
+ setupSavePath: 'Saved to: ~/.config/javinfo/config.json',
43
69
  },
44
70
  jp: {
45
71
  actress: '女優',
@@ -59,8 +85,21 @@ export const messages = {
59
85
  notFound: '番号が見つかりません',
60
86
  queryFailed: '検索失敗',
61
87
  cacheCleared: 'キャッシュを削除しました',
62
- fc2Detected: 'FC2番号を変換しました',
88
+ cacheClearFailed: 'キャッシュの削除に失敗しました',
89
+ cachePath: 'キャッシュパス',
90
+ fc2Detected: 'FC2番号を検出しました',
63
91
  windowsHint: '注意: この番号はJAVDBが必要ですが、WindowsではJAVDBが利用できません。',
92
+ setupTitle: 'JAVDB Cookieの設定(オプション)',
93
+ setupDesc: '設定しなくても使用できますが、設定すると検索範囲が広がります。',
94
+ setupSteps: '取得手順:',
95
+ setupStep1: 'Chromeで https://javdb.com を開いてログイン',
96
+ setupStep2: '拡張機能 "Get cookies.txt LOCALLY" をインストール',
97
+ setupStep3: 'Cookieをエクスポートし、_jdb_session の行を探す',
98
+ setupStep4: '最後の列の値をコピーして以下に貼り付け',
99
+ setupPrompt: '_jdb_session の値を貼り付けてください(Enterでスキップ): ',
100
+ setupSkipped: 'スキップしました。JAVBUS + JavLibrary をデータソースとして使用します。',
101
+ setupSuccess: '設定を保存しました!',
102
+ setupSavePath: '保存場所: ~/.config/javinfo/config.json',
64
103
  },
65
104
  kr: {
66
105
  actress: '여배우',
@@ -80,8 +119,21 @@ export const messages = {
80
119
  notFound: '번호를 찾을 수 없습니다',
81
120
  queryFailed: '검색 실패',
82
121
  cacheCleared: '캐시가 삭제되었습니다',
83
- fc2Detected: 'FC2 번호 변환됨',
122
+ cacheClearFailed: '캐시 삭제 실패',
123
+ cachePath: '캐시 경로',
124
+ fc2Detected: 'FC2 형식 감지됨',
84
125
  windowsHint: '알림: 이 번호는 JAVDB가 필요하지만 Windows에서는 사용할 수 없습니다.',
126
+ setupTitle: 'JAVDB Cookie 설정 (선택사항)',
127
+ setupDesc: '설정하지 않아도 사용할 수 있지만, 설정하면 검색 범위가 넓어집니다.',
128
+ setupSteps: '획득 단계:',
129
+ setupStep1: 'Chrome에서 https://javdb.com 을 열고 로그인',
130
+ setupStep2: '확장 프로그램 "Get cookies.txt LOCALLY" 설치',
131
+ setupStep3: '쿠키를 내보내고 _jdb_session 줄을 찾기',
132
+ setupStep4: '마지막 열의 값을 복사하여 아래에 붙여넣기',
133
+ setupPrompt: '_jdb_session 값을 붙여넣어주세요 (Enter로 건너뛰기): ',
134
+ setupSkipped: '건너뛰었습니다. JAVBUS + JavLibrary를 데이터 소스로 사용합니다.',
135
+ setupSuccess: '설정이 성공적으로 저장되었습니다!',
136
+ setupSavePath: '저장 위치: ~/.config/javinfo/config.json',
85
137
  },
86
138
  de: {
87
139
  actress: 'Darstellerin',
@@ -101,8 +153,21 @@ export const messages = {
101
153
  notFound: 'Titel nicht gefunden',
102
154
  queryFailed: 'Suche fehlgeschlagen',
103
155
  cacheCleared: 'Cache geleert',
156
+ cacheClearFailed: 'Cache konnte nicht geleert werden',
157
+ cachePath: 'Cache-Pfad',
104
158
  fc2Detected: 'FC2-Format erkannt',
105
159
  windowsHint: 'Hinweis: Dieser Titel benötigt JAVDB, das unter Windows nicht verfügbar ist.',
160
+ setupTitle: 'JAVDB Cookie einrichten (optional)',
161
+ setupDesc: 'Ohne Konfiguration funktioniert es auch, aber mit Cookie ist die Abdeckung besser.',
162
+ setupSteps: 'Schritte zum Abrufen:',
163
+ setupStep1: 'Chrome öffnen, https://javdb.com aufrufen und anmelden',
164
+ setupStep2: 'Erweiterung "Get cookies.txt LOCALLY" installieren',
165
+ setupStep3: 'Cookies exportieren und die _jdb_session Zeile finden',
166
+ setupStep4: 'Den Wert der letzten Spalte kopieren und unten einfügen',
167
+ setupPrompt: 'Wert von _jdb_session einfügen (Enter zum Überspringen): ',
168
+ setupSkipped: 'Übersprungen. JAVBUS + JavLibrary werden als Datenquellen verwendet.',
169
+ setupSuccess: 'Konfiguration erfolgreich gespeichert!',
170
+ setupSavePath: 'Gespeichert unter: ~/.config/javinfo/config.json',
106
171
  },
107
172
  };
108
173
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javdict",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "AV番号命令行查询工具",
5
5
  "main": "./index.js",
6
6
  "type": "module",