Compare commits

...

6 Commits
v1.2.2 ... main

Author SHA1 Message Date
Bonny Lin
88a00874c8
fix(install): detect architecture instead of hardcoding amd64 (#227)
install.sh always downloaded the linux_amd64 binary, so arm64/386/mips machines got a binary that does not run. Detect the architecture via uname and pick the matching release artifact; releases already ship those builds.
2026-06-07 17:45:46 +08:00
Bonny Lin
231393c669
ci(release): build cross-platform binaries in parallel via matrix (#226)
The release job ran .cross_compile.sh, which builds all 12 targets sequentially in a single runner. Split the build into a matrix so each GOOS/GOARCH pair builds concurrently on its own runner, then a dependent Release job collects the artifacts and publishes them in one release. Output filenames are unchanged.
2026-06-05 11:10:47 +08:00
Vincent Young
9d6b294a61
fix(service): log translation errors and hide internals from clients
Return a generic "Translation failed" message instead of echoing
err.Error() in the HTTP response, and log the underlying error
server-side via log.Printf. Avoids leaking internal details (proxy
address, upstream URL, etc.) to API clients while keeping the 500
behavior introduced in #224.
2026-06-02 14:38:02 +08:00
Bonny Lin
d19a3902df
fix(service): validate request body on /translate and /v1/translate (#225)
The two handlers ignored the error from c.BindJSON, so a malformed JSON body was silently processed as an empty payload. Check the error and return 400, consistent with /v2/translate.
2026-06-02 14:32:22 +08:00
Bonny Lin
3f099d187c
fix(service): return 500 instead of crashing on translation error (#224)
The /translate, /v1/translate and /v2/translate handlers called log.Fatalf when TranslateByDeepLX returned an error. log.Fatalf calls os.Exit, so a single failed translation would tear down the whole server process. Return a 500 JSON response and keep serving instead.
2026-05-31 03:47:09 -07:00
趙子賢
1b88e428ae
feat(docker): non-root user + ENTRYPOINT (#222)
Closes #221.

- Run as non-root using an Alpine system account (UID auto-assigned from the 100-999 system range, referenced by name to avoid hard-coding).
- Replace CMD with ENTRYPOINT so args passed to `docker run` flow through to the deeplx binary.
- EXPOSE 1188 for documentation.
2026-05-24 01:30:05 +08:00
4 changed files with 100 additions and 12 deletions

View File

@ -5,11 +5,28 @@ on:
pull_request: pull_request:
name: Release name: Release
jobs: jobs:
Build: Build:
if: startsWith(github.ref, 'refs/tags/v') if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { goos: darwin, goarch: amd64 }
- { goos: darwin, goarch: arm64 }
- { goos: linux, goarch: '386' }
- { goos: linux, goarch: amd64 }
- { goos: linux, goarch: arm64 }
- { goos: linux, goarch: mips }
- { goos: openbsd, goarch: amd64 }
- { goos: openbsd, goarch: arm64 }
- { goos: freebsd, goarch: amd64 }
- { goos: freebsd, goarch: arm64 }
- { goos: windows, goarch: '386' }
- { goos: windows, goarch: amd64 }
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -17,12 +34,40 @@ jobs:
with: with:
go-version: "1.24.2" go-version: "1.24.2"
- run: bash .cross_compile.sh - name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
run: |
mkdir -p dist
BINARY="dist/deeplx_${GOOS}_${GOARCH}"
if [ "${GOOS}" = "windows" ]; then
BINARY="${BINARY}.exe"
fi
go build -trimpath -ldflags "-w -s" -o "${BINARY}" .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: deeplx_${{ matrix.goos }}_${{ matrix.goarch }}
path: dist/*
if-no-files-found: error
Release:
needs: Build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Release - name: Release
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
draft: false draft: false
generate_release_notes: true generate_release_notes: true
files: | files: dist/*
dist/*

View File

@ -6,5 +6,8 @@ RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o deeplx .
FROM alpine:latest FROM alpine:latest
WORKDIR /app WORKDIR /app
COPY --from=builder /go/src/github.com/OwO-Network/DeepLX/deeplx /app/deeplx RUN addgroup -S deeplx && adduser -h /app -G deeplx -SH deeplx
CMD ["/app/deeplx"] USER deeplx:deeplx
COPY --from=builder --chown=deeplx:deeplx /go/src/github.com/OwO-Network/DeepLX/deeplx /app/deeplx
EXPOSE 1188
ENTRYPOINT ["/app/deeplx"]

View File

@ -16,7 +16,20 @@ install_deeplx(){
exit 1 exit 1
fi fi
echo -e "DeepLX latest version: ${last_version}, Start install..." echo -e "DeepLX latest version: ${last_version}, Start install..."
wget -q -N --no-check-certificate -O /usr/bin/deeplx https://github.com/OwO-Network/DeepLX/releases/download/${last_version}/deeplx_linux_amd64
arch=$(uname -m)
case "${arch}" in
x86_64 | amd64) file_arch="amd64" ;;
aarch64 | arm64) file_arch="arm64" ;;
i386 | i686) file_arch="386" ;;
mips) file_arch="mips" ;;
*)
echo -e "${red}Unsupported architecture: ${arch}${plain}"
exit 1
;;
esac
wget -q -N --no-check-certificate -O /usr/bin/deeplx https://github.com/OwO-Network/DeepLX/releases/download/${last_version}/deeplx_linux_${file_arch}
chmod +x /usr/bin/deeplx chmod +x /usr/bin/deeplx
wget -q -N --no-check-certificate -O /etc/systemd/system/deeplx.service https://raw.githubusercontent.com/OwO-Network/DeepLX/main/deeplx.service wget -q -N --no-check-certificate -O /etc/systemd/system/deeplx.service https://raw.githubusercontent.com/OwO-Network/DeepLX/main/deeplx.service

View File

@ -108,7 +108,13 @@ func Router(cfg *Config) *gin.Engine {
// Free API endpoint, No Pro Account required // Free API endpoint, No Pro Account required
r.POST("/translate", authMiddleware(cfg), func(c *gin.Context) { r.POST("/translate", authMiddleware(cfg), func(c *gin.Context) {
req := PayloadFree{} req := PayloadFree{}
c.BindJSON(&req) if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
"message": "Invalid request payload",
})
return
}
sourceLang := req.SourceLang sourceLang := req.SourceLang
targetLang := req.TargetLang targetLang := req.TargetLang
@ -127,7 +133,12 @@ func Router(cfg *Config) *gin.Engine {
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, "") result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, "")
if err != nil { if err != nil {
log.Fatalf("Translation failed: %s", err) log.Printf("Translation failed: %s", err)
c.JSON(http.StatusInternalServerError, gin.H{
"code": http.StatusInternalServerError,
"message": "Translation failed",
})
return
} }
if result.Code == http.StatusOK { if result.Code == http.StatusOK {
@ -152,7 +163,13 @@ func Router(cfg *Config) *gin.Engine {
// Pro API endpoint, Pro Account required // Pro API endpoint, Pro Account required
r.POST("/v1/translate", authMiddleware(cfg), func(c *gin.Context) { r.POST("/v1/translate", authMiddleware(cfg), func(c *gin.Context) {
req := PayloadFree{} req := PayloadFree{}
c.BindJSON(&req) if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
"message": "Invalid request payload",
})
return
}
sourceLang := req.SourceLang sourceLang := req.SourceLang
targetLang := req.TargetLang targetLang := req.TargetLang
@ -191,7 +208,12 @@ func Router(cfg *Config) *gin.Engine {
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, dlSession) result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, dlSession)
if err != nil { if err != nil {
log.Fatalf("Translation failed: %s", err) log.Printf("Translation failed: %s", err)
c.JSON(http.StatusInternalServerError, gin.H{
"code": http.StatusInternalServerError,
"message": "Translation failed",
})
return
} }
if result.Code == http.StatusOK { if result.Code == http.StatusOK {
@ -243,7 +265,12 @@ func Router(cfg *Config) *gin.Engine {
result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", proxyURL, "") result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", proxyURL, "")
if err != nil { if err != nil {
log.Fatalf("Translation failed: %s", err) log.Printf("Translation failed: %s", err)
c.JSON(http.StatusInternalServerError, gin.H{
"code": http.StatusInternalServerError,
"message": "Translation failed",
})
return
} }
if result.Code == http.StatusOK { if result.Code == http.StatusOK {