Compare commits

...
21 Commits
Author SHA1 Message Date
Vincent Young 491a2e7e5e Merge branch 'main' of https://github.com/OwO-Network/DeepLX 2023-04-23 13:25:52 +08:00
Vincent Young c4e7565703 feat: support for specified ports 2023-04-23 13:25:47 +08:00
Vincent Young bbf535e97b chore: switch to the robot release 2023-04-10 00:30:37 +08:00
Vincent Young f9f378e7eb docs: add python call example 2023-03-21 16:56:08 +08:00
Vincent Young d0310450e5 Create .github/FUNDING.yml 2023-03-18 19:05:31 +08:00
Vincent Young 80aaa94b06 Update README.md 2023-03-17 17:27:19 +08:00
Vincent Young 62befe706c docs: add docker compose v2 command
Update README.md
2023-03-17 17:23:41 +08:00
Davy b429e451dd Update README.md 2023-03-17 02:21:15 -07:00
Vincent Young cbd1507335 docs: modify to the latest response demo 2023-03-16 20:25:44 +08:00
Vincent Young db722920cd feat: return full alternatives 2023-03-16 20:23:21 +08:00
Vincent Young a5b256d7ad docs: not recommended for use on immersive 2023-03-07 04:58:17 +08:00
Vincent Young 6befe9c53d docs: detailed description 2023-03-07 04:40:44 +08:00
Vincent Young 1ecf4480d6 docs: fix guide 2023-03-07 04:10:38 +08:00
Vincent Young 6d4f38c051 chore: add docker-compose 2023-03-07 03:12:31 +08:00
Vincent Young b35c1d6622 docs: add dockerhub support 2023-03-07 03:05:22 +08:00
Vincent Young 70e64ad3b1 chore: fix dockerhub bug 2023-03-07 02:57:58 +08:00
Vincent Young 5be234ffd1 chore: add dockerhub 2023-03-07 02:53:59 +08:00
Vincent Young 7af10b4528 Merge pull request #28 from K024/feat/cors
feat: Add CORS middleware
2023-03-07 00:28:58 +08:00
K024 ca78976607 feat: Add CORS middleware 2023-03-07 00:19:27 +08:00
Vincent Young 865067066f Update README.md 2023-03-06 20:48:46 +08:00
Vincent Young 1dc48e6d3c docs: support docker 2023-03-06 20:48:26 +08:00
8 changed files with 188 additions and 21 deletions
+1
View File
@@ -0,0 +1 @@
custom: https://paypal.me/missuo
-2
View File
@@ -25,5 +25,3 @@ jobs:
draft: false draft: false
files: | files: |
dist/* dist/*
env:
GITHUB_TOKEN: ${{ secrets.GT_Token }}
+78
View File
@@ -0,0 +1,78 @@
name: Docker Image CI Dockerhub
on:
push:
branches:
- dev
tags:
- 'v*'
env:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: missuo/deeplx
jobs:
docker_build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
- name: Login to DockerHub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
type=pep440,pattern={{raw}},enable=${{ startsWith(github.ref, 'refs/tags/') }}
tpye=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
- name: Build dev branch and push
if: github.ref == 'refs/heads/dev'
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build release and push
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
+60 -11
View File
@@ -2,7 +2,7 @@
* @Author: Vincent Young * @Author: Vincent Young
* @Date: 2022-10-18 07:32:29 * @Date: 2022-10-18 07:32:29
* @LastEditors: Vincent Young * @LastEditors: Vincent Young
* @LastEditTime: 2023-03-03 02:30:52 * @LastEditTime: 2023-04-23 13:25:08
* @FilePath: /DeepLX/README.md * @FilePath: /DeepLX/README.md
* @Telegram: https://t.me/missuo * @Telegram: https://t.me/missuo
* *
@@ -12,10 +12,9 @@
Permanently free DeepL API written in Golang Permanently free DeepL API written in Golang
## Description ## Description
- `deeplx` in only run in port `1188`, later versions will do the specified port. - `DeepLX` is listening to `0.0.0.0:1188` by default. You can modify the listening port by yourself.
- `deeplx` is listening to `0.0.0.0:1188` by default. - `DeepLX` is using `DeepL` Free API.
- `deeplx` is using `DeepL` Free API. - `DeepLX` is unlimited to the number of requests.
- `deeplx` is unlimited to the number of requests.
## Usage ## Usage
### Request Parameters ### Request Parameters
@@ -26,11 +25,43 @@ Permanently free DeepL API written in Golang
### Response ### Response
```json ```json
{ {
"alternatives": [
"Undisputed",
"Unquestionable",
"Unquestionably"
],
"code": 200, "code": 200,
"data": "Hello world", "data": "Undoubtedly",
"id": 8305092005 "id": 8300079001
} }
``` ```
### Specify the port
**Thanks to [cijiugechu](https://github.com/cijiugechu) for [his contribution](https://github.com/OwO-Network/DeepLX/commit/4a0920579ea868b0f05ccdff6bceae316bfd5dc8) to make this feature possible for this project!**
```bash
./deeplx -p 3333
# or
./deeplx -port 3333
```
### Run with Docker
```bash
# ghcr.io
docker run -itd -p 1188:1188 ghcr.io/owo-network/deeplx:latest
# dockerhub
docker run -itd -p 1188:1188 missuo/deeplx:latest
```
### Run with Docker Compose
```bash
mkdir deeplx
cd deeplx
wget https://raw.githubusercontent.com/OwO-Network/DeepLX/main/docker-compose.yaml
# docker compose v1
docker-compose up -d
# or docker compose v2
docker compose up -d
```
### Run on Linux Server ### Run on Linux Server
```bash ```bash
@@ -53,7 +84,6 @@ brew services restart owo-network/brew/deeplx
brew list --versions deeplx brew list --versions deeplx
``` ```
#### Manual #### Manual
1. Download the latest release of DeepL X. 1. Download the latest release of DeepL X.
```bash ```bash
@@ -86,17 +116,36 @@ systemctl enable deeplx
## Setup on [Bob App](https://bobtranslate.com/) ## Setup on [Bob App](https://bobtranslate.com/)
1. Install [bob-plugin-deeplx](https://github.com/missuo/bob-plugin-deeplx) on Bob. 1. Install [bob-plugin-deeplx](https://github.com/missuo/bob-plugin-deeplx) on Bob.
2. Setup the API. 2. Setup the API. (If you use Brew to install locally you can skip this step)
![c5c19dd89df6fae1a256d](https://missuo.ru/file/c5c19dd89df6fae1a256d.png) ![c5c19dd89df6fae1a256d](https://missuo.ru/file/c5c19dd89df6fae1a256d.png)
## Setup on [immersive-translate](https://github.com/immersive-translate/immersive-translate) ## Setup on [immersive-translate](https://github.com/immersive-translate/immersive-translate)
**It is not recommended, because the `immersive-translate` will send many requests in a short time, which will cause the `DeepL API` to block your IP.**
1. Install Latest [immersive-translate ](https://github.com/immersive-translate/immersive-translate/releases) on your browser. 1. Install Latest [immersive-translate ](https://github.com/immersive-translate/immersive-translate/releases) on your browser.
2. Click on **Developer Settings** in the bottom left corner. **Enable Beta experimental features**. 2. Click on **Developer Settings** in the bottom left corner. **Enable Beta experimental features**.
3. Set the URL. 3. Set the URL. (If you are not deploying locally, you need to change 127.0.0.1 to the IP of your server)
![0779ecf8c7d7d1bee532b](https://missuo.ru/file/0779ecf8c7d7d1bee532b.png) ![6a48ba28621f2465028f0](https://missuo.ru/file/6a48ba28621f2465028f0.png)
## Use in Python
```python
import httpx, json
deeplx_api = "http://127.0.0.1:1188/translate"
data = {
"text": "Hello World",
"source_lang": "EN",
"target_lang": "ZH"
}
post_data = json.dumps(data)
r = httpx.post(url = deeplx_api, data = post_data).text
print(r)
```
## Backup the Docker Image of zu1k ## Backup the Docker Image of zu1k
```shell ```shell
+8
View File
@@ -0,0 +1,8 @@
version: '3'
services:
deeplx:
image: ghcr.io/owo-network/deeplx:latest
restart: always
ports:
- "1188:1188"
+3 -1
View File
@@ -1,14 +1,16 @@
module github.com/OwO-Network/deepl-api module github.com/OwO-Network/DeepLX
go 1.19 go 1.19
require ( require (
github.com/abadojack/whatlanggo v1.0.1 github.com/abadojack/whatlanggo v1.0.1
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.8.1 github.com/gin-gonic/gin v1.8.1
github.com/tidwall/gjson v1.14.3 github.com/tidwall/gjson v1.14.3
) )
require ( require (
github.com/Jeffail/gabs/v2 v2.7.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect
+9 -2
View File
@@ -1,9 +1,13 @@
github.com/Jeffail/gabs/v2 v2.7.0 h1:Y2edYaTcE8ZpRsR2AtmPu5xQdFDIthFG0jYhu5PY8kg=
github.com/Jeffail/gabs/v2 v2.7.0/go.mod h1:dp5ocw1FvBBQYssgHsG7I1WYsiLRtkUaB1FEtSwvNUw=
github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4= github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc= github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
@@ -49,11 +53,13 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
@@ -94,5 +100,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+29 -5
View File
@@ -3,6 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"flag"
"fmt" "fmt"
"io" "io"
"log" "log"
@@ -12,11 +13,22 @@ import (
"time" "time"
"github.com/abadojack/whatlanggo" "github.com/abadojack/whatlanggo"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
var port int
func init() { func init() {
const (
defaultPort = 1188
usage = "set up the port to listen on"
)
flag.IntVar(&port, "port", defaultPort, usage)
flag.IntVar(&port, "p", defaultPort, usage)
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
} }
@@ -97,8 +109,11 @@ type ResData struct {
} }
func main() { func main() {
// parse flags
flag.Parse()
// display information // display information
fmt.Println("DeepL X has been successfully launched! Listening on 0.0.0.0:1188") fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", port)
fmt.Println("Made by sjlleo and missuo.") fmt.Println("Made by sjlleo and missuo.")
// create a random id // create a random id
@@ -107,6 +122,7 @@ func main() {
// set release mode // set release mode
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
r := gin.Default() r := gin.Default()
r.Use(cors.Default())
r.GET("/", func(c *gin.Context) { r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
@@ -191,6 +207,7 @@ func main() {
body, _ := io.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
res := gjson.ParseBytes(body) res := gjson.ParseBytes(body)
// display response // display response
// fmt.Println(res) // fmt.Println(res)
if res.Get("error.code").String() == "-32600" { if res.Get("error.code").String() == "-32600" {
@@ -208,13 +225,20 @@ func main() {
"message": "Too Many Requests", "message": "Too Many Requests",
}) })
} else { } else {
var alternatives []string
res.Get("result.texts.0.alternatives").ForEach(func(key, value gjson.Result) bool {
alternatives = append(alternatives, value.Get("text").String())
return true
})
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": http.StatusOK, "code": http.StatusOK,
"id": id, "id": id,
"data": res.Get("result.texts.0.text").String(), "data": res.Get("result.texts.0.text").String(),
"alternatives": alternatives,
}) })
} }
} }
}) })
r.Run(":1188") // listen and serve on 0.0.0.0:1188 // by default, listen and serve on 0.0.0.0:1188
r.Run(fmt.Sprintf(":%v", port))
} }