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
|
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.
|
// HtmlFormattingPolicy configures which formatting features are ignored in HTML notes mode.
|
||||||
type HtmlFormattingPolicy struct {
|
type HtmlFormattingPolicy = officeconvertapiv1.HtmlFormattingPolicy
|
||||||
IgnoreBold bool
|
|
||||||
IgnoreItalic bool
|
|
||||||
IgnoreUnderline bool
|
|
||||||
IgnoreStrikethrough bool
|
|
||||||
IgnoreFontSize bool
|
|
||||||
IgnoreColor bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotesOptions controls speaker-notes extraction/output.
|
// NotesOptions controls speaker-notes extraction/output.
|
||||||
type NotesOptions struct {
|
type NotesOptions = officeconvertapiv1.NotesOptions
|
||||||
Format officeconvertapiv1.NotesFormat
|
|
||||||
HTMLUseParagraphTags *bool
|
|
||||||
HTMLPolicy *HtmlFormattingPolicy
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateConversionOptions configures optional full and thumbnail raster tiers.
|
// SlideRasterOptions defines rendering settings for a raster output tier.
|
||||||
type CreateConversionOptions struct {
|
type SlideRasterOptions = officeconvertapiv1.SlideRasterOptions
|
||||||
Full *RasterTierOptions
|
|
||||||
Thumbnail *RasterTierOptions
|
// SlideRaster_JPEG configures JPEG-specific rendering settings.
|
||||||
Notes *NotesOptions
|
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.
|
// Client wraps the generated Connect client with orchestration-focused helpers.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@@ -76,18 +61,9 @@ func (c *Client) SetPollInterval(interval time.Duration) {
|
|||||||
// CreateConversion starts a conversion session and returns upload metadata.
|
// CreateConversion starts a conversion session and returns upload metadata.
|
||||||
func (c *Client) CreateConversion(
|
func (c *Client) CreateConversion(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
sourceFilename string,
|
|
||||||
options *CreateConversionOptions,
|
options *CreateConversionOptions,
|
||||||
) (*CreateConversionResponse, error) {
|
) (*CreateConversionResponse, error) {
|
||||||
message := &officeconvertapiv1.CreateConversionRequest{
|
req := connect.NewRequest(options)
|
||||||
SourceFilename: sourceFilename,
|
|
||||||
}
|
|
||||||
if options != nil {
|
|
||||||
message.Full = toProtoSlideRasterOptions(options.Full)
|
|
||||||
message.Thumbnail = toProtoSlideRasterOptions(options.Thumbnail)
|
|
||||||
message.Notes = toProtoNotesOptions(options.Notes)
|
|
||||||
}
|
|
||||||
req := connect.NewRequest(message)
|
|
||||||
res, err := c.rpc.CreateConversion(ctx, req)
|
res, err := c.rpc.CreateConversion(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -95,48 +71,6 @@ func (c *Client) CreateConversion(
|
|||||||
return augmentCreateConversionResponse(res.Msg)
|
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.
|
// StartConversion signals that upload is complete and conversion can begin.
|
||||||
func (c *Client) StartConversion(
|
func (c *Client) StartConversion(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|||||||
@@ -18,8 +18,9 @@ type ConversionResult struct {
|
|||||||
func (c *Client) ConvertPPTXFile(ctx context.Context, localPPTXPath string) (*ConversionResult, error) {
|
func (c *Client) ConvertPPTXFile(ctx context.Context, localPPTXPath string) (*ConversionResult, error) {
|
||||||
createRes, err := c.CreateConversion(
|
createRes, err := c.CreateConversion(
|
||||||
ctx,
|
ctx,
|
||||||
filepath.Base(localPPTXPath),
|
&CreateConversionOptions{
|
||||||
nil,
|
SourceFilename: filepath.Base(localPPTXPath),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create conversion: %w", err)
|
return nil, fmt.Errorf("create conversion: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user