chore(libreoffice): switch to supervisor (#708)

This commit is contained in:
Julien Neuhart
2023-10-28 17:55:53 +02:00
committed by GitHub
parent c8b318b315
commit 052448c59a
38 changed files with 2381 additions and 3093 deletions

View File

@@ -8,37 +8,37 @@ import (
"go.uber.org/zap"
"github.com/gotenberg/gotenberg/v7/pkg/gotenberg"
"github.com/gotenberg/gotenberg/v7/pkg/modules/libreoffice/uno"
"github.com/gotenberg/gotenberg/v7/pkg/modules/libreoffice/api"
)
func init() {
gotenberg.MustRegisterModule(UNO{})
gotenberg.MustRegisterModule(new(LibreOfficePdfEngine))
}
// UNO interacts with the UNO (Universal Network Objects) API and implements
// the gotenberg.PDFEngine interface.
type UNO struct {
unoAPI uno.API
// LibreOfficePdfEngine interacts with the LibreOffice (Universal Network Objects) API
// and implements the [gotenberg.PDFEngine] interface.
type LibreOfficePdfEngine struct {
unoAPI api.Uno
}
// Descriptor returns a UNO's module descriptor.
func (UNO) Descriptor() gotenberg.ModuleDescriptor {
// Descriptor returns a [LibreOfficePdfEngine]'s module descriptor.
func (engine *LibreOfficePdfEngine) Descriptor() gotenberg.ModuleDescriptor {
return gotenberg.ModuleDescriptor{
ID: "uno-pdfengine",
New: func() gotenberg.Module { return new(UNO) },
ID: "libreoffice-pdfengine",
New: func() gotenberg.Module { return new(LibreOfficePdfEngine) },
}
}
// Provision sets the module properties.
func (engine *UNO) Provision(ctx *gotenberg.Context) error {
provider, err := ctx.Module(new(uno.Provider))
func (engine *LibreOfficePdfEngine) Provision(ctx *gotenberg.Context) error {
provider, err := ctx.Module(new(api.Provider))
if err != nil {
return fmt.Errorf("get unoconv provider: %w", err)
return fmt.Errorf("get LibreOffice Uno provider: %w", err)
}
unoAPI, err := provider.(uno.Provider).UNO()
unoAPI, err := provider.(api.Provider).LibreOffice()
if err != nil {
return fmt.Errorf("get unoconv API: %w", err)
return fmt.Errorf("get LibreOffice Uno: %w", err)
}
engine.unoAPI = unoAPI
@@ -47,24 +47,24 @@ func (engine *UNO) Provision(ctx *gotenberg.Context) error {
}
// Merge is not available for this PDF engine.
func (engine UNO) Merge(_ context.Context, _ *zap.Logger, _ []string, _ string) error {
return fmt.Errorf("merge PDFs with unoconv: %w", gotenberg.ErrPDFEngineMethodNotAvailable)
func (engine *LibreOfficePdfEngine) Merge(_ context.Context, _ *zap.Logger, _ []string, _ string) error {
return fmt.Errorf("merge PDFs with LibreOffice: %w", gotenberg.ErrPDFEngineMethodNotAvailable)
}
// Convert converts the given PDF to a specific PDF format. Currently, only the
// PDF/A-1a, PDF/A-2b and PDF/A-3b formats are available. If another PDF format
// is requested, it returns a gotenberg.ErrPDFFormatNotAvailable error.
func (engine UNO) Convert(ctx context.Context, logger *zap.Logger, format, inputPath, outputPath string) error {
err := engine.unoAPI.PDF(ctx, logger, inputPath, outputPath, uno.Options{
PDFformat: format,
// is requested, it returns a [gotenberg.ErrPDFFormatNotAvailable] error.
func (engine *LibreOfficePdfEngine) Convert(ctx context.Context, logger *zap.Logger, format, inputPath, outputPath string) error {
err := engine.unoAPI.Pdf(ctx, logger, inputPath, outputPath, api.Options{
PdfFormat: format,
})
if err == nil {
return nil
}
if errors.Is(err, uno.ErrInvalidPDFformat) {
return fmt.Errorf("convert PDF to '%s' with unoconv: %w", format, gotenberg.ErrPDFFormatNotAvailable)
if errors.Is(err, api.ErrInvalidPdfFormat) {
return fmt.Errorf("convert PDF to '%s' with LibreOffice: %w", format, gotenberg.ErrPDFFormatNotAvailable)
}
return fmt.Errorf("convert PDF to '%s' with unoconv: %w", format, err)
@@ -72,7 +72,7 @@ func (engine UNO) Convert(ctx context.Context, logger *zap.Logger, format, input
// Interface guards.
var (
_ gotenberg.Module = (*UNO)(nil)
_ gotenberg.Provisioner = (*UNO)(nil)
_ gotenberg.PDFEngine = (*UNO)(nil)
_ gotenberg.Module = (*LibreOfficePdfEngine)(nil)
_ gotenberg.Provisioner = (*LibreOfficePdfEngine)(nil)
_ gotenberg.PDFEngine = (*LibreOfficePdfEngine)(nil)
)