Files
compress/internal/infrastructure/repositories/filesystem_repository.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

70 lines
1.8 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 repositories
import (
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"compress/internal/domain/entities"
)
// FileSystemRepository реализация репозитория для работы с файловой системой
type FileSystemRepository struct{}
// NewFileSystemRepository создает новый репозиторий файловой системы
func NewFileSystemRepository() *FileSystemRepository {
return &FileSystemRepository{}
}
// GetFileInfo получает информацию о PDF файле
func (r *FileSystemRepository) GetFileInfo(path string) (*entities.PDFDocument, error) {
info, err := os.Stat(path)
if err != nil {
return nil, err
}
return &entities.PDFDocument{
Path: path,
Size: info.Size(),
ModifiedTime: info.ModTime(),
Pages: 0, // TODO: Можно добавить определение количества страниц
}, nil
}
// FileExists проверяет существование файла
func (r *FileSystemRepository) FileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}
// CreateDirectory создает директорию
func (r *FileSystemRepository) CreateDirectory(path string) error {
return os.MkdirAll(path, 0755)
}
// ListPDFFiles возвращает список PDF файлов в директории и всех подпапках
func (r *FileSystemRepository) ListPDFFiles(directory string) ([]string, error) {
var pdfFiles []string
err := filepath.WalkDir(directory, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return nil
}
if d.IsDir() {
return nil
}
if strings.EqualFold(filepath.Ext(d.Name()), ".pdf") {
pdfFiles = append(pdfFiles, path)
}
return nil
})
if err != nil {
return nil, err
}
sort.Strings(pdfFiles)
return pdfFiles, nil
}