mirror of
https://github.com/kjanat/articulate-parser.git
synced 2026-10-13 01:35:27 +02:00
refactor: extract base exporter, add sentinel errors, document unused fields
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/kjanat/articulate-parser/internal/apperrors"
|
||||
"github.com/kjanat/articulate-parser/internal/interfaces"
|
||||
"github.com/kjanat/articulate-parser/internal/models"
|
||||
)
|
||||
@@ -37,7 +38,7 @@ func NewApp(parser interfaces.CourseParser, exporterFactory interfaces.ExporterF
|
||||
func (a *App) ProcessCourseFromFile(ctx context.Context, filePath, format, outputPath string) error {
|
||||
// Check for cancellation before loading
|
||||
if err := ctx.Err(); err != nil {
|
||||
return fmt.Errorf("operation canceled: %w", err)
|
||||
return fmt.Errorf("%w: %w", apperrors.ErrOperationCanceled, err)
|
||||
}
|
||||
|
||||
course, err := a.parser.LoadCourseFromFile(filePath)
|
||||
@@ -68,7 +69,7 @@ func (a *App) ProcessCourseFromURI(ctx context.Context, uri, format, outputPath
|
||||
func (a *App) exportCourse(ctx context.Context, course *models.Course, format, outputPath string) error {
|
||||
// Check for cancellation before export
|
||||
if err := ctx.Err(); err != nil {
|
||||
return fmt.Errorf("operation canceled: %w", err)
|
||||
return fmt.Errorf("%w: %w", apperrors.ErrOperationCanceled, err)
|
||||
}
|
||||
|
||||
exporter, err := a.exporterFactory.CreateExporter(format)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/kjanat/articulate-parser/internal/apperrors"
|
||||
"github.com/kjanat/articulate-parser/internal/config"
|
||||
"github.com/kjanat/articulate-parser/internal/interfaces"
|
||||
"github.com/kjanat/articulate-parser/internal/models"
|
||||
@@ -127,17 +128,17 @@ func (p *ArticulateParser) extractShareID(uri string) (string, error) {
|
||||
// Parse the URL to validate the domain
|
||||
parsedURL, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("invalid URI: %s", uri)
|
||||
return "", fmt.Errorf("%w: %s", apperrors.ErrInvalidURI, uri)
|
||||
}
|
||||
|
||||
// Validate that it's an Articulate Rise domain
|
||||
if parsedURL.Host != riseHost {
|
||||
return "", fmt.Errorf("invalid domain for Articulate Rise URI: %s", parsedURL.Host)
|
||||
return "", fmt.Errorf("%w: %s", apperrors.ErrInvalidDomain, parsedURL.Host)
|
||||
}
|
||||
|
||||
matches := shareIDRegex.FindStringSubmatch(uri)
|
||||
if len(matches) < 2 {
|
||||
return "", fmt.Errorf("could not extract share ID from URI: %s", uri)
|
||||
return "", fmt.Errorf("%w: %s", apperrors.ErrNoShareID, uri)
|
||||
}
|
||||
return matches[1], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user