Files
compress/internal/usecase/compress_pdf.go
Dmitriy Fofanov eee9a4a093 Добавлены скрипты сборки для кроссплатформенных двоичных файлов и лицензия GPL.
- Добавлен файл LICENSE с лицензией GNU General Public License версии 3.0.
- Создан скрипт PowerShell (build-all.ps1) для сборки двоичных файлов Windows и Linux из Windows с использованием кросс-компиляции.
- Разработан скрипт сборки Linux (build-linux.sh) для сборки двоичных файлов Linux.
- Реализован скрипт PowerShell (build-windows.ps1) для сборки двоичных файлов Windows.
- Каждый скрипт сборки включает упаковку и генерацию контрольной суммы SHA256 для двоичных файлов.
2025-11-05 13:05:49 +03:00

74 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package usecases
import (
"fmt"
"path/filepath"
"compress/internal/domain/entities"
"compress/internal/domain/repositories"
)
// CompressPDFUseCase сценарий сжатия одного PDF файла
type CompressPDFUseCase struct {
compressor repositories.PDFCompressor
fileRepo repositories.FileRepository
configRepo repositories.ConfigRepository
}
// NewCompressPDFUseCase создает новый сценарий сжатия PDF
func NewCompressPDFUseCase(
compressor repositories.PDFCompressor,
fileRepo repositories.FileRepository,
configRepo repositories.ConfigRepository,
) *CompressPDFUseCase {
return &CompressPDFUseCase{
compressor: compressor,
fileRepo: fileRepo,
configRepo: configRepo,
}
}
// Execute выполняет сжатие PDF файла
func (uc *CompressPDFUseCase) Execute(inputPath string, outputPath string, compressionLevel int) (*entities.CompressionResult, error) {
// Проверяем существование входного файла
if !uc.fileRepo.FileExists(inputPath) {
return nil, entities.ErrFileNotFound
}
// Получаем информацию о файле
fileInfo, err := uc.fileRepo.GetFileInfo(inputPath)
if err != nil {
return nil, fmt.Errorf("ошибка получения информации о файле: %w", err)
}
// Создаем конфигурацию сжатия
config, err := uc.configRepo.GetCompressionConfig(compressionLevel)
if err != nil {
return nil, fmt.Errorf("ошибка создания конфигурации: %w", err)
}
// Валидируем конфигурацию
if err := uc.configRepo.ValidateConfig(config); err != nil {
return nil, fmt.Errorf("ошибка валидации конфигурации: %w", err)
}
// Генерируем имя выходного файла, если не указано
if outputPath == "" {
ext := filepath.Ext(inputPath)
base := inputPath[:len(inputPath)-len(ext)]
outputPath = base + "_compressed" + ext
}
// Выполняем сжатие
result, err := uc.compressor.Compress(inputPath, outputPath, config)
if err != nil {
return nil, fmt.Errorf("ошибка сжатия файла: %w", err)
}
// Устанавливаем исходный размер
result.OriginalSize = fileInfo.Size
result.CalculateCompressionRatio()
return result, nil
}