Compare commits

...
3 Commits
Author SHA1 Message Date
Vincent Young 41bba5e89f Update release.yaml 2024-03-07 09:56:46 -05:00
Vincent Young e286a732cb docs: fix token usage 2024-03-07 09:49:14 -05:00
chenxiaolei 6db098eb8b feat: support for getting token from url parameter (#95)
* support for getting token from url parameter

* support for getting token from url parameter
improve docs
2024-03-07 02:10:51 -05:00
3 changed files with 15 additions and 4 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ jobs:
Build: Build:
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/v')
runs-on: self-hosted runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
+11 -1
View File
@@ -67,7 +67,7 @@
### Custom Options ### Custom Options
**The following settings are optional and not required.** **The following settings are optional and not required.**
- `-port` or `-p` : Listening port. Default is `1188`. - `-port` or `-p` : Listening port. Default is `1188`.
- `-token` : Access token. If you have set it up, each request will need to include an `Authorization` header. - `-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. - `-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.
#### Requesting a token-protected **DeepLX API** instance using the `curl` #### Requesting a token-protected **DeepLX API** instance using the `curl`
@@ -81,6 +81,16 @@ curl -X POST http://localhost:1188/translate \
"target_lang": "DE" "target_lang": "DE"
}' }'
``` ```
or
```
curl -X POST http://localhost:1188/translate?token=your_access_token \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, world!",
"source_lang": "EN",
"target_lang": "DE"
}'
```
### Run with Docker ### Run with Docker
```bash ```bash
+3 -2
View File
@@ -274,8 +274,9 @@ func main() {
c.BindJSON(&req) c.BindJSON(&req)
if cfg.Token != "" { if cfg.Token != "" {
providedToken := c.GetHeader("Authorization") providedTokenInQuery := c.Query("token")
if providedToken != "Bearer "+cfg.Token { providedTokenInHeader := c.GetHeader("Authorization")
if providedTokenInHeader != "Bearer "+cfg.Token && providedTokenInQuery != cfg.Token {
c.JSON(http.StatusUnauthorized, gin.H{ c.JSON(http.StatusUnauthorized, gin.H{
"code": http.StatusUnauthorized, "code": http.StatusUnauthorized,
"message": "Invalid access token", "message": "Invalid access token",