complete mobile image upload

This commit is contained in:
2024-12-18 01:08:25 +08:00
parent 58777e4b58
commit 24df28e53f
15 changed files with 526 additions and 136 deletions

View File

@@ -13,6 +13,7 @@ import (
oauth "schisandra-album-cloud-microservices/app/core/api/internal/handler/oauth"
sms "schisandra-album-cloud-microservices/app/core/api/internal/handler/sms"
token "schisandra-album-cloud-microservices/app/core/api/internal/handler/token"
upscale "schisandra-album-cloud-microservices/app/core/api/internal/handler/upscale"
user "schisandra-album-cloud-microservices/app/core/api/internal/handler/user"
websocket "schisandra-album-cloud-microservices/app/core/api/internal/handler/websocket"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
@@ -199,6 +200,22 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithMaxBytes(1048576),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/upload",
Handler: upscale.UploadImageHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/api/auth/upscale"),
rest.WithTimeout(10000*time.Millisecond),
rest.WithMaxBytes(10485760),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
@@ -233,6 +250,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/file",
Handler: websocket.FileWebsocketHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/message",

View File

@@ -0,0 +1,35 @@
package upscale
import (
"github.com/zeromicro/go-zero/core/logx"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/core/api/common/response"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/upscale"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
"schisandra-album-cloud-microservices/app/core/api/internal/types"
)
func UploadImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UploadRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := upscale.NewUploadImageLogic(r.Context(), svcCtx)
resp, err := l.UploadImage(r, &req)
if err != nil {
logx.Error(err)
httpx.WriteJsonCtx(
r.Context(),
w,
http.StatusInternalServerError,
response.ErrorWithI18n(r.Context(), "system.error"))
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,15 @@
package websocket
import (
"net/http"
"schisandra-album-cloud-microservices/app/core/api/internal/logic/websocket"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
func FileWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := websocket.NewFileWebsocketLogic(r.Context(), svcCtx)
l.FileWebsocket(w, r)
}
}