🚧 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

@@ -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" {