This commit is contained in:
2026-10-03 01:18:55 +07:00
parent c69dfb8503
commit 52e5ec6576
3 changed files with 14 additions and 7 deletions
+6 -6
View File
@@ -29,14 +29,14 @@ func (s *server) UploadFile(ctx context.Context, req *proto.UploadFileReq) (*pro
if err != nil {
switch {
case errors.Is(err, file_service.ErrFileTooLarge):
return nil, status.Errorf(codes.ResourceExhausted, "%v", err)
return nil, status.Error(codes.ResourceExhausted, err.Error())
case errors.Is(err, file_service.ErrEmptyName),
errors.Is(err, file_service.ErrEmptyData),
errors.Is(err, file_service.ErrInvalidExtension),
errors.Is(err, file_service.ErrInvalidContentType):
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
return nil, status.Error(codes.InvalidArgument, err.Error())
default:
return nil, status.Errorf(codes.Internal, "%v", err)
return nil, status.Error(codes.Internal, "не удалось загрузить файл")
}
}
return &proto.UploadFileRsp{
@@ -50,15 +50,15 @@ func (s *server) DownloadFile(ctx context.Context, req *proto.DownloadFileReq) (
if err != nil {
switch {
case errors.Is(err, file_service.ErrFileNotFound):
return nil, status.Errorf(codes.NotFound, "%v", err)
return nil, status.Error(codes.NotFound, err.Error())
default:
return nil, status.Errorf(codes.Internal, "%v", err)
return nil, status.Error(codes.Internal, "не удалось скачать файл")
}
}
// nosniff — при публичном скачивании браузер не должен угадывать
// Content-Type по содержимому (защита от stored-XSS при расхождении).
if err := grpc.SetHeader(ctx, metadata.Pairs("X-Content-Type-Options", "nosniff")); err != nil {
return nil, status.Errorf(codes.Internal, "failed to set response header: %v", err)
return nil, status.Error(codes.Internal, "не удалось установить заголовки файла")
}
return &httpbody.HttpBody{
Data: file.Data,