check file existant before processing
This commit is contained in:
parent
7dae7a4c2b
commit
86ce908b4e
@ -22,6 +22,7 @@ var (
|
|||||||
ErrUploadNotExists = errors.New("upload id doesn't exists")
|
ErrUploadNotExists = errors.New("upload id doesn't exists")
|
||||||
ErrUploadPartTooLarge = fmt.Errorf("upload part too large (> %d B)", MaxUploadPartSize)
|
ErrUploadPartTooLarge = fmt.Errorf("upload part too large (> %d B)", MaxUploadPartSize)
|
||||||
ErrUploadPartWrongSha256 = errors.New("upload part wrong sha256")
|
ErrUploadPartWrongSha256 = errors.New("upload part wrong sha256")
|
||||||
|
ErrFileAlreadExists = errors.New("file already exists")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Model
|
// Model
|
||||||
@ -53,6 +54,8 @@ func (s *Service) UploadCreate(c *gin.Context) {
|
|||||||
c.JSON(http.StatusCreated, upload)
|
c.JSON(http.StatusCreated, upload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Service
|
||||||
|
|
||||||
type Upload struct {
|
type Upload struct {
|
||||||
Id string `json:"upload_id" uri:"upload_id" binding:"required,uuid"`
|
Id string `json:"upload_id" uri:"upload_id" binding:"required,uuid"`
|
||||||
}
|
}
|
||||||
@ -62,6 +65,12 @@ type UploadPartQuery struct {
|
|||||||
PartSha256 string `form:"sha256" binding:"required,sha256"`
|
PartSha256 string `form:"sha256" binding:"required,sha256"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UploadCompleteRequest struct {
|
||||||
|
Sha256 string `json:"sha256" binding:"required,sha256"`
|
||||||
|
Name string `json:"name" binding:"required"`
|
||||||
|
Parts uint `json:"parts" binding:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) UploadPart(c *gin.Context) {
|
func (s *Service) UploadPart(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
upload Upload
|
upload Upload
|
||||||
@ -133,12 +142,6 @@ func (s *Service) UploadCancel(c *gin.Context) {
|
|||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadCompleteRequest struct {
|
|
||||||
Sha256 string `json:"sha256" binding:"required,sha256"`
|
|
||||||
Name string `json:"name" binding:"required"`
|
|
||||||
Parts uint `json:"parts" binding:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) UploadComplete(c *gin.Context) {
|
func (s *Service) UploadComplete(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
upload Upload
|
upload Upload
|
||||||
@ -153,6 +156,13 @@ func (s *Service) UploadComplete(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f, err := s.StorageUpload.Stat(uploadCompleteRequest.Sha256[0:1], uploadCompleteRequest.Sha256[1:2], uploadCompleteRequest.Sha256)
|
||||||
|
fmt.Println(err)
|
||||||
|
if err == nil && f.Mode().IsRegular() {
|
||||||
|
c.AbortWithError(http.StatusConflict, ErrFileAlreadExists)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user