re organizer project

This commit is contained in:
m
2026-07-12 13:44:15 +02:00
parent 999fbaf7fa
commit 6b8c64bd40
20 changed files with 529 additions and 479 deletions
+44
View File
@@ -0,0 +1,44 @@
package service
import (
"fmt"
"os"
"strings"
"github.com/vaultdrop/backend/internal/config"
"github.com/vaultdrop/backend/internal/ocr"
)
type OCRService struct {
client *ocr.Client
}
func NewOCRService(cfg *config.Config) *OCRService {
return &OCRService{
client: ocr.NewClient(cfg.OCREndpoint),
}
}
func (s *OCRService) RecognizeFromFile(filePath string) ([]ocr.TextBlock, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)
}
return s.client.Recognize(data)
}
func (s *OCRService) RecognizeFromBytes(data []byte) ([]ocr.TextBlock, error) {
return s.client.Recognize(data)
}
func (s *OCRService) FlattenResults(blocks []ocr.TextBlock) string {
var texts []string
for _, b := range blocks {
texts = append(texts, b.Text)
}
return strings.Join(texts, "\n")
}
func (s *OCRService) HealthCheck() error {
return s.client.HealthCheck()
}