add fix for donate page by avatar
This commit is contained in:
parent
c4bebf0ffa
commit
eb61fd899c
@ -220,10 +220,8 @@ func GetOuterDonatePage(donatService model.DonatService) echo.HandlerFunc {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
streamerLogin := request.Param("streamer-login")
|
streamerLogin := request.Param("streamer-login")
|
||||||
|
|
||||||
accessToken := model.Token(request.Request().Header.Get("Authorization"))
|
|
||||||
|
|
||||||
outerPageResponse, err := donatService.GetOuterDonatPage(
|
outerPageResponse, err := donatService.GetOuterDonatPage(
|
||||||
ctx, streamerLogin, string(accessToken),
|
ctx, streamerLogin,
|
||||||
)
|
)
|
||||||
if outerPageResponse.Login == "" {
|
if outerPageResponse.Login == "" {
|
||||||
return echo.NewHTTPError(http.StatusNotFound, "Пользователь не найден!")
|
return echo.NewHTTPError(http.StatusNotFound, "Пользователь не найден!")
|
||||||
|
@ -81,7 +81,7 @@ type DonatService interface {
|
|||||||
MarkDonatView(ctx context.Context, orderID string) error
|
MarkDonatView(ctx context.Context, orderID string) error
|
||||||
|
|
||||||
GetInnerDonatPage(ctx context.Context, streamerID int, token string) (InnerDonatePageResponse, error)
|
GetInnerDonatPage(ctx context.Context, streamerID int, token string) (InnerDonatePageResponse, error)
|
||||||
GetOuterDonatPage(ctx context.Context, streamerLogin string, token string) (OuterDonatePageResponse, error)
|
GetOuterDonatPage(ctx context.Context, streamerLogin string) (OuterDonatePageResponse, error)
|
||||||
UpdateDonatePage(
|
UpdateDonatePage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerID int,
|
streamerID int,
|
||||||
@ -252,6 +252,7 @@ type FileService interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StreamerClient interface {
|
type StreamerClient interface {
|
||||||
GetAvatarID(token string) (string, error)
|
GetAvatarIdByToken(token string) (string, error)
|
||||||
|
GetAvatarById(accountId string) (string, error)
|
||||||
UpdateAvatarID(token string, avatarUUID string) error
|
UpdateAvatarID(token string, avatarUUID string) error
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,7 @@ SELECT
|
|||||||
dp.description,
|
dp.description,
|
||||||
dp.text_after_donat,
|
dp.text_after_donat,
|
||||||
dp.streamer_login,
|
dp.streamer_login,
|
||||||
|
dp.profile_avatar,
|
||||||
|
|
||||||
-- Поля для хед-изображения
|
-- Поля для хед-изображения
|
||||||
head_img.id AS head_img_id,
|
head_img.id AS head_img_id,
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceDonat struct {
|
type ServiceDonat struct {
|
||||||
@ -217,7 +218,7 @@ func (donatService *ServiceDonat) GetInnerDonatPage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if donatePage.ProfileAvatar == true {
|
if donatePage.ProfileAvatar == true {
|
||||||
fileId, err := donatService.streamerClient.GetAvatarID(token)
|
fileId, err := donatService.streamerClient.GetAvatarIdByToken(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
}
|
}
|
||||||
@ -260,7 +261,6 @@ func (donatService *ServiceDonat) GetInnerDonatPage(
|
|||||||
func (donatService *ServiceDonat) GetOuterDonatPage(
|
func (donatService *ServiceDonat) GetOuterDonatPage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerLogin string,
|
streamerLogin string,
|
||||||
token string,
|
|
||||||
) (model.OuterDonatePageResponse, error) {
|
) (model.OuterDonatePageResponse, error) {
|
||||||
donatePage, err := donatService.donatRepo.GetDonatPageByLogin(ctx, streamerLogin)
|
donatePage, err := donatService.donatRepo.GetDonatPageByLogin(ctx, streamerLogin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -271,7 +271,17 @@ func (donatService *ServiceDonat) GetOuterDonatPage(
|
|||||||
avatarFileId := donatePage.AvatarFileId
|
avatarFileId := donatePage.AvatarFileId
|
||||||
|
|
||||||
if donatePage.ProfileAvatar == true {
|
if donatePage.ProfileAvatar == true {
|
||||||
fileId, err := donatService.streamerClient.GetAvatarID(token)
|
donatModel, err := donatService.donatRepo.GetDonatPageByLogin(ctx, streamerLogin)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(err.Error())
|
||||||
|
}
|
||||||
|
streamerID := donatModel.StreamerID
|
||||||
|
if streamerID == 0 {
|
||||||
|
slog.Error("Account by login not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
fileId, err := donatService.streamerClient.GetAvatarById(strconv.Itoa(streamerID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
avatarFileId = donatePage.AvatarFileId
|
avatarFileId = donatePage.AvatarFileId
|
||||||
|
@ -71,7 +71,7 @@ func (c *ClientStreamer) UpdateAvatarID(token string, avatarUUID string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientStreamer) GetAvatarID(token string) (string, error) {
|
func (c *ClientStreamer) GetAvatarIdByToken(token string) (string, error) {
|
||||||
const endpoint = "/info"
|
const endpoint = "/info"
|
||||||
var result model.StreamerInfo
|
var result model.StreamerInfo
|
||||||
|
|
||||||
@ -115,6 +115,49 @@ func (c *ClientStreamer) GetAvatarID(token string) (string, error) {
|
|||||||
return extractFileID(result.Avatar), nil
|
return extractFileID(result.Avatar), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ClientStreamer) GetAvatarById(accountId string) (string, error) {
|
||||||
|
var endpoint = "/info" + "/" + accountId
|
||||||
|
var result model.StreamerInfo
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", c.baseURL+endpoint, nil)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("create request failed", "error", err)
|
||||||
|
return "", fmt.Errorf("request creation error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Accept", "application/json")
|
||||||
|
|
||||||
|
resp, err := c.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("request failed", "error", err)
|
||||||
|
return "", fmt.Errorf("HTTP request error: %w", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
slog.Error("unexpected status code",
|
||||||
|
"status", resp.Status,
|
||||||
|
"response", string(body))
|
||||||
|
return "", fmt.Errorf("HTTP %d: %s", resp.StatusCode, resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawBody, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("read body failed", "error", err)
|
||||||
|
return "", fmt.Errorf("read body error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(rawBody, &result); err != nil {
|
||||||
|
slog.Error("JSON parse error",
|
||||||
|
"error", err,
|
||||||
|
"response", string(rawBody))
|
||||||
|
return "", fmt.Errorf("JSON unmarshal error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return extractFileID(result.Avatar), nil
|
||||||
|
}
|
||||||
|
|
||||||
// extractFileID извлекает последний сегмент URL (fileId)
|
// extractFileID извлекает последний сегмент URL (fileId)
|
||||||
func extractFileID(avatarURL string) string {
|
func extractFileID(avatarURL string) string {
|
||||||
if avatarURL == "" {
|
if avatarURL == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user