Skip to content

Commit e8c0ea2

Browse files
committed
Embed auth_upload.html into the binary and simplify AuthUploadPage logic
1 parent 613abf1 commit e8c0ea2

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

internal/api/handlers.go

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/chromedp/chromedp"
77
"github.com/luispater/anyAIProxyAPI/internal/browser/chrome"
88
"github.com/luispater/anyAIProxyAPI/internal/config"
9+
"github.com/luispater/anyAIProxyAPI/internal/html"
910
"github.com/luispater/anyAIProxyAPI/internal/runner"
1011
log "github.com/sirupsen/logrus"
1112
"github.com/tidwall/gjson"
@@ -508,31 +509,9 @@ func (h *APIHandlers) AuthDownload(c *gin.Context) {
508509

509510
// AuthUploadPage handles the GET /v1/auth/upload endpoint to serve the upload page
510511
func (h *APIHandlers) AuthUploadPage(c *gin.Context) {
511-
// Try to find the HTML file in different possible locations
512-
possiblePaths := []string{
513-
filepath.Join("internal", "html", "auth_upload.html"),
514-
filepath.Join("..", "internal", "html", "auth_upload.html"),
515-
"auth_upload.html", // fallback for tests
516-
}
517-
518-
var htmlContent []byte
519-
var err error
520-
521-
for _, htmlPath := range possiblePaths {
522-
htmlContent, err = os.ReadFile(htmlPath)
523-
if err == nil {
524-
break
525-
}
526-
}
527-
528-
if err != nil {
529-
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Failed to load upload page: %v", err), "code": 500})
530-
return
531-
}
532-
533512
// Serve the HTML content
534513
c.Header("Content-Type", "text/html; charset=utf-8")
535-
c.String(http.StatusOK, string(htmlContent))
514+
c.String(http.StatusOK, string(html.AuthUploadHTML))
536515
}
537516

538517
// AuthInstances handles the GET /v1/auth/instances endpoint to return available instances

internal/html/html.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package html
2+
3+
import _ "embed"
4+
5+
//go:embed auth_upload.html
6+
var AuthUploadHTML []byte

0 commit comments

Comments
 (0)