diff --git a/clients/go/officeconvertclient/client.go b/clients/go/officeconvertclient/client.go index a02f14c..76398e1 100644 --- a/clients/go/officeconvertclient/client.go +++ b/clients/go/officeconvertclient/client.go @@ -8,6 +8,7 @@ import ( "time" "connectrpc.com/connect" + "github.com/segmentio/ksuid" officeconvertapiv1 "gitea.auvem.com/end-internal/officeconvert/gen/go/officeconvertapi/v1" "gitea.auvem.com/end-internal/officeconvert/gen/go/officeconvertapi/v1/officeconvertapiv1connect" ) @@ -47,7 +48,7 @@ func (c *Client) CreateConversion( ctx context.Context, sourceFilename string, resolution officeconvertapiv1.ConversionResolution, -) (*officeconvertapiv1.CreateConversionResponse, error) { +) (*CreateConversionResponse, error) { req := connect.NewRequest(&officeconvertapiv1.CreateConversionRequest{ SourceFilename: sourceFilename, Resolution: resolution, @@ -56,46 +57,46 @@ func (c *Client) CreateConversion( if err != nil { return nil, err } - return res.Msg, nil + return augmentCreateConversionResponse(res.Msg) } // StartConversion signals that upload is complete and conversion can begin. func (c *Client) StartConversion( ctx context.Context, - conversionID string, -) (*officeconvertapiv1.StartConversionResponse, error) { + id ksuid.KSUID, +) (*StartConversionResponse, error) { req := connect.NewRequest(&officeconvertapiv1.StartConversionRequest{ - ConversionId: conversionID, + ConversionId: id.String(), }) res, err := c.rpc.StartConversion(ctx, req) if err != nil { return nil, err } - return res.Msg, nil + return augmentStartConversionResponse(res.Msg) } // GetConversionStatus returns the latest status for a conversion session. func (c *Client) GetConversionStatus( ctx context.Context, - conversionID string, -) (*officeconvertapiv1.GetConversionStatusResponse, error) { + id ksuid.KSUID, +) (*GetConversionStatusResponse, error) { req := connect.NewRequest(&officeconvertapiv1.GetConversionStatusRequest{ - ConversionId: conversionID, + ConversionId: id.String(), }) res, err := c.rpc.GetConversionStatus(ctx, req) if err != nil { return nil, err } - return res.Msg, nil + return augmentGetConversionStatusResponse(res.Msg) } // GetSlideDeck retrieves the final converted deck response. func (c *Client) GetSlideDeck( ctx context.Context, - conversionID string, + id ksuid.KSUID, ) (*officeconvertapiv1.GetSlideDeckResponse, error) { req := connect.NewRequest(&officeconvertapiv1.GetSlideDeckRequest{ - ConversionId: conversionID, + ConversionId: id.String(), }) res, err := c.rpc.GetSlideDeck(ctx, req) if err != nil { @@ -107,28 +108,28 @@ func (c *Client) GetSlideDeck( // DeleteConversion triggers immediate resource cleanup for a session. func (c *Client) DeleteConversion( ctx context.Context, - conversionID string, -) (*officeconvertapiv1.DeleteConversionResponse, error) { + id ksuid.KSUID, +) (*DeleteConversionResponse, error) { req := connect.NewRequest(&officeconvertapiv1.DeleteConversionRequest{ - ConversionId: conversionID, + ConversionId: id.String(), }) res, err := c.rpc.DeleteConversion(ctx, req) if err != nil { return nil, err } - return res.Msg, nil + return augmentDeleteConversionResponse(res.Msg) } // WaitForCompletion polls status until terminal completion or context cancellation. func (c *Client) WaitForCompletion( ctx context.Context, - conversionID string, -) (*officeconvertapiv1.GetConversionStatusResponse, error) { + id ksuid.KSUID, +) (*GetConversionStatusResponse, error) { ticker := time.NewTicker(c.pollInterval) defer ticker.Stop() for { - status, err := c.GetConversionStatus(ctx, conversionID) + status, err := c.GetConversionStatus(ctx, id) if err != nil { return nil, err } diff --git a/clients/go/officeconvertclient/orchestrate.go b/clients/go/officeconvertclient/orchestrate.go index 2882dc9..87e7ab7 100644 --- a/clients/go/officeconvertclient/orchestrate.go +++ b/clients/go/officeconvertclient/orchestrate.go @@ -10,7 +10,7 @@ import ( // ConversionResult groups the terminal status and deck payload for one conversion. type ConversionResult struct { - Status *officeconvertapiv1.GetConversionStatusResponse + Status *GetConversionStatusResponse Deck *officeconvertapiv1.SlideDeck } @@ -29,15 +29,15 @@ func (c *Client) ConvertPPTXFile(ctx context.Context, localPPTXPath string) (*Co return nil, err } - if _, err := c.StartConversion(ctx, createRes.ConversionId); err != nil { + if _, err := c.StartConversion(ctx, createRes.ConversionKSUID); err != nil { return nil, fmt.Errorf("start conversion: %w", err) } - statusRes, err := c.WaitForCompletion(ctx, createRes.ConversionId) + statusRes, err := c.WaitForCompletion(ctx, createRes.ConversionKSUID) if err != nil { return nil, fmt.Errorf("wait for completion: %w", err) } - deckRes, err := c.GetSlideDeck(ctx, createRes.ConversionId) + deckRes, err := c.GetSlideDeck(ctx, createRes.ConversionKSUID) if err != nil { return nil, fmt.Errorf("get slide deck: %w", err) } diff --git a/clients/go/officeconvertclient/types.go b/clients/go/officeconvertclient/types.go new file mode 100644 index 0000000..58abefa --- /dev/null +++ b/clients/go/officeconvertclient/types.go @@ -0,0 +1,83 @@ +package officeconvertclient + +import ( + "fmt" + + "github.com/segmentio/ksuid" + officeconvertapiv1 "gitea.auvem.com/end-internal/officeconvert/gen/go/officeconvertapi/v1" +) + +// CreateConversionResponse embeds the API message and adds a parsed KSUID alongside the wire ConversionId string. +type CreateConversionResponse struct { + *officeconvertapiv1.CreateConversionResponse + ConversionKSUID ksuid.KSUID +} + +// StartConversionResponse embeds the API message and adds a parsed KSUID alongside the wire ConversionId string. +type StartConversionResponse struct { + *officeconvertapiv1.StartConversionResponse + ConversionKSUID ksuid.KSUID +} + +// GetConversionStatusResponse embeds the API message and adds a parsed KSUID alongside the wire ConversionId string. +type GetConversionStatusResponse struct { + *officeconvertapiv1.GetConversionStatusResponse + ConversionKSUID ksuid.KSUID +} + +// DeleteConversionResponse embeds the API message and adds a parsed KSUID alongside the wire ConversionId string. +type DeleteConversionResponse struct { + *officeconvertapiv1.DeleteConversionResponse + ConversionKSUID ksuid.KSUID +} + +func parseConversionKSUID(s string) (ksuid.KSUID, error) { + if s == "" { + return ksuid.KSUID{}, fmt.Errorf("empty conversion id") + } + return ksuid.Parse(s) +} + +func augmentCreateConversionResponse(msg *officeconvertapiv1.CreateConversionResponse) (*CreateConversionResponse, error) { + k, err := parseConversionKSUID(msg.GetConversionId()) + if err != nil { + return nil, err + } + return &CreateConversionResponse{ + CreateConversionResponse: msg, + ConversionKSUID: k, + }, nil +} + +func augmentStartConversionResponse(msg *officeconvertapiv1.StartConversionResponse) (*StartConversionResponse, error) { + k, err := parseConversionKSUID(msg.GetConversionId()) + if err != nil { + return nil, err + } + return &StartConversionResponse{ + StartConversionResponse: msg, + ConversionKSUID: k, + }, nil +} + +func augmentGetConversionStatusResponse(msg *officeconvertapiv1.GetConversionStatusResponse) (*GetConversionStatusResponse, error) { + k, err := parseConversionKSUID(msg.GetConversionId()) + if err != nil { + return nil, err + } + return &GetConversionStatusResponse{ + GetConversionStatusResponse: msg, + ConversionKSUID: k, + }, nil +} + +func augmentDeleteConversionResponse(msg *officeconvertapiv1.DeleteConversionResponse) (*DeleteConversionResponse, error) { + k, err := parseConversionKSUID(msg.GetConversionId()) + if err != nil { + return nil, err + } + return &DeleteConversionResponse{ + DeleteConversionResponse: msg, + ConversionKSUID: k, + }, nil +} diff --git a/go.mod b/go.mod index f9e306a..7f58850 100644 --- a/go.mod +++ b/go.mod @@ -6,3 +6,5 @@ require ( connectrpc.com/connect v1.19.1 google.golang.org/protobuf v1.36.11 ) + +require github.com/segmentio/ksuid v1.0.4 diff --git a/go.sum b/go.sum index 6dfa443..e971143 100644 --- a/go.sum +++ b/go.sum @@ -2,5 +2,7 @@ connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14= connectrpc.com/connect v1.19.1/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c= +github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=