🚧 developing...
This commit is contained in:
@@ -400,6 +400,14 @@ type (
|
|||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
userId string `json:"user_id"`
|
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 (
|
@server (
|
||||||
@@ -415,6 +423,9 @@ type (
|
|||||||
service auth {
|
service auth {
|
||||||
@handler uploadImage
|
@handler uploadImage
|
||||||
post /upload (UploadRequest)
|
post /upload (UploadRequest)
|
||||||
|
|
||||||
|
@handler sharePhoneUpload
|
||||||
|
post /share/upload (SharePhoneUploadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件上传配置请求参数
|
// 文件上传配置请求参数
|
||||||
@@ -803,6 +814,7 @@ type (
|
|||||||
VisitLimit int64 `json:"visit_limit"`
|
VisitLimit int64 `json:"visit_limit"`
|
||||||
AccessPassword string `json:"access_password"`
|
AccessPassword string `json:"access_password"`
|
||||||
ValidityPeriod int64 `json:"validity_period"`
|
ValidityPeriod int64 `json:"validity_period"`
|
||||||
|
AlbumID int64 `json:"album_id"`
|
||||||
}
|
}
|
||||||
ShareRecordListResponse {
|
ShareRecordListResponse {
|
||||||
records []ShareRecord `json:"records"`
|
records []ShareRecord `json:"records"`
|
||||||
@@ -832,6 +844,12 @@ type (
|
|||||||
PublishCount int64 `json:"publish_count"`
|
PublishCount int64 `json:"publish_count"`
|
||||||
PublishCountToday int64 `json:"publish_count_today"`
|
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
|
@handler queryShareOverview
|
||||||
post /overview returns (ShareOverviewResponse)
|
post /overview returns (ShareOverviewResponse)
|
||||||
|
|
||||||
|
// 删除分享记录
|
||||||
|
@handler deleteShareRecord
|
||||||
|
post /record/delete (DeleteShareRecordRequest) returns (string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -163,6 +163,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
rest.WithMiddlewares(
|
rest.WithMiddlewares(
|
||||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.NonceMiddleware},
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/share/upload",
|
||||||
|
Handler: phone.SharePhoneUploadHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/upload",
|
Path: "/upload",
|
||||||
@@ -194,6 +199,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/overview",
|
Path: "/overview",
|
||||||
Handler: share.QueryShareOverviewHandler(serverCtx),
|
Handler: share.QueryShareOverviewHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/record/delete",
|
||||||
|
Handler: share.DeleteShareRecordHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/record/list",
|
Path: "/record/list",
|
||||||
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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
|
||||||
|
}
|
@@ -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
|
||||||
|
}
|
@@ -39,6 +39,7 @@ func (l *ListShareRecordLogic) ListShareRecord(req *types.ShareRecordListRequest
|
|||||||
storageShare.VisitLimit,
|
storageShare.VisitLimit,
|
||||||
storageShare.AccessPassword,
|
storageShare.AccessPassword,
|
||||||
storageShare.ValidityPeriod,
|
storageShare.ValidityPeriod,
|
||||||
|
storageShare.AlbumID,
|
||||||
storageShare.CreatedAt,
|
storageShare.CreatedAt,
|
||||||
storageAlbum.CoverImage).
|
storageAlbum.CoverImage).
|
||||||
LeftJoin(storageAlbum, storageShare.AlbumID.EqCol(storageAlbum.ID)).
|
LeftJoin(storageAlbum, storageShare.AlbumID.EqCol(storageAlbum.ID)).
|
||||||
|
@@ -79,6 +79,7 @@ func (l *QueryAllImageListLogic) QueryAllImageList(req *types.AllImageListReques
|
|||||||
storageInfo.Provider.Eq(req.Provider),
|
storageInfo.Provider.Eq(req.Provider),
|
||||||
storageInfo.Bucket.Eq(req.Bucket),
|
storageInfo.Bucket.Eq(req.Bucket),
|
||||||
storageInfo.Type.Neq(constant.ImageTypeShared),
|
storageInfo.Type.Neq(constant.ImageTypeShared),
|
||||||
|
storageInfo.IsDisplayed.Eq(0),
|
||||||
}
|
}
|
||||||
queryCondition = append(queryCondition, conditions...)
|
queryCondition = append(queryCondition, conditions...)
|
||||||
if req.Type != "all" {
|
if req.Type != "all" {
|
||||||
|
@@ -14,3 +14,10 @@ type ShareFileInfoResult struct {
|
|||||||
Provider string `json:"provider"`
|
Provider string `json:"provider"`
|
||||||
Bucket string `json:"bucket"`
|
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"`
|
||||||
|
}
|
||||||
|
@@ -168,6 +168,12 @@ type DeleteRecordListResponse struct {
|
|||||||
Records []AllImageDetail `json:"records"`
|
Records []AllImageDetail `json:"records"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteShareRecordRequest struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
InviteCode string `json:"invite_code"`
|
||||||
|
AlbumID int64 `json:"album_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type DownloadAlbumRequest struct {
|
type DownloadAlbumRequest struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Provider string `json:"provider"`
|
Provider string `json:"provider"`
|
||||||
@@ -419,6 +425,15 @@ type ShareOverviewResponse struct {
|
|||||||
PublishCountToday int64 `json:"publish_count_today"`
|
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 {
|
type ShareRecord struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
CoverImage string `json:"cover_image"`
|
CoverImage string `json:"cover_image"`
|
||||||
@@ -427,6 +442,7 @@ type ShareRecord struct {
|
|||||||
VisitLimit int64 `json:"visit_limit"`
|
VisitLimit int64 `json:"visit_limit"`
|
||||||
AccessPassword string `json:"access_password"`
|
AccessPassword string `json:"access_password"`
|
||||||
ValidityPeriod int64 `json:"validity_period"`
|
ValidityPeriod int64 `json:"validity_period"`
|
||||||
|
AlbumID int64 `json:"album_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShareRecordListRequest struct {
|
type ShareRecordListRequest struct {
|
||||||
|
Reference in New Issue
Block a user