优化结构
This commit is contained in:
@@ -5,7 +5,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUserNotFound = errors.NotFound("USER_NOT_FOUND", "user not found")
|
||||
ErrUserNotFound = errors.NotFound("USER_NOT_FOUND", "user not found")
|
||||
ErrMediaNotFound = errors.NotFound("MEDIA_NOT_FOUND", "media not found")
|
||||
// ErrInvalidCredentials is returned for any failed login, regardless of
|
||||
// whether the user exists, to avoid leaking which accounts are registered.
|
||||
ErrInvalidCredentials = errors.Unauthorized("INVALID_CREDENTIALS", "invalid credentials")
|
||||
|
||||
@@ -110,10 +110,12 @@ func (uc *MediaUsecase) Upload(ctx context.Context, userID uint, name, suppliedM
|
||||
if save {
|
||||
count, countErr := uc.MediaKeyReferences(ctx, key)
|
||||
if countErr != nil {
|
||||
_ = uc.files.Delete(ctx, key)
|
||||
return nil, countErr
|
||||
}
|
||||
if count == 0 {
|
||||
if err = uc.CreateMedia(ctx, media); err != nil {
|
||||
_ = uc.files.Delete(ctx, key)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +260,7 @@ func (uc *MediaUsecase) CompleteUpload(ctx context.Context, userID, uploadID uin
|
||||
}
|
||||
}
|
||||
if err = uc.CreateMedia(ctx, media); err != nil {
|
||||
_ = uc.files.Delete(ctx, key)
|
||||
return fail(err)
|
||||
}
|
||||
if err = uc.CompleteUploadSession(ctx, uploadID, key, media.ID); err != nil {
|
||||
|
||||
@@ -23,6 +23,7 @@ type MediaSettings struct {
|
||||
}
|
||||
|
||||
const DefaultMaxMediaFileSize int64 = 100 << 20
|
||||
const UploadBodyOverhead int64 = 1 << 20
|
||||
|
||||
func (s MediaSettings) EffectiveMaxFileSize() int64 {
|
||||
if s.MaxFileSize > 0 {
|
||||
|
||||
Reference in New Issue
Block a user