🚧 developing...

This commit is contained in:
2025-02-24 17:10:53 +08:00
parent a26f0a5583
commit 693ed8755c
10 changed files with 250 additions and 0 deletions

View File

@@ -400,6 +400,14 @@ type (
AccessToken string `json:"access_token"`
userId string `json:"user_id"`
}
SharePhoneUploadRequest {
OriginFileObj string `json:"origin_file_obj"`
Name string `json:"name"`
Type string `json:"type"`
Size int64 `json:"size"`
AccessToken string `json:"access_token"`
userId string `json:"user_id"`
}
)
@server (
@@ -415,6 +423,9 @@ type (
service auth {
@handler uploadImage
post /upload (UploadRequest)
@handler sharePhoneUpload
post /share/upload (SharePhoneUploadRequest)
}
// 文件上传配置请求参数
@@ -803,6 +814,7 @@ type (
VisitLimit int64 `json:"visit_limit"`
AccessPassword string `json:"access_password"`
ValidityPeriod int64 `json:"validity_period"`
AlbumID int64 `json:"album_id"`
}
ShareRecordListResponse {
records []ShareRecord `json:"records"`
@@ -832,6 +844,12 @@ type (
PublishCount int64 `json:"publish_count"`
PublishCountToday int64 `json:"publish_count_today"`
}
// 删除分享记录请求参数
DeleteShareRecordRequest {
ID int64 `json:"id"`
InviteCode string `json:"invite_code"`
AlbumID int64 `json:"album_id"`
}
)
// 分享服务
@@ -865,5 +883,9 @@ service auth {
// 查询浏览数据概览
@handler queryShareOverview
post /overview returns (ShareOverviewResponse)
// 删除分享记录
@handler deleteShareRecord
post /record/delete (DeleteShareRecordRequest) returns (string)
}

View File

@@ -0,0 +1,26 @@
package phone
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/phone"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"schisandra-album-cloud-microservices/common/xhttp"
)
func SharePhoneUploadHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SharePhoneUploadRequest
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := phone.NewSharePhoneUploadLogic(r.Context(), svcCtx)
err := l.SharePhoneUpload(r, &req)
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
}
}

View File

@@ -163,6 +163,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/share/upload",
Handler: phone.SharePhoneUploadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/upload",
@@ -194,6 +199,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/overview",
Handler: share.QueryShareOverviewHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/record/delete",
Handler: share.DeleteShareRecordHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/record/list",

View File

@@ -0,0 +1,29 @@
package share
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/share"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"schisandra-album-cloud-microservices/common/xhttp"
)
func DeleteShareRecordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteShareRecordRequest
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := share.NewDeleteShareRecordLogic(r.Context(), svcCtx)
resp, err := l.DeleteShareRecord(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,64 @@
package phone
import (
"context"
"encoding/json"
"net/http"
"schisandra-album-cloud-microservices/app/auth/api/internal/logic/websocket"
"schisandra-album-cloud-microservices/common/errors"
"schisandra-album-cloud-microservices/common/jwt"
"schisandra-album-cloud-microservices/common/xhttp"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SharePhoneUploadLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSharePhoneUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SharePhoneUploadLogic {
return &SharePhoneUploadLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SharePhoneUploadLogic) SharePhoneUpload(r *http.Request, req *types.SharePhoneUploadRequest) error {
token, ok := jwt.ParseAccessToken(l.svcCtx.Config.Auth.AccessSecret, req.AccessToken)
if !ok {
return errors.New(http.StatusForbidden, "invalid access token")
}
if token.UserID != req.UserId {
return errors.New(http.StatusForbidden, "invalid user id")
}
correct, err := l.svcCtx.CasbinEnforcer.Enforce(req.UserId, r.URL.Path, r.Method)
if err != nil || !correct {
return errors.New(http.StatusForbidden, "permission denied")
}
data, err := json.Marshal(xhttp.BaseResponse[types.SharePhoneUploadResult]{
Data: types.SharePhoneUploadResult{
OriginFileObj: req.OriginFileObj,
Name: req.Name,
Type: req.Type,
Size: req.Size,
},
Msg: "success",
Code: http.StatusOK,
})
if err != nil {
return errors.New(http.StatusForbidden, err.Error())
}
err = websocket.FileWebSocketHandler.SendMessageToClient(req.UserId, data)
if err != nil {
return errors.New(http.StatusForbidden, err.Error())
}
return nil
}

View File

@@ -0,0 +1,74 @@
package share
import (
"context"
"errors"
"schisandra-album-cloud-microservices/app/auth/api/internal/svc"
"schisandra-album-cloud-microservices/app/auth/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteShareRecordLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteShareRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteShareRecordLogic {
return &DeleteShareRecordLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteShareRecordLogic) DeleteShareRecord(req *types.DeleteShareRecordRequest) (resp string, err error) {
uid, ok := l.ctx.Value("user_id").(string)
if !ok {
return "", errors.New("user_id not found")
}
tx := l.svcCtx.DB.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
}
}()
storageShare := tx.ScaStorageShare
storageShareDeleted, err := storageShare.Where(storageShare.UserID.Eq(uid),
storageShare.ID.Eq(req.ID),
storageShare.InviteCode.Eq(req.InviteCode),
storageShare.AlbumID.Eq(req.AlbumID)).
Delete()
if err != nil || storageShareDeleted.RowsAffected == 0 {
tx.Rollback()
return "", errors.New("delete share record failed")
}
shareVisit := tx.ScaStorageShareVisit
shareVisitDeleted, err := shareVisit.Where(shareVisit.ShareID.Eq(req.ID), shareVisit.UserID.Eq(uid)).Delete()
if err != nil || shareVisitDeleted.RowsAffected == 0 {
tx.Rollback()
return "", errors.New("delete share visit record failed")
}
storageAlbum := tx.ScaStorageAlbum
albumDeleted, err := storageAlbum.Where(storageAlbum.ID.Eq(req.AlbumID), storageAlbum.UserID.Eq(uid)).Delete()
if err != nil || albumDeleted.RowsAffected == 0 {
tx.Rollback()
return "", errors.New("delete album record failed")
}
storageInfo := tx.ScaStorageInfo
infoDeleted, err := storageInfo.Where(storageInfo.AlbumID.Eq(req.AlbumID), storageInfo.UserID.Eq(uid)).Delete()
if err != nil || infoDeleted.RowsAffected == 0 {
tx.Rollback()
return "", errors.New("delete storage info record failed")
}
err = tx.Commit()
if err != nil {
tx.Rollback()
return "", errors.New("commit failed")
}
return
}

