-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"baidu_cloud_disk/core/internal/logic" | ||
"baidu_cloud_disk/core/internal/svc" | ||
"baidu_cloud_disk/core/internal/types" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func FileUploadPrepareHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.FileUploadPrepareRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
return | ||
} | ||
|
||
l := logic.NewFileUploadPrepareLogic(r.Context(), svcCtx) | ||
resp, err := l.FileUploadPrepare(&req) | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.OkJsonCtx(r.Context(), w, resp) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package logic | ||
|
||
import ( | ||
"baidu_cloud_disk/core/helper" | ||
"baidu_cloud_disk/core/models" | ||
"context" | ||
|
||
"baidu_cloud_disk/core/internal/svc" | ||
"baidu_cloud_disk/core/internal/types" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type FileUploadPrepareLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewFileUploadPrepareLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileUploadPrepareLogic { | ||
return &FileUploadPrepareLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *FileUploadPrepareLogic) FileUploadPrepare(req *types.FileUploadPrepareRequest) (resp *types.FileUploadPrepareReply, err error) { | ||
// todo: add your logic here and delete this line | ||
rp := new(models.RepositoryPool) | ||
has, err := l.svcCtx.Engine.Where("hash = ?", req.Md5).Get(rp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if has { | ||
// 妙传成功 | ||
resp.Identity = rp.Identity | ||
} | ||
key, uploadId, err := helper.CosInitPart(req.Ext) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resp.Key = key | ||
resp.UploadId = uploadId | ||
|
||
return | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.