✨ improve image sharing function
This commit is contained in:
8
common/constant/album_type.go
Normal file
8
common/constant/album_type.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
AlbumTypeMine = 0
|
||||
AlbumTypeShared = 1
|
||||
|
||||
AlbumTypeCollection = 2
|
||||
)
|
@@ -1,7 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
FaceBucketName = "schisandra-face-samples"
|
||||
CommentImagesBucketName = "schisandra-comment-images"
|
||||
ThumbnailBucketName = "schisandra-thumbnail-images"
|
||||
FaceBucketName = "schisandra-face-samples"
|
||||
CommentImagesBucketName = "schisandra-comment-images"
|
||||
ThumbnailBucketName = "schisandra-thumbnail-images"
|
||||
ShareThumbnailBucketName = "schisandra-share-thumbnails"
|
||||
)
|
||||
|
9
common/constant/image_type.go
Normal file
9
common/constant/image_type.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
ImageTypeImage = "image"
|
||||
ImageTypeVideo = "video"
|
||||
ImageTypeScreenshot = "screenshot"
|
||||
ImageTypeGif = "gif"
|
||||
ImageTypeShared = "shared"
|
||||
)
|
@@ -21,8 +21,10 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
ImageListPrefix = "image:list:"
|
||||
ImageRecentPrefix = "image:recent:"
|
||||
ImageFaceListPrefix = "image:faces:"
|
||||
ImageSinglePrefix = "image:single:"
|
||||
ImageListPrefix = "image:list:"
|
||||
ImageRecentPrefix = "image:recent:"
|
||||
ImageFaceListPrefix = "image:faces:"
|
||||
ImageSinglePrefix = "image:single:"
|
||||
ImageSharePrefix = "image:share:"
|
||||
ImageShareVisitPrefix = "image:share:visit:"
|
||||
)
|
||||
|
@@ -1,18 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/casbin/casbin/v2"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
)
|
||||
|
||||
func CasbinMiddleware(w http.ResponseWriter, r *http.Request, casbin *casbin.SyncedCachedEnforcer) {
|
||||
userId := r.Header.Get(constant.UID_HEADER_KEY)
|
||||
correct, err := casbin.Enforce(userId, r.URL.Path, r.Method)
|
||||
if err != nil || !correct {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, errors.New(http.StatusNotFound, "not found"))
|
||||
return
|
||||
}
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
"net/http"
|
||||
"schisandra-album-cloud-microservices/common/constant"
|
||||
"schisandra-album-cloud-microservices/common/errors"
|
||||
"schisandra-album-cloud-microservices/common/xhttp"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NonceMiddleware(w http.ResponseWriter, r *http.Request, redisClient *redis.Client) {
|
||||
nonce := r.Header.Get("X-Nonce")
|
||||
if nonce == "" {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, errors.New(http.StatusBadRequest, "bad request!"))
|
||||
return
|
||||
}
|
||||
if len(nonce) != 32 {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, errors.New(http.StatusBadRequest, "bad request!"))
|
||||
return
|
||||
}
|
||||
result := redisClient.Get(r.Context(), constant.SystemApiNoncePrefix+nonce).Val()
|
||||
if result != "" {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, errors.New(http.StatusBadRequest, "bad request!"))
|
||||
return
|
||||
}
|
||||
err := redisClient.Set(r.Context(), constant.SystemApiNoncePrefix+nonce, nonce, time.Minute*1).Err()
|
||||
if err != nil {
|
||||
xhttp.JsonBaseResponseCtx(r.Context(), w, errors.New(http.StatusInternalServerError, "internal server error!"))
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user