Removed unnecessary type re-implementations in favour of using generated types directly and providing aliases for import simplicity.
This commit is contained in:
@@ -15,35 +15,20 @@ import (
|
||||
|
||||
const defaultPollInterval = 2 * time.Second
|
||||
|
||||
// RasterTierOptions defines per-tier raster settings for conversion output.
|
||||
type RasterTierOptions struct {
|
||||
Resolution officeconvertapiv1.ConversionResolution
|
||||
JPEGQuality int32
|
||||
}
|
||||
|
||||
// HtmlFormattingPolicy configures which formatting features are ignored in HTML notes mode.
|
||||
type HtmlFormattingPolicy struct {
|
||||
IgnoreBold bool
|
||||
IgnoreItalic bool
|
||||
IgnoreUnderline bool
|
||||
IgnoreStrikethrough bool
|
||||
IgnoreFontSize bool
|
||||
IgnoreColor bool
|
||||
}
|
||||
type HtmlFormattingPolicy = officeconvertapiv1.HtmlFormattingPolicy
|
||||
|
||||
// NotesOptions controls speaker-notes extraction/output.
|
||||
type NotesOptions struct {
|
||||
Format officeconvertapiv1.NotesFormat
|
||||
HTMLUseParagraphTags *bool
|
||||
HTMLPolicy *HtmlFormattingPolicy
|
||||
}
|
||||
type NotesOptions = officeconvertapiv1.NotesOptions
|
||||
|
||||
// CreateConversionOptions configures optional full and thumbnail raster tiers.
|
||||
type CreateConversionOptions struct {
|
||||
Full *RasterTierOptions
|
||||
Thumbnail *RasterTierOptions
|
||||
Notes *NotesOptions
|
||||
}
|
||||
// SlideRasterOptions defines rendering settings for a raster output tier.
|
||||
type SlideRasterOptions = officeconvertapiv1.SlideRasterOptions
|
||||
|
||||
// SlideRaster_JPEG configures JPEG-specific rendering settings.
|
||||
type SlideRaster_JPEG = officeconvertapiv1.JpegOutputOptions
|
||||
|
||||
// CreateConversionOptions control the behaviour of a CreateConversion session.
|
||||
type CreateConversionOptions = officeconvertapiv1.CreateConversionRequest
|
||||
|
||||
// Client wraps the generated Connect client with orchestration-focused helpers.
|
||||
type Client struct {
|
||||
@@ -76,18 +61,9 @@ func (c *Client) SetPollInterval(interval time.Duration) {
|
||||
// CreateConversion starts a conversion session and returns upload metadata.
|
||||
func (c *Client) CreateConversion(
|
||||
ctx context.Context,
|
||||
sourceFilename string,
|
||||
options *CreateConversionOptions,
|
||||
) (*CreateConversionResponse, error) {
|
||||
message := &officeconvertapiv1.CreateConversionRequest{
|
||||
SourceFilename: sourceFilename,
|
||||
}
|
||||
if options != nil {
|
||||
message.Full = toProtoSlideRasterOptions(options.Full)
|
||||
message.Thumbnail = toProtoSlideRasterOptions(options.Thumbnail)
|
||||
message.Notes = toProtoNotesOptions(options.Notes)
|
||||
}
|
||||
req := connect.NewRequest(message)
|
||||
req := connect.NewRequest(options)
|
||||
res, err := c.rpc.CreateConversion(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -95,48 +71,6 @@ func (c *Client) CreateConversion(
|
||||
return augmentCreateConversionResponse(res.Msg)
|
||||
}
|
||||
|
||||
func toProtoSlideRasterOptions(
|
||||
options *RasterTierOptions,
|
||||
) *officeconvertapiv1.SlideRasterOptions {
|
||||
if options == nil {
|
||||
return nil
|
||||
}
|
||||
proto := &officeconvertapiv1.SlideRasterOptions{
|
||||
Resolution: options.Resolution,
|
||||
}
|
||||
if options.JPEGQuality != 0 {
|
||||
proto.Format = &officeconvertapiv1.SlideRasterOptions_Jpeg{
|
||||
Jpeg: &officeconvertapiv1.JpegOutputOptions{
|
||||
Quality: options.JPEGQuality,
|
||||
},
|
||||
}
|
||||
}
|
||||
return proto
|
||||
}
|
||||
|
||||
func toProtoNotesOptions(options *NotesOptions) *officeconvertapiv1.NotesOptions {
|
||||
if options == nil {
|
||||
return nil
|
||||
}
|
||||
proto := &officeconvertapiv1.NotesOptions{
|
||||
Format: options.Format,
|
||||
}
|
||||
if options.HTMLUseParagraphTags != nil {
|
||||
proto.HtmlUseParagraphTags = options.HTMLUseParagraphTags
|
||||
}
|
||||
if options.HTMLPolicy != nil {
|
||||
proto.HtmlPolicy = &officeconvertapiv1.HtmlFormattingPolicy{
|
||||
IgnoreBold: options.HTMLPolicy.IgnoreBold,
|
||||
IgnoreItalic: options.HTMLPolicy.IgnoreItalic,
|
||||
IgnoreUnderline: options.HTMLPolicy.IgnoreUnderline,
|
||||
IgnoreStrikethrough: options.HTMLPolicy.IgnoreStrikethrough,
|
||||
IgnoreFontSize: options.HTMLPolicy.IgnoreFontSize,
|
||||
IgnoreColor: options.HTMLPolicy.IgnoreColor,
|
||||
}
|
||||
}
|
||||
return proto
|
||||
}
|
||||
|
||||
// StartConversion signals that upload is complete and conversion can begin.
|
||||
func (c *Client) StartConversion(
|
||||
ctx context.Context,
|
||||
|
||||
@@ -18,8 +18,9 @@ type ConversionResult struct {
|
||||
func (c *Client) ConvertPPTXFile(ctx context.Context, localPPTXPath string) (*ConversionResult, error) {
|
||||
createRes, err := c.CreateConversion(
|
||||
ctx,
|
||||
filepath.Base(localPPTXPath),
|
||||
nil,
|
||||
&CreateConversionOptions{
|
||||
SourceFilename: filepath.Base(localPPTXPath),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create conversion: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user