View File

@@ -39,6 +39,7 @@ func (l *ListShareRecordLogic) ListShareRecord(req *types.ShareRecordListRequest
storageShare.VisitLimit,
storageShare.AccessPassword,
storageShare.ValidityPeriod,
storageShare.AlbumID,
storageShare.CreatedAt,
storageAlbum.CoverImage).
LeftJoin(storageAlbum, storageShare.AlbumID.EqCol(storageAlbum.ID)).

View File

@@ -79,6 +79,7 @@ func (l *QueryAllImageListLogic) QueryAllImageList(req *types.AllImageListReques
storageInfo.Provider.Eq(req.Provider),
storageInfo.Bucket.Eq(req.Bucket),
storageInfo.Type.Neq(constant.ImageTypeShared),
storageInfo.IsDisplayed.Eq(0),
}
queryCondition = append(queryCondition, conditions...)
if req.Type != "all" {

View File

@@ -14,3 +14,10 @@ type ShareFileInfoResult struct {
Provider string `json:"provider"`
Bucket string `json:"bucket"`
}
type SharePhoneUploadResult struct {
OriginFileObj string `json:"origin_file_obj"`
Name string `json:"name"`
Type string `json:"type"`
Size int64 `json:"size"`
}

View File

@@ -168,6 +168,12 @@ type DeleteRecordListResponse struct {
Records []AllImageDetail `json:"records"`
}
type DeleteShareRecordRequest struct {
ID int64 `json:"id"`
InviteCode string `json:"invite_code"`
AlbumID int64 `json:"album_id"`
}
type DownloadAlbumRequest struct {
ID int64 `json:"id"`
Provider string `json:"provider"`
@@ -419,6 +425,15 @@ type ShareOverviewResponse struct {
PublishCountToday int64 `json:"publish_count_today"`
}
type SharePhoneUploadRequest struct {
OriginFileObj string `json:"origin_file_obj"`
Name string `json:"name"`
Type string `json:"type"`
Size int64 `json:"size"`
AccessToken string `json:"access_token"`
UserId string `json:"user_id"`
}
type ShareRecord struct {
ID int64 `json:"id"`
CoverImage string `json:"cover_image"`
@@ -427,6 +442,7 @@ type ShareRecord struct {
VisitLimit int64 `json:"visit_limit"`
AccessPassword string `json:"access_password"`
ValidityPeriod int64 `json:"validity_period"`
AlbumID int64 `json:"album_id"`
}
type ShareRecordListRequest struct {