Skip to content

Commit

Permalink
feat: support pro account
Browse files Browse the repository at this point in the history
  • Loading branch information
missuo committed Apr 23, 2024
1 parent 90d4d44 commit a76d888
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 328 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
FROM golang:1.22 AS builder
WORKDIR /go/src/github.com/OwO-Network/DeepLX
COPY main.go ./
COPY dto.go ./
COPY types.go ./
COPY utils.go ./
COPY config.go ./
COPY translate.go ./
COPY go.mod ./
COPY go.sum ./
RUN go get -d -v ./
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!--
* @Author: Vincent Young
* @Date: 2022-10-18 07:32:29
* @LastEditors: Vincent Young
* @LastEditTime: 2024-04-16 15:10:38
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-04-23 00:47:59
* @FilePath: /DeepLX/README.md
* @Telegram: https://t.me/missuo
*
Expand Down Expand Up @@ -69,8 +69,10 @@
- `-port` or `-p` : Listening port. Default is `1188`.
- `-token` : Access token. If you have set it up, each request needs to include `Authorization` in the **Headers** or `token` parameter in the **URL Params**.
- `-authkey` : DeepL Official `AuthKey`. If you have set it up, after the 429 response, the official AuthKey will be used for the request. If multiple authKeys are used simultaneously, they need to be separated by commas.
- `s`: `dl-session` is the cookie for a **DeepL Pro** account. If you set this, you will be able to use another endpoint `/v1/translate`, which can effectively avoid 429.
- `/v2/translate` : This endpoint is fully compatible with the DeepL official API. When using this endpoint, please strictly adhere to the request styles outlined in the official DeepL documentation. Note that in this endpoint, please use `DeepL-Auth-Key $token` in the `Authorization`, which is actually the Access Token, not the official `Auth Key` of DeepL.


#### Example of requesting a token-protected `/v2/translate` endpoint
```bash
curl -X POST 'http://localhost:1188/v2/translate' \
Expand Down Expand Up @@ -113,13 +115,13 @@ curl -X POST http://localhost:1188/translate?token=your_access_token \
docker run -itd -p 1188:1188 ghcr.io/owo-network/deeplx:latest

# custom environment variables
docker run -itd -p 1188:1188 -e "TOKEN=helloxxx" -e "AUTHKEY=xxxx:fx" ghcr.io/owo-network/deeplx:latest
docker run -itd -p 1188:1188 -e "TOKEN=helloxxx" -e "AUTHKEY=xxxx:fx" -e "DL_SESSION=xxxxx" ghcr.io/owo-network/deeplx:latest

# dockerhub
docker run -itd -p 1188:1188 missuo/deeplx:latest

# custom environment variables
docker run -itd -p 1188:1188 -e "TOKEN=helloxxx" -e "AUTHKEY=xxxx:fx" missuo/deeplx:latest
docker run -itd -p 1188:1188 -e "TOKEN=helloxxx" -e "AUTHKEY=xxxx:fx" -e "DL_SESSION=xxxxx" missuo/deeplx:latest
```

### Run with Docker Compose
Expand All @@ -131,6 +133,7 @@ wget https://raw.githubusercontent.com/OwO-Network/DeepLX/main/compose.yaml
# environment:
# - TOKEN=helloxxx
# - AUTHKEY=xxxxxxx:fx
# - DL_SESSION=xxxxx
# docker compose
docker compose up -d
```
Expand Down
3 changes: 2 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ services:
- "1188:1188"
# environment:
# - TOKEN=helloworld
# - AUTHKEY=xxxxxxx:fx
# - AUTHKEY=xxxxxxx:fx
# - DL_SESSION=xxxxxx
55 changes: 55 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* @Author: Vincent Yang
* @Date: 2024-04-23 00:39:03
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-04-23 00:43:43
* @FilePath: /DeepLX/config.go
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
*
* Copyright © 2024 by Vincent, All Rights Reserved.
*/

package main

import (
"flag"
"os"
)

func initConfig() *Config {
cfg := &Config{
Port: 1188,
}

// Port flag
flag.IntVar(&cfg.Port, "port", cfg.Port, "set up the port to listen on")
flag.IntVar(&cfg.Port, "p", cfg.Port, "set up the port to listen on")

// DL Session flag
flag.StringVar(&cfg.DlSession, "s", "", "set the dl-session for /v1/translate endpoint")
if cfg.DlSession == "" {
if dlSession, ok := os.LookupEnv("DL_SESSION"); ok {
cfg.DlSession = dlSession
}
}

// Access token flag
flag.StringVar(&cfg.Token, "token", "", "set the access token for /translate endpoint")
if cfg.Token == "" {
if token, ok := os.LookupEnv("TOKEN"); ok {
cfg.Token = token
}
}

// DeepL Official Authentication key flag
flag.StringVar(&cfg.AuthKey, "authkey", "", "The authentication key for DeepL API")
if cfg.AuthKey == "" {
if authKey, ok := os.LookupEnv("AUTHKEY"); ok {
cfg.AuthKey = authKey
}
}

flag.Parse()
return cfg
}
Loading

0 comments on commit a76d888

Please sign in to comment.