🚧 improve image encryption and decryption

This commit is contained in:
2025-03-22 13:05:50 +08:00
parent 3a03224f8c
commit 781a71a27c
39 changed files with 1274 additions and 977 deletions

View File

@@ -49,8 +49,8 @@ func (l *DeleteShareRecordLogic) DeleteShareRecord(req *types.DeleteShareRecordR
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 {
_, err = shareVisit.Where(shareVisit.ShareID.Eq(req.ID), shareVisit.UserID.Eq(uid)).Delete()
if err != nil {
tx.Rollback()
return "", errors.New("delete share visit record failed")
}

View File

@@ -54,23 +54,25 @@ func (l *QueryShareImageLogic) QueryShareImage(req *types.QueryShareImageRequest
shareData, err := l.svcCtx.RedisClient.Get(l.ctx, cacheKey).Result()
if err != nil {
if errors.Is(err, redis.Nil) {
return nil, errors.New("share code not found")
return nil, errors.New("没有找到分享记录")
}
return nil, err
}
var storageShare model.ScaStorageShare
if err := json.Unmarshal([]byte(shareData), &storageShare); err != nil {
return nil, errors.New("unmarshal share data failed")
return nil, errors.New("解析分享记录失败")
}
// 验证密码
if storageShare.AccessPassword != "" && storageShare.AccessPassword != req.AccessPassword {
return nil, errors.New("incorrect password")
return nil, errors.New("密码错误")
}
// 检查分享是否过期
if storageShare.ExpireTime.Before(time.Now()) {
return nil, errors.New("share link has expired")
if storageShare.ValidityPeriod > 0 {
if storageShare.ExpireTime.Before(time.Now()) {
return nil, errors.New("分享已过期")
}
}
// 检查访问限制

View File

@@ -87,7 +87,10 @@ func (l *UploadShareImageLogic) UploadShareImage(req *types.ShareImageRequest) (
if err != nil {
return "", errors.New("invalid expire date")
}
expiryTime := l.GenerateExpiryTime(time.Now(), duration)
var expiryTime time.Time
if duration > 0 {
expiryTime = l.GenerateExpiryTime(time.Now(), duration)
}
storageShare := model.ScaStorageShare{
UserID: uid,
AlbumID: album.ID,