ding-trans
Advanced tools
Comparing version 1.1.1 to 1.1.2
#! /usr/bin/env node | ||
require("colors"); | ||
const { axios } = require("./request"); | ||
const say = require("say"); | ||
const querystring = require("querystring"); | ||
@@ -27,8 +26,2 @@ const argv = require("yargs").argv; | ||
} else { | ||
//播放 | ||
if (argv.say == true || argv.S == true) { | ||
console.log("播放中...".rainbow); | ||
say.speak(querystring.unescape(queryStr)); | ||
return; | ||
} | ||
//查词 | ||
@@ -39,5 +32,7 @@ sendInfo(querystring.unescape(queryStr)); | ||
function sendInfo(queryStr) { | ||
const targetLang = escape(queryStr).indexOf("%u") < 0 ? "ZH" : "EN"; | ||
// console.log("🚀🚀🚀 / queryStr", queryStr, escape(queryStr), targetLang); | ||
axios | ||
.post("http://47.95.239.198:9521/translate", { | ||
data: { text: queryStr, source_lang: "auto", target_lang: "ZH" }, | ||
data: { text: queryStr, source_lang: "auto", target_lang: targetLang }, | ||
}) | ||
@@ -44,0 +39,0 @@ .then((res) => { |
@@ -5,2 +5,3 @@ #! /usr/bin/env node | ||
const querystring = require("querystring"); | ||
const http = require("http"); | ||
const argv = require("yargs").argv; | ||
@@ -67,15 +68,17 @@ // 对驼峰的连续单词进行分割后转义 | ||
} | ||
// 获取请求的参数 | ||
function getOptions(queryStr) { | ||
// 用于请求的选项 | ||
// let options = { | ||
// host: "fanyi.youdao.com", | ||
// port: "80", | ||
// path: | ||
// "/openapi.do?keyfrom=translation-tool&key=1730699468&type=data&doctype=json&version=1.1&q=" + | ||
// queryStr, | ||
// }; | ||
let options = `http://aidemo.youdao.com/trans?q=${queryStr}&&from=Auto&&to=Auto`; | ||
return options | ||
} | ||
//发送请求 | ||
function sendInfo(query) { | ||
//发送翻译请求 | ||
let http = require("http"); | ||
// 1.用于请求的选项 | ||
let options = { | ||
host: "fanyi.youdao.com", | ||
port: "80", | ||
path: | ||
"/openapi.do?keyfrom=translation-tool&key=1730699468&type=data&doctype=json&version=1.1&q=" + | ||
query, | ||
}; | ||
// let options = ` http://aidemo.youdao.com/trans?q=${query}&&from=Auto&&to=Auto`; | ||
function sendInfo(queryStr) { | ||
// 处理响应的回调函数 | ||
@@ -92,4 +95,4 @@ let callback = function (response) { | ||
// 向服务端发送请求 | ||
let req = http.request(options, callback); | ||
let req = http.request(getOptions(queryStr), callback); | ||
req.end(); | ||
} |
{ | ||
"name": "ding-trans", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "a translation cli", | ||
@@ -8,2 +8,3 @@ "main": "index.js", | ||
"ding": "./bin/translate.js", | ||
"preinstall": "npx npm-limit yarn", | ||
"dd": "./bin/deepl-translate.js" | ||
@@ -10,0 +11,0 @@ }, |
@@ -0,0 +0,0 @@ # ding-trans (ding 翻译) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6988
174