Compare commits
No commits in common. "86ce908b4e974953dce0224ae75d4741f70fa4c1" and "5dbd59fe8f60bd1add7e067fa103f96c5ef02856" have entirely different histories.
86ce908b4e
...
5dbd59fe8f
@ -34,9 +34,8 @@ func (c *UploadCommand) Execute(args []string) error {
|
||||
if resp.IsError() {
|
||||
return resp.Error().(*photosapi.ErrorWithDetails)
|
||||
}
|
||||
uploadId := resp.Result().(*photosapi.Upload).Id
|
||||
|
||||
defer cli.R().SetPathParam("id", uploadId).Delete("/upload/{id}")
|
||||
uploadId := resp.Result().(*photosapi.Upload).Id
|
||||
|
||||
f, err := os.Open(c.File)
|
||||
if err != nil {
|
||||
@ -87,29 +86,21 @@ func (c *UploadCommand) Execute(args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
completeRequest := &photosapi.UploadCompleteRequest{
|
||||
Sha256: hex.EncodeToString(completesha256.Sum(nil)),
|
||||
Parts: uint(parts),
|
||||
Name: filepath.Base(c.File),
|
||||
}
|
||||
|
||||
fmt.Printf(`Result:
|
||||
- Upload ID: %s
|
||||
- Name : %s
|
||||
- Parts : %d
|
||||
- SHA256 : %s
|
||||
`,
|
||||
fmt.Printf(
|
||||
"Result:\n - Upload ID: %s\n - Parts: %d\n",
|
||||
uploadId,
|
||||
completeRequest.Name,
|
||||
completeRequest.Parts,
|
||||
completeRequest.Sha256,
|
||||
parts,
|
||||
)
|
||||
|
||||
resp, err = cli.
|
||||
R().
|
||||
SetError(&photosapi.ErrorWithDetails{}).
|
||||
SetPathParam("id", uploadId).
|
||||
SetBody(completeRequest).
|
||||
SetBody(&photosapi.UploadCompleteRequest{
|
||||
Sha256: hex.EncodeToString(completesha256.Sum(nil)),
|
||||
Parts: uint(parts),
|
||||
Name: filepath.Base(c.File),
|
||||
}).
|
||||
Post("/upload/{id}")
|
||||
|
||||
if err != nil {
|
||||
@ -120,6 +111,8 @@ func (c *UploadCommand) Execute(args []string) error {
|
||||
return resp.Error().(*photosapi.ErrorWithDetails)
|
||||
}
|
||||
|
||||
cli.R().SetPathParam("id", uploadId).Delete("/upload/{id}")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package photosapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@ -25,7 +24,7 @@ func (s *Storage) Create(paths ...string) error {
|
||||
}
|
||||
|
||||
func (s *Storage) Exists(paths ...string) bool {
|
||||
f, err := s.Stat(paths...)
|
||||
f, err := os.Stat(s.Join(paths...))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
@ -39,7 +38,3 @@ func (s *Storage) Delete(paths ...string) error {
|
||||
return fmt.Errorf("%s doesn't exists", s.Join(paths...))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) Stat(paths ...string) (fs.FileInfo, error) {
|
||||
return os.Stat(s.Join(paths...))
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ var (
|
||||
ErrUploadNotExists = errors.New("upload id doesn't exists")
|
||||
ErrUploadPartTooLarge = fmt.Errorf("upload part too large (> %d B)", MaxUploadPartSize)
|
||||
ErrUploadPartWrongSha256 = errors.New("upload part wrong sha256")
|
||||
ErrFileAlreadExists = errors.New("file already exists")
|
||||
)
|
||||
|
||||
// Model
|
||||
@ -54,8 +53,6 @@ func (s *Service) UploadCreate(c *gin.Context) {
|
||||
c.JSON(http.StatusCreated, upload)
|
||||
}
|
||||
|
||||
// Service
|
||||
|
||||
type Upload struct {
|
||||
Id string `json:"upload_id" uri:"upload_id" binding:"required,uuid"`
|
||||
}
|
||||
@ -65,12 +62,6 @@ type UploadPartQuery struct {
|
||||
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) {
|
||||
var (
|
||||
upload Upload
|
||||
@ -142,6 +133,12 @@ func (s *Service) UploadCancel(c *gin.Context) {
|
||||
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) {
|
||||
var (
|
||||
upload Upload
|
||||
@ -156,13 +153,6 @@ func (s *Service) UploadComplete(c *gin.Context) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user