Skip to content

Commit

Permalink
Merge pull request #43 from kenshinji/chore/refactoring
Browse files Browse the repository at this point in the history
chore: config.js refactoring
  • Loading branch information
kenshinji authored Oct 30, 2024
2 parents 090c8d2 + c1aec97 commit 41cb4f4
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
const pkg = require('../package.json')
const Configstore = require('configstore')
const isChinese = require('is-chinese')
const conf = new Configstore(pkg.name, { color: 'white', spinner: true })
let config = {
proxy: conf.get('proxy') ? conf.get('proxy') : undefined,

// 默认配置
const DEFAULT_CONFIG = {
color: 'white',
spinner: true,
proxy: undefined
}

// 初始化配置存储
const conf = new Configstore(pkg.name, DEFAULT_CONFIG)

// 有道词典 API 基础 URL
const YOUDAO_BASE_URL = 'https://dict.youdao.com/w'

const config = {
// 从存储中获取配置,如果没有则使用默认值
proxy: conf.get('proxy'),
spinner: conf.get('spinner'),
color: conf.get('color'),
getURL: function (word) {
return isChinese(word) ? 'https://dict.youdao.com/w/eng/' : 'https://dict.youdao.com/w/'

/**
* 根据输入词判断返回适当的查询 URL
* @param {string} word - 要查询的词
* @returns {string} 完整的查询 URL
*/
getURL (word) {
const path = isChinese(word) ? '/eng/' : '/'
return `${YOUDAO_BASE_URL}${path}`
}
}

Expand Down

0 comments on commit 41cb4f4

Please sign in to comment.