generated from VLADIMIR/template
fix
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"evening_detective_server/internal/modules/file_storage"
|
|
||||||
"evening_detective_server/internal/modules/roles"
|
"evening_detective_server/internal/modules/roles"
|
||||||
"evening_detective_server/internal/services/file_service"
|
"evening_detective_server/internal/services/file_service"
|
||||||
proto "evening_detective_server/proto"
|
proto "evening_detective_server/proto"
|
||||||
@@ -50,7 +49,7 @@ func (s *server) DownloadFile(ctx context.Context, req *proto.DownloadFileReq) (
|
|||||||
file, err := s.fileService.DownloadFile(ctx, req.Filename)
|
file, err := s.fileService.DownloadFile(ctx, req.Filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, file_storage.ErrFileNotFound):
|
case errors.Is(err, file_service.ErrFileNotFound):
|
||||||
return nil, status.Errorf(codes.NotFound, "%v", err)
|
return nil, status.Errorf(codes.NotFound, "%v", err)
|
||||||
default:
|
default:
|
||||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ var (
|
|||||||
ErrInvalidExtension = errors.New("недопустимое расширение файла (разрешены pdf, jpg, jpeg, png, gif, webp, mp3, ogg, wav, mp4, webm)")
|
ErrInvalidExtension = errors.New("недопустимое расширение файла (разрешены pdf, jpg, jpeg, png, gif, webp, mp3, ogg, wav, mp4, webm)")
|
||||||
ErrInvalidContentType = errors.New("содержимое файла не соответствует разрешённым типам (pdf, изображения, аудио или видео)")
|
ErrInvalidContentType = errors.New("содержимое файла не соответствует разрешённым типам (pdf, изображения, аудио или видео)")
|
||||||
ErrFileTooLarge = errors.New("файл слишком большой")
|
ErrFileTooLarge = errors.New("файл слишком большой")
|
||||||
|
// ErrFileNotFound — файл отсутствует в хранилище.
|
||||||
|
ErrFileNotFound = errors.New("файл не найден")
|
||||||
)
|
)
|
||||||
|
|
||||||
// allowedExtensions — расширения, разрешённые для загрузки: PDF, изображения
|
// allowedExtensions — расширения, разрешённые для загрузки: PDF, изображения
|
||||||
@@ -152,6 +154,9 @@ func (s *FileService) DownloadFile(
|
|||||||
) (*file_storage.File, error) {
|
) (*file_storage.File, error) {
|
||||||
file, err := s.fileStorage.Get(ctx, filename)
|
file, err := s.fileStorage.Get(ctx, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, file_storage.ErrFileNotFound) {
|
||||||
|
return nil, ErrFileNotFound
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return file, nil
|
return file, nil
|
||||||
|
|||||||
@@ -155,6 +155,14 @@ func TestUploadFileTooLarge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDownloadFileNotFound(t *testing.T) {
|
||||||
|
svc := newService(1 << 20)
|
||||||
|
_, err := svc.DownloadFile(context.Background(), "missing.pdf")
|
||||||
|
if !errors.Is(err, ErrFileNotFound) {
|
||||||
|
t.Fatalf("err = %v, want ErrFileNotFound", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func bytes1024() []byte {
|
func bytes1024() []byte {
|
||||||
b := make([]byte, 1024)
|
b := make([]byte, 1024)
|
||||||
copy(b, "%PDF-1.7 ")
|
copy(b, "%PDF-1.7 ")
|
||||||
|
|||||||
Reference in New Issue
Block a user