fix: remove 500 error responses from upload endpoints; fix: return validation error strings instead of error lists; fix: handle invalid avatar upload IDs with 400 Bad Request response; fix: add missing S3Controller to controller initialization; fix: change avatar_upload_id to string type and update validation rules; chore: add license header to smtp.go; refactor: replace manual proxy implementation with httputil.ReverseProxy; fix: inject S3Service dependency into ProfileService; fix: set color and color_grad fields during profile update; fix: correct DTO mapping for profile and settings; fix: check object existence before copying in SaveUpload; fix: adjust profile DTO mapping function for proper pointer handling
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
// Copyright (c) 2025 Nikolai Papin
|
|
//
|
|
// This file is part of Easywish
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
|
// the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
package minioclient
|
|
|
|
import (
|
|
"easywish/config"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func setupGinEndpoint(router *gin.Engine) {
|
|
cfg := config.GetConfig()
|
|
minioHost := fmt.Sprintf("%s:%d", cfg.MinioHost, cfg.MinioPort)
|
|
|
|
proxy := &httputil.ReverseProxy{
|
|
Director: func(req *http.Request) {
|
|
path := strings.TrimPrefix(req.URL.Path, "/s3")
|
|
targetURL := &url.URL{
|
|
Scheme: "http",
|
|
Host: minioHost,
|
|
Path: path,
|
|
RawQuery: req.URL.RawQuery,
|
|
}
|
|
|
|
req.URL = targetURL
|
|
req.Host = minioHost
|
|
req.Header.Set("Host", minioHost)
|
|
|
|
req.Header.Del("X-Forwarded-For")
|
|
req.Header.Del("X-Forwarded-Host")
|
|
req.Header.Del("X-Forwarded-Proto")
|
|
},
|
|
Transport: &http.Transport{
|
|
ResponseHeaderTimeout: time.Duration(cfg.MinioTimeout),
|
|
},
|
|
ErrorHandler: func(w http.ResponseWriter, r *http.Request, err error) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
w.Write([]byte(`{"error": "Failed to forward request"}`))
|
|
fmt.Printf("Proxy error: %v\n", err)
|
|
},
|
|
}
|
|
|
|
s3group := router.Group("/s3")
|
|
s3group.Any("/*path", func(c *gin.Context) {
|
|
proxy.ServeHTTP(c.Writer, c.Request)
|
|
})
|
|
}
|