diff --git a/.gitignore b/.gitignore index 5fc739f..f04cc2a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ lerna-debug.log* node_modules/ yarn.lock -package-lock.json \ No newline at end of file +package-lock.json + +dist.zip \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a756f72 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 LegendLeo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..73b3a76 --- /dev/null +++ b/README.md @@ -0,0 +1,91 @@ +# DeepLX Serverless + +DeepLX 免费翻译API**腾讯云函数部署版**,与[原项目DeepLX](https://github.com/OwO-Network/DeepLX)的区别在于**利用了云函数的请求IP不固定的特性,极大程度上避免了`429`请求太频繁报错** + +感谢原项目[OwO-Network/DeepLX](https://github.com/OwO-Network/DeepLX)提供的灵感,这是本项目的坚实基础 + +## Usage | 用法 + +### Prerequisites | 你需要准备什么 + +- 一台电脑或平板 +- 一个腾讯旗下的账号或者手机号 + +### Deploy | 部署 + +在 [https://cloud.tencent.com/](https://cloud.tencent.com/) 注册账号 + +进入云函数控制台:[https://console.cloud.tencent.com/scf/list](https://console.cloud.tencent.com/scf/list) + +依次点击【新建】->【从头开始】,然后按照以下配置,**没写出来的就不用管,使用默认设置** + +- 函数类型:Web函数 +- 函数名称:deeplx(名字随便取) +- 地域:任意(国内也可直连) +- 运行环境:Nodejs 16.13(或者更高的版本) +- 高级配置: + - 内存:64M + - 执行超时时间:60 秒 + - 请求多并发:5 并发(个人体验下来,2个都行) +- 日志配置 -> 日志投递:启用(可以选择不开,开的话一个月应该几分钱) +- 函数代码:本地上传zip包([点我下载 ZIP 包](https://github.com/LegendLeo/deeplx-serverless/releases/download/v1.0.0/dist.zip)) +- 触发器配置(这里可能要创建一个新的触发器): + - 默认触发器 + - 触发别名/版本:默认流量 + - 请求方法:ANY + - 发布环境:发布 + - 鉴权方法:免鉴权 + +此时已部署完成,可以点击“完成”按钮,进入【函数管理】,点击【函数代码】,往下拉,找到【访问路径】并复制后续使用 + + +### How to use | 如何使用 + +建议搭配浏览器插件沉浸式翻译一同使用,使用的时候需要把访问路径里的 `/release` 部分替换为翻译路径`translate` + +例如:`https://service-aaaaa.gz.apigw.tencentcs.com/release/` 改为:`https://service-aaaaa.gz.apigw.tencentcs.com/translate` + +请求示例: + +``` bash +curl --location 'https://service-aaaaa.gz.apigw.tencentcs.com/translate' \ +--header 'Content-Type: application/json' \ +--data '{ + "text": "你好,世界", + "source_lang": "zh", + "target_lang": "en" +}' +``` + +响应示例: + +``` json +{ + "code": 200, + "message": "success", + "data": "Hello, world.", + "source_lang": "zh", + "target_lang": "en", + "alternatives": ["Hello, World.", "Hello, world!", "Hi, world."] +} +``` + +#### 沉浸式翻译设置 + +1. 在浏览器上安装最新的 [沉浸式翻译](https://github.com/immersive-translate/immersive-translate/releases)。 +2. 点击左下角的 "开发者设置"。启用测试版实验功能。 +3. 翻译服务选中 `DeepLX(beta)` +3. 设置 URL 为刚才获取的访问路径(需带translate)。 + +![沉浸式翻译](https://github.com/LegendLeo/deeplx-serverless/assets/25115173/d3affe2b-9e99-4d5c-bc8c-cd67e70d0368) + +## 自托管 + +尽管本项目是专为 serverless 适配的方案,但是也能使用自己提供服务器进行部署 + +``` bash +git clone https://github.com/LegendLeo/deeplx-serverless +cd deeplx-serverless +npm install +npm run start +``` diff --git a/package.json b/package.json index b55f30f..f53205b 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,19 @@ { - "name": "deepl", + "name": "deeplx-serverless", "version": "1.0.0", - "description": "", - "main": "index.js", + "description": "DeepLX Free API for serverless", + "main": "translate.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node server.js", + "zip": "zip -r dist.zip ./" }, - "keywords": [], - "author": "", - "license": "ISC", + "keywords": [ + "deeplx", + "deepl", + "translate", + "serverless" + ], + "license": "MIT", "dependencies": { "axios": "^1.6.3", "body-parser": "^1.20.2",