diff --git a/conversion/client/api_client.go b/conversion/client/api_client.go
deleted file mode 100644
index 747cc2619..000000000
--- a/conversion/client/api_client.go
+++ /dev/null
@@ -1,213 +0,0 @@
-// Copyright 2023 Anass Bouassaba.
-//
-// Use of this software is governed by the Business Source License
-// included in the file licenses/BSL.txt.
-//
-// As of the Change Date specified in that file, in accordance with
-// the Business Source License, use of this software will be governed
-// by the GNU Affero General Public License v3.0 only, included in the file
-// licenses/AGPL.txt.
-
-package client
-
-import (
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "net/http"
-
- "github.com/kouprlabs/voltaserve/conversion/config"
-)
-
-type APIClient struct {
- config *config.Config
-}
-
-func NewAPIClient() *APIClient {
- return &APIClient{
- config: config.GetConfig(),
- }
-}
-
-func (cl *APIClient) GetHealth() (string, error) {
- req, err := http.NewRequest("GET", fmt.Sprintf("%s/v2/health", cl.config.APIURL), nil)
- if err != nil {
- return "", err
- }
- client := &http.Client{}
- res, err := client.Do(req)
- if err != nil {
- return "", err
- }
- defer res.Body.Close()
- body, err := io.ReadAll(res.Body)
- if err != nil {
- return "", err
- }
- return string(body), nil
-}
-
-type PipelineRunOptions struct {
- PipelineID *string `json:"pipelineId,omitempty"`
- TaskID string `json:"taskId"`
- SnapshotID string `json:"snapshotId"`
- Bucket string `json:"bucket"`
- Key string `json:"key"`
- Payload map[string]string `json:"payload,omitempty"`
-}
-
-type SnapshotPatchOptions struct {
- Options PipelineRunOptions `json:"options"`
- Fields []string `json:"fields"`
- Original *S3Object `json:"original"`
- Preview *S3Object `json:"preview"`
- Text *S3Object `json:"text"`
- OCR *S3Object `json:"ocr"`
- Entities *S3Object `json:"entities"`
- Mosaic *S3Object `json:"mosaic"`
- Thumbnail *S3Object `json:"thumbnail"`
- Status *string `json:"status"`
- TaskID *string `json:"taskId"`
-}
-
-const (
- SnapshotStatusWaiting = "waiting"
- SnapshotStatusProcessing = "processing"
- SnapshotStatusReady = "ready"
- SnapshotStatusError = "error"
-)
-
-const (
- SnapshotFieldOriginal = "original"
- SnapshotFieldPreview = "preview"
- SnapshotFieldText = "text"
- SnapshotFieldOCR = "ocr"
- SnapshotFieldEntities = "entities"
- SnapshotFieldMosaic = "mosaic"
- SnapshotFieldThumbnail = "thumbnail"
- SnapshotFieldStatus = "status"
- SnapshotFieldLanguage = "language"
- SnapshotFieldTaskID = "taskId"
-)
-
-type S3Object struct {
- Bucket string `json:"bucket"`
- Key string `json:"key"`
- Size *int64 `json:"size,omitempty"`
- Image *ImageProps `json:"image,omitempty"`
-}
-
-type ImageProps struct {
- Width int `json:"width"`
- Height int `json:"height"`
-}
-
-func (cl *APIClient) PatchSnapshot(opts SnapshotPatchOptions) error {
- body, err := json.Marshal(opts)
- if err != nil {
- return err
- }
- req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/v2/snapshots/%s?api_key=%s", cl.config.APIURL, opts.Options.SnapshotID, cl.config.Security.APIKey), bytes.NewBuffer(body))
- if err != nil {
- return err
- }
- req.Header.Set("Content-Type", "application/json; charset=UTF-8")
- client := &http.Client{}
- res, err := client.Do(req)
- if err != nil {
- return err
- }
- defer res.Body.Close()
- return nil
-}
-
-type TaskCreateOptions struct {
- Name string `json:"name"`
- Error *string `json:"error,omitempty"`
- Percentage *int `json:"percentage,omitempty"`
- IsIndeterminate bool `json:"isIndeterminate"`
- UserID string `json:"userId"`
- Status string `json:"status"`
-}
-
-const (
- TaskStatusWaiting = "waiting"
- TaskStatusRunning = "running"
- TaskStatusSuccess = "success"
- TaskStatusError = "error"
-)
-
-func (cl *APIClient) CreateTask(opts TaskCreateOptions) error {
- body, err := json.Marshal(opts)
- if err != nil {
- return err
- }
- req, err := http.NewRequest("POST", fmt.Sprintf("%s/v2/tasks?api_key=%s", cl.config.APIURL, cl.config.Security.APIKey), bytes.NewBuffer(body))
- if err != nil {
- return err
- }
- req.Header.Set("Content-Type", "application/json; charset=UTF-8")
- client := &http.Client{}
- res, err := client.Do(req)
- if err != nil {
- return err
- }
- defer res.Body.Close()
- return nil
-}
-
-type TaskPatchOptions struct {
- Fields []string `json:"fields"`
- Name *string `json:"name"`
- Error *string `json:"error"`
- Percentage *int `json:"percentage"`
- IsIndeterminate *bool `json:"isIndeterminate"`
- UserID *string `json:"userId"`
- Status *string `json:"status"`
- Payload map[string]string `json:"payload"`
-}
-
-const (
- TaskFieldName = "name"
- TaskFieldError = "error"
- TaskFieldPercentage = "percentage"
- TaskFieldIsIndeterminate = "isIndeterminate"
- TaskFieldUserID = "userId"
- TaskFieldStatus = "status"
- TaskFieldPayload = "payload"
-)
-
-func (cl *APIClient) PatchTask(id string, opts TaskPatchOptions) error {
- body, err := json.Marshal(opts)
- if err != nil {
- return err
- }
- req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/v2/tasks/%s?api_key=%s", cl.config.APIURL, id, cl.config.Security.APIKey), bytes.NewBuffer(body))
- if err != nil {
- return err
- }
- req.Header.Set("Content-Type", "application/json; charset=UTF-8")
- client := &http.Client{}
- res, err := client.Do(req)
- if err != nil {
- return err
- }
- defer res.Body.Close()
- return nil
-}
-
-func (cl *APIClient) DeletTask(id string) error {
- req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/v2/tasks/%s?api_key=%s", cl.config.APIURL, id, cl.config.Security.APIKey), nil)
- if err != nil {
- return err
- }
- req.Header.Set("Content-Type", "application/json; charset=UTF-8")
- client := &http.Client{}
- res, err := client.Do(req)
- if err != nil {
- return err
- }
- defer res.Body.Close()
- return nil
-}
diff --git a/conversion/client/api_client/health_client.go b/conversion/client/api_client/health_client.go
new file mode 100644
index 000000000..e3e7abd7d
--- /dev/null
+++ b/conversion/client/api_client/health_client.go
@@ -0,0 +1,52 @@
+// Copyright 2023 Anass Bouassaba.
+//
+// Use of this software is governed by the Business Source License
+// included in the file licenses/BSL.txt.
+//
+// As of the Change Date specified in that file, in accordance with
+// the Business Source License, use of this software will be governed
+// by the GNU Affero General Public License v3.0 only, included in the file
+// licenses/AGPL.txt.
+
+package api_client
+
+import (
+ "fmt"
+ "io"
+ "net/http"
+
+ "github.com/kouprlabs/voltaserve/conversion/config"
+ "github.com/kouprlabs/voltaserve/conversion/infra"
+)
+
+type HealthClient struct {
+ config *config.Config
+}
+
+func NewHealthClient() *HealthClient {
+ return &HealthClient{
+ config: config.GetConfig(),
+ }
+}
+
+func (cl *HealthClient) Get() (string, error) {
+ req, err := http.NewRequest("GET", fmt.Sprintf("%s/v2/health", cl.config.APIURL), nil)
+ if err != nil {
+ return "", err
+ }
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ return "", err
+ }
+ defer func(Body io.ReadCloser) {
+ if err := Body.Close(); err != nil {
+ infra.GetLogger().Error(err)
+ }
+ }(resp.Body)
+ body, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return "", err
+ }
+ return string(body), nil
+}
diff --git a/conversion/client/api_client/snapshot_client.go b/conversion/client/api_client/snapshot_client.go
new file mode 100644
index 000000000..d3351223b
--- /dev/null
+++ b/conversion/client/api_client/snapshot_client.go
@@ -0,0 +1,110 @@
+// Copyright 2023 Anass Bouassaba.
+//
+// Use of this software is governed by the Business Source License
+// included in the file licenses/BSL.txt.
+//
+// As of the Change Date specified in that file, in accordance with
+// the Business Source License, use of this software will be governed
+// by the GNU Affero General Public License v3.0 only, included in the file
+// licenses/AGPL.txt.
+
+package api_client
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+
+ "github.com/kouprlabs/voltaserve/conversion/config"
+ "github.com/kouprlabs/voltaserve/conversion/infra"
+)
+
+type SnapshotClient struct {
+ config *config.Config
+}
+
+func NewSnapshotClient() *SnapshotClient {
+ return &SnapshotClient{
+ config: config.GetConfig(),
+ }
+}
+
+type SnapshotPatchOptions struct {
+ Options PipelineRunOptions `json:"options"`
+ Fields []string `json:"fields"`
+ Original *S3Object `json:"original"`
+ Preview *S3Object `json:"preview"`
+ Text *S3Object `json:"text"`
+ OCR *S3Object `json:"ocr"`
+ Entities *S3Object `json:"entities"`
+ Mosaic *S3Object `json:"mosaic"`
+ Thumbnail *S3Object `json:"thumbnail"`
+ Status *string `json:"status"`
+ TaskID *string `json:"taskId"`
+}
+
+const (
+ SnapshotStatusWaiting = "waiting"
+ SnapshotStatusProcessing = "processing"
+ SnapshotStatusReady = "ready"
+ SnapshotStatusError = "error"
+)
+
+const (
+ SnapshotFieldOriginal = "original"
+ SnapshotFieldPreview = "preview"
+ SnapshotFieldText = "text"
+ SnapshotFieldOCR = "ocr"
+ SnapshotFieldEntities = "entities"
+ SnapshotFieldMosaic = "mosaic"
+ SnapshotFieldThumbnail = "thumbnail"
+ SnapshotFieldStatus = "status"
+ SnapshotFieldLanguage = "language"
+ SnapshotFieldTaskID = "taskId"
+)
+
+type PipelineRunOptions struct {
+ PipelineID *string `json:"pipelineId,omitempty"`
+ TaskID string `json:"taskId"`
+ SnapshotID string `json:"snapshotId"`
+ Bucket string `json:"bucket"`
+ Key string `json:"key"`
+ Payload map[string]string `json:"payload,omitempty"`
+}
+
+type S3Object struct {
+ Bucket string `json:"bucket"`
+ Key string `json:"key"`
+ Size *int64 `json:"size,omitempty"`
+ Image *ImageProps `json:"image,omitempty"`
+}
+
+type ImageProps struct {
+ Width int `json:"width"`
+ Height int `json:"height"`
+}
+
+func (cl *SnapshotClient) Patch(opts SnapshotPatchOptions) error {
+ body, err := json.Marshal(opts)
+ if err != nil {
+ return err
+ }
+ req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/v2/snapshots/%s?api_key=%s", cl.config.APIURL, opts.Options.SnapshotID, cl.config.Security.APIKey), bytes.NewBuffer(body))
+ if err != nil {
+ return err
+ }
+ req.Header.Set("Content-Type", "application/json; charset=UTF-8")
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ return err
+ }
+ defer func(Body io.ReadCloser) {
+ if err := Body.Close(); err != nil {
+ infra.GetLogger().Error(err)
+ }
+ }(resp.Body)
+ return nil
+}
diff --git a/conversion/client/api_client/task_client.go b/conversion/client/api_client/task_client.go
new file mode 100644
index 000000000..c107003fd
--- /dev/null
+++ b/conversion/client/api_client/task_client.go
@@ -0,0 +1,130 @@
+// Copyright 2023 Anass Bouassaba.
+//
+// Use of this software is governed by the Business Source License
+// included in the file licenses/BSL.txt.
+//
+// As of the Change Date specified in that file, in accordance with
+// the Business Source License, use of this software will be governed
+// by the GNU Affero General Public License v3.0 only, included in the file
+// licenses/AGPL.txt.
+
+package api_client
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+
+ "github.com/kouprlabs/voltaserve/conversion/config"
+ "github.com/kouprlabs/voltaserve/conversion/infra"
+)
+
+type TaskClient struct {
+ config *config.Config
+}
+
+func NewTaskClient() *TaskClient {
+ return &TaskClient{
+ config: config.GetConfig(),
+ }
+}
+
+type TaskCreateOptions struct {
+ Name string `json:"name"`
+ Error *string `json:"error,omitempty"`
+ Percentage *int `json:"percentage,omitempty"`
+ IsIndeterminate bool `json:"isIndeterminate"`
+ UserID string `json:"userId"`
+ Status string `json:"status"`
+}
+
+const (
+ TaskStatusWaiting = "waiting"
+ TaskStatusRunning = "running"
+ TaskStatusSuccess = "success"
+ TaskStatusError = "error"
+)
+
+func (cl *TaskClient) Create(opts TaskCreateOptions) error {
+ body, err := json.Marshal(opts)
+ if err != nil {
+ return err
+ }
+ req, err := http.NewRequest("POST", fmt.Sprintf("%s/v2/tasks?api_key=%s", cl.config.APIURL, cl.config.Security.APIKey), bytes.NewBuffer(body))
+ if err != nil {
+ return err
+ }
+ req.Header.Set("Content-Type", "application/json; charset=UTF-8")
+ client := &http.Client{}
+ res, err := client.Do(req)
+ if err != nil {
+ return err
+ }
+ defer res.Body.Close()
+ return nil
+}
+
+type TaskPatchOptions struct {
+ Fields []string `json:"fields"`
+ Name *string `json:"name"`
+ Error *string `json:"error"`
+ Percentage *int `json:"percentage"`
+ IsIndeterminate *bool `json:"isIndeterminate"`
+ UserID *string `json:"userId"`
+ Status *string `json:"status"`
+ Payload map[string]string `json:"payload"`
+}
+
+const (
+ TaskFieldName = "name"
+ TaskFieldError = "error"
+ TaskFieldPercentage = "percentage"
+ TaskFieldIsIndeterminate = "isIndeterminate"
+ TaskFieldUserID = "userId"
+ TaskFieldStatus = "status"
+ TaskFieldPayload = "payload"
+)
+
+func (cl *TaskClient) Patch(id string, opts TaskPatchOptions) error {
+ body, err := json.Marshal(opts)
+ if err != nil {
+ return err
+ }
+ req, err := http.NewRequest("PATCH", fmt.Sprintf("%s/v2/tasks/%s?api_key=%s", cl.config.APIURL, id, cl.config.Security.APIKey), bytes.NewBuffer(body))
+ if err != nil {
+ return err
+ }
+ req.Header.Set("Content-Type", "application/json; charset=UTF-8")
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ return err
+ }
+ defer func(Body io.ReadCloser) {
+ if err := Body.Close(); err != nil {
+ infra.GetLogger().Error(err)
+ }
+ }(resp.Body)
+ return nil
+}
+
+func (cl *TaskClient) Delete(id string) error {
+ req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/v2/tasks/%s?api_key=%s", cl.config.APIURL, id, cl.config.Security.APIKey), nil)
+ if err != nil {
+ return err
+ }
+ req.Header.Set("Content-Type", "application/json; charset=UTF-8")
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ return err
+ }
+ defer func(Body io.ReadCloser) {
+ if err := Body.Close(); err != nil {
+ infra.GetLogger().Error(err)
+ }
+ }(resp.Body)
+ return nil
+}
diff --git a/conversion/client/language_client.go b/conversion/client/language_client/language_client.go
similarity index 98%
rename from conversion/client/language_client.go
rename to conversion/client/language_client/language_client.go
index 4ef5e8425..3219962ca 100644
--- a/conversion/client/language_client.go
+++ b/conversion/client/language_client/language_client.go
@@ -8,7 +8,7 @@
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
-package client
+package language_client
import (
"bytes"
diff --git a/conversion/client/mosaic_client.go b/conversion/client/mosaic_client/mosaic_client.go
similarity index 99%
rename from conversion/client/mosaic_client.go
rename to conversion/client/mosaic_client/mosaic_client.go
index 3ded36be1..4a0dbed7a 100644
--- a/conversion/client/mosaic_client.go
+++ b/conversion/client/mosaic_client/mosaic_client.go
@@ -8,7 +8,7 @@
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
-package client
+package mosaic_client
import (
"bytes"
diff --git a/conversion/identifier/pipeline_identifier.go b/conversion/identifier/pipeline_identifier.go
index 591346fd1..b51124a9b 100644
--- a/conversion/identifier/pipeline_identifier.go
+++ b/conversion/identifier/pipeline_identifier.go
@@ -11,7 +11,7 @@
package identifier
import (
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/model"
)
@@ -25,7 +25,7 @@ func NewPipelineIdentifier() *PipelineIdentifier {
}
}
-func (pi *PipelineIdentifier) Identify(opts client.PipelineRunOptions) string {
+func (pi *PipelineIdentifier) Identify(opts api_client.PipelineRunOptions) string {
if opts.PipelineID != nil {
return *opts.PipelineID
} else {
diff --git a/conversion/model/types.go b/conversion/model/types.go
index 9e918d50a..aa64a9ab6 100644
--- a/conversion/model/types.go
+++ b/conversion/model/types.go
@@ -10,12 +10,14 @@
package model
-import "github.com/kouprlabs/voltaserve/conversion/client"
+import (
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
+)
type Pipeline interface {
- Run(client.PipelineRunOptions) error
+ Run(api_client.PipelineRunOptions) error
}
type Builder interface {
- Build(client.PipelineRunOptions) error
+ Build(api_client.PipelineRunOptions) error
}
diff --git a/conversion/pipeline/audio_video_pipeline.go b/conversion/pipeline/audio_video_pipeline.go
index 660cc41ad..51600a6a1 100644
--- a/conversion/pipeline/audio_video_pipeline.go
+++ b/conversion/pipeline/audio_video_pipeline.go
@@ -17,7 +17,7 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/infra"
@@ -26,24 +26,26 @@ import (
)
type audioVideoPipeline struct {
- videoProc *processor.VideoProcessor
- imageProc *processor.ImageProcessor
- s3 *infra.S3Manager
- apiClient *client.APIClient
- config *config.Config
+ videoProc *processor.VideoProcessor
+ imageProc *processor.ImageProcessor
+ s3 *infra.S3Manager
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
+ config *config.Config
}
func NewAudioVideoPipeline() model.Pipeline {
return &audioVideoPipeline{
- videoProc: processor.NewVideoProcessor(),
- imageProc: processor.NewImageProcessor(),
- s3: infra.NewS3Manager(),
- apiClient: client.NewAPIClient(),
- config: config.GetConfig(),
+ videoProc: processor.NewVideoProcessor(),
+ imageProc: processor.NewImageProcessor(),
+ s3: infra.NewS3Manager(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
+ config: config.GetConfig(),
}
}
-func (p *audioVideoPipeline) Run(opts client.PipelineRunOptions) error {
+func (p *audioVideoPipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -55,16 +57,16 @@ func (p *audioVideoPipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Creating thumbnail."),
}); err != nil {
return err
}
// Here we intentionally ignore the error, as the media file may contain just audio
_ = p.createThumbnail(inputPath, opts)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Saving preview."),
}); err != nil {
return err
@@ -72,17 +74,17 @@ func (p *audioVideoPipeline) Run(opts client.PipelineRunOptions) error {
if err := p.saveOriginalAsPreview(inputPath, opts); err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName, client.TaskFieldStatus},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName, api_client.TaskFieldStatus},
Name: helper.ToPtr("Done."),
- Status: helper.ToPtr(client.TaskStatusSuccess),
+ Status: helper.ToPtr(api_client.TaskStatusSuccess),
}); err != nil {
return err
}
return nil
}
-func (p *audioVideoPipeline) createThumbnail(inputPath string, opts client.PipelineRunOptions) error {
+func (p *audioVideoPipeline) createThumbnail(inputPath string, opts api_client.PipelineRunOptions) error {
tmpPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".png")
defer func(path string) {
_, err := os.Stat(path)
@@ -103,7 +105,7 @@ func (p *audioVideoPipeline) createThumbnail(inputPath string, opts client.Pipel
if err != nil {
return err
}
- s3Object := &client.S3Object{
+ s3Object := &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/thumbnail" + filepath.Ext(tmpPath),
Image: props,
@@ -112,9 +114,9 @@ func (p *audioVideoPipeline) createThumbnail(inputPath string, opts client.Pipel
if err := p.s3.PutFile(s3Object.Key, tmpPath, helper.DetectMimeFromFile(tmpPath), s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldThumbnail},
+ Fields: []string{api_client.SnapshotFieldThumbnail},
Thumbnail: s3Object,
}); err != nil {
return err
@@ -122,15 +124,15 @@ func (p *audioVideoPipeline) createThumbnail(inputPath string, opts client.Pipel
return nil
}
-func (p *audioVideoPipeline) saveOriginalAsPreview(inputPath string, opts client.PipelineRunOptions) error {
+func (p *audioVideoPipeline) saveOriginalAsPreview(inputPath string, opts api_client.PipelineRunOptions) error {
stat, err := os.Stat(inputPath)
if err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
- Preview: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldPreview},
+ Preview: &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.Key,
Size: helper.ToPtr(stat.Size()),
diff --git a/conversion/pipeline/dispatcher.go b/conversion/pipeline/dispatcher.go
index 25469c224..a117e9518 100644
--- a/conversion/pipeline/dispatcher.go
+++ b/conversion/pipeline/dispatcher.go
@@ -11,7 +11,7 @@
package pipeline
import (
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/errorpkg"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
@@ -28,7 +28,8 @@ type Dispatcher struct {
mosaicPipeline model.Pipeline
glbPipeline model.Pipeline
zipPipeline model.Pipeline
- apiClient *client.APIClient
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
}
func NewDispatcher() *Dispatcher {
@@ -42,22 +43,22 @@ func NewDispatcher() *Dispatcher {
mosaicPipeline: NewMosaicPipeline(),
glbPipeline: NewGLBPipeline(),
zipPipeline: NewZIPPipeline(),
- apiClient: client.NewAPIClient(),
+ taskClient: api_client.NewTaskClient(),
}
}
-func (d *Dispatcher) Dispatch(opts client.PipelineRunOptions) error {
- if err := d.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+func (d *Dispatcher) Dispatch(opts api_client.PipelineRunOptions) error {
+ if err := d.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldStatus},
- Status: helper.ToPtr(client.SnapshotStatusProcessing),
+ Fields: []string{api_client.SnapshotFieldStatus},
+ Status: helper.ToPtr(api_client.SnapshotStatusProcessing),
}); err != nil {
return err
}
- if err := d.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
+ if err := d.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
Name: helper.ToPtr("Processing."),
- Fields: []string{client.TaskFieldStatus},
- Status: helper.ToPtr(client.TaskStatusRunning),
+ Fields: []string{api_client.TaskFieldStatus},
+ Status: helper.ToPtr(api_client.TaskStatusRunning),
}); err != nil {
return err
}
@@ -81,30 +82,30 @@ func (d *Dispatcher) Dispatch(opts client.PipelineRunOptions) error {
err = d.zipPipeline.Run(opts)
}
if err != nil {
- if err := d.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := d.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldStatus},
- Status: helper.ToPtr(client.SnapshotStatusError),
+ Fields: []string{api_client.SnapshotFieldStatus},
+ Status: helper.ToPtr(api_client.SnapshotStatusError),
}); err != nil {
return err
}
- if err := d.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldStatus, client.TaskFieldError},
- Status: helper.ToPtr(client.TaskStatusError),
+ if err := d.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldStatus, api_client.TaskFieldError},
+ Status: helper.ToPtr(api_client.TaskStatusError),
Error: helper.ToPtr(errorpkg.GetUserFriendlyMessage(err.Error(), errorpkg.FallbackMessage)),
}); err != nil {
return err
}
return err
} else {
- if err := d.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := d.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldStatus, client.SnapshotFieldTaskID},
- Status: helper.ToPtr(client.SnapshotStatusReady),
+ Fields: []string{api_client.SnapshotFieldStatus, api_client.SnapshotFieldTaskID},
+ Status: helper.ToPtr(api_client.SnapshotStatusReady),
}); err != nil {
return err
}
- if err := d.apiClient.DeletTask(opts.TaskID); err != nil {
+ if err := d.taskClient.Delete(opts.TaskID); err != nil {
return err
}
return nil
diff --git a/conversion/pipeline/glb_pipeline.go b/conversion/pipeline/glb_pipeline.go
index 6c3c56830..8617a2dcf 100644
--- a/conversion/pipeline/glb_pipeline.go
+++ b/conversion/pipeline/glb_pipeline.go
@@ -17,7 +17,7 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/infra"
@@ -26,24 +26,26 @@ import (
)
type glbPipeline struct {
- glbProc *processor.GLBProcessor
- imageProc *processor.ImageProcessor
- s3 *infra.S3Manager
- apiClient *client.APIClient
- config *config.Config
+ glbProc *processor.GLBProcessor
+ imageProc *processor.ImageProcessor
+ s3 *infra.S3Manager
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
+ config *config.Config
}
func NewGLBPipeline() model.Pipeline {
return &glbPipeline{
- glbProc: processor.NewGLBProcessor(),
- imageProc: processor.NewImageProcessor(),
- s3: infra.NewS3Manager(),
- apiClient: client.NewAPIClient(),
- config: config.GetConfig(),
+ glbProc: processor.NewGLBProcessor(),
+ imageProc: processor.NewImageProcessor(),
+ s3: infra.NewS3Manager(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
+ config: config.GetConfig(),
}
}
-func (p *glbPipeline) Run(opts client.PipelineRunOptions) error {
+func (p *glbPipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -55,8 +57,8 @@ func (p *glbPipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Creating thumbnail."),
}); err != nil {
return err
@@ -68,10 +70,10 @@ func (p *glbPipeline) Run(opts client.PipelineRunOptions) error {
if err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
- Preview: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldPreview},
+ Preview: &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.Key,
Size: helper.ToPtr(stat.Size()),
@@ -82,7 +84,7 @@ func (p *glbPipeline) Run(opts client.PipelineRunOptions) error {
return nil
}
-func (p *glbPipeline) createThumbnail(inputPath string, opts client.PipelineRunOptions) error {
+func (p *glbPipeline) createThumbnail(inputPath string, opts api_client.PipelineRunOptions) error {
tmpPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".jpeg")
defer func(path string) {
if err := os.Remove(path); errors.Is(err, os.ErrNotExist) {
@@ -101,7 +103,7 @@ func (p *glbPipeline) createThumbnail(inputPath string, opts client.PipelineRunO
if err != nil {
return err
}
- s3Object := &client.S3Object{
+ s3Object := &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/thumbnail" + filepath.Ext(tmpPath),
Image: props,
@@ -110,9 +112,9 @@ func (p *glbPipeline) createThumbnail(inputPath string, opts client.PipelineRunO
if err := p.s3.PutFile(s3Object.Key, tmpPath, helper.DetectMimeFromFile(tmpPath), s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldThumbnail},
+ Fields: []string{api_client.SnapshotFieldThumbnail},
Thumbnail: s3Object,
}); err != nil {
return err
diff --git a/conversion/pipeline/image_pipeline.go b/conversion/pipeline/image_pipeline.go
index 16addbafe..186c2e223 100644
--- a/conversion/pipeline/image_pipeline.go
+++ b/conversion/pipeline/image_pipeline.go
@@ -17,7 +17,7 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
@@ -27,24 +27,26 @@ import (
)
type imagePipeline struct {
- imageProc *processor.ImageProcessor
- s3 *infra.S3Manager
- apiClient *client.APIClient
- fileIdent *identifier.FileIdentifier
- config *config.Config
+ imageProc *processor.ImageProcessor
+ s3 *infra.S3Manager
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
+ fileIdent *identifier.FileIdentifier
+ config *config.Config
}
func NewImagePipeline() model.Pipeline {
return &imagePipeline{
- imageProc: processor.NewImageProcessor(),
- s3: infra.NewS3Manager(),
- apiClient: client.NewAPIClient(),
- fileIdent: identifier.NewFileIdentifier(),
- config: config.GetConfig(),
+ imageProc: processor.NewImageProcessor(),
+ s3: infra.NewS3Manager(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
+ fileIdent: identifier.NewFileIdentifier(),
+ config: config.GetConfig(),
}
}
-func (p *imagePipeline) Run(opts client.PipelineRunOptions) error {
+func (p *imagePipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -56,8 +58,8 @@ func (p *imagePipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Measuring image dimensions."),
}); err != nil {
return err
@@ -68,8 +70,8 @@ func (p *imagePipeline) Run(opts client.PipelineRunOptions) error {
}
var imagePath string
if filepath.Ext(inputPath) == ".tiff" {
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Converting TIFF image to JPEG format."),
}); err != nil {
return err
@@ -92,25 +94,25 @@ func (p *imagePipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(imagePath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Creating thumbnail."),
}); err != nil {
return err
}
// We don't consider failing the creation of the thumbnail as an error
_ = p.createThumbnail(imagePath, opts)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName, client.TaskFieldStatus},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName, api_client.TaskFieldStatus},
Name: helper.ToPtr("Done."),
- Status: helper.ToPtr(client.TaskStatusSuccess),
+ Status: helper.ToPtr(api_client.TaskStatusSuccess),
}); err != nil {
return err
}
return nil
}
-func (p *imagePipeline) measureImageDimensions(inputPath string, opts client.PipelineRunOptions) (*client.ImageProps, error) {
+func (p *imagePipeline) measureImageDimensions(inputPath string, opts api_client.PipelineRunOptions) (*api_client.ImageProps, error) {
imageProps, err := p.imageProc.MeasureImage(inputPath)
if err != nil {
return nil, err
@@ -119,10 +121,10 @@ func (p *imagePipeline) measureImageDimensions(inputPath string, opts client.Pip
if err != nil {
return nil, err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldOriginal},
- Original: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldOriginal},
+ Original: &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.Key,
Size: helper.ToPtr(stat.Size()),
@@ -134,7 +136,7 @@ func (p *imagePipeline) measureImageDimensions(inputPath string, opts client.Pip
return imageProps, nil
}
-func (p *imagePipeline) createThumbnail(inputPath string, opts client.PipelineRunOptions) error {
+func (p *imagePipeline) createThumbnail(inputPath string, opts api_client.PipelineRunOptions) error {
tmpPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".png")
isAvailable, err := p.imageProc.Thumbnail(inputPath, tmpPath)
if err != nil {
@@ -159,7 +161,7 @@ func (p *imagePipeline) createThumbnail(inputPath string, opts client.PipelineRu
if err != nil {
return err
}
- s3Object := &client.S3Object{
+ s3Object := &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/thumbnail" + filepath.Ext(tmpPath),
Image: props,
@@ -168,9 +170,9 @@ func (p *imagePipeline) createThumbnail(inputPath string, opts client.PipelineRu
if err := p.s3.PutFile(s3Object.Key, tmpPath, helper.DetectMimeFromFile(tmpPath), s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldThumbnail},
+ Fields: []string{api_client.SnapshotFieldThumbnail},
Thumbnail: s3Object,
}); err != nil {
return err
@@ -178,7 +180,7 @@ func (p *imagePipeline) createThumbnail(inputPath string, opts client.PipelineRu
return nil
}
-func (p *imagePipeline) convertTIFFToJPEG(inputPath string, imageProps client.ImageProps, opts client.PipelineRunOptions) (*string, error) {
+func (p *imagePipeline) convertTIFFToJPEG(inputPath string, imageProps api_client.ImageProps, opts api_client.PipelineRunOptions) (*string, error) {
jpegPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".jpg")
if err := p.imageProc.ConvertImage(inputPath, jpegPath); err != nil {
return nil, err
@@ -187,7 +189,7 @@ func (p *imagePipeline) convertTIFFToJPEG(inputPath string, imageProps client.Im
if err != nil {
return nil, err
}
- s3Object := &client.S3Object{
+ s3Object := &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/preview.jpg",
Size: helper.ToPtr(stat.Size()),
@@ -196,9 +198,9 @@ func (p *imagePipeline) convertTIFFToJPEG(inputPath string, imageProps client.Im
if err := p.s3.PutFile(s3Object.Key, jpegPath, helper.DetectMimeFromFile(jpegPath), s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return nil, err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
+ Fields: []string{api_client.SnapshotFieldPreview},
Preview: s3Object,
}); err != nil {
return nil, err
@@ -206,15 +208,15 @@ func (p *imagePipeline) convertTIFFToJPEG(inputPath string, imageProps client.Im
return &jpegPath, nil
}
-func (p *imagePipeline) saveOriginalAsPreview(inputPath string, opts client.PipelineRunOptions) error {
+func (p *imagePipeline) saveOriginalAsPreview(inputPath string, opts api_client.PipelineRunOptions) error {
stat, err := os.Stat(inputPath)
if err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
- Preview: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldPreview},
+ Preview: &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.Key,
Size: helper.ToPtr(stat.Size()),
diff --git a/conversion/pipeline/insights_pipeline.go b/conversion/pipeline/insights_pipeline.go
index 7ab0d1b2b..af78b8816 100644
--- a/conversion/pipeline/insights_pipeline.go
+++ b/conversion/pipeline/insights_pipeline.go
@@ -18,7 +18,8 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
+ "github.com/kouprlabs/voltaserve/conversion/client/language_client"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
"github.com/kouprlabs/voltaserve/conversion/infra"
@@ -32,8 +33,9 @@ type insightsPipeline struct {
ocrProc *processor.OCRProcessor
fileIdent *identifier.FileIdentifier
s3 *infra.S3Manager
- apiClient *client.APIClient
- languageClient *client.LanguageClient
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
+ languageClient *language_client.LanguageClient
}
func NewInsightsPipeline() model.Pipeline {
@@ -43,12 +45,13 @@ func NewInsightsPipeline() model.Pipeline {
ocrProc: processor.NewOCRProcessor(),
fileIdent: identifier.NewFileIdentifier(),
s3: infra.NewS3Manager(),
- apiClient: client.NewAPIClient(),
- languageClient: client.NewLanguageClient(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
+ languageClient: language_client.NewLanguageClient(),
}
}
-func (p *insightsPipeline) Run(opts client.PipelineRunOptions) error {
+func (p *insightsPipeline) Run(opts api_client.PipelineRunOptions) error {
if opts.Payload == nil || opts.Payload["language"] == "" {
return errors.New("language is undefined")
}
@@ -63,8 +66,8 @@ func (p *insightsPipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Extracting text."),
}); err != nil {
return err
@@ -73,8 +76,8 @@ func (p *insightsPipeline) Run(opts client.PipelineRunOptions) error {
if err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Collecting entities."),
}); err != nil {
return err
@@ -82,17 +85,17 @@ func (p *insightsPipeline) Run(opts client.PipelineRunOptions) error {
if err := p.createEntities(*text, opts); err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName, client.TaskFieldStatus},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName, api_client.TaskFieldStatus},
Name: helper.ToPtr("Done."),
- Status: helper.ToPtr(client.TaskStatusSuccess),
+ Status: helper.ToPtr(api_client.TaskStatusSuccess),
}); err != nil {
return err
}
return nil
}
-func (p *insightsPipeline) createText(inputPath string, opts client.PipelineRunOptions) (*string, error) {
+func (p *insightsPipeline) createText(inputPath string, opts api_client.PipelineRunOptions) (*string, error) {
/* Generate PDF/A */
var pdfPath string
if p.fileIdent.IsImage(opts.Key) {
@@ -130,7 +133,7 @@ func (p *insightsPipeline) createText(inputPath string, opts client.PipelineRunO
if err != nil {
return nil, err
}
- s3Object := client.S3Object{
+ s3Object := api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/ocr.pdf",
Size: helper.ToPtr(stat.Size()),
@@ -138,9 +141,9 @@ func (p *insightsPipeline) createText(inputPath string, opts client.PipelineRunO
if err := p.s3.PutFile(s3Object.Key, pdfPath, helper.DetectMimeFromFile(pdfPath), s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return nil, err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldOCR},
+ Fields: []string{api_client.SnapshotFieldOCR},
OCR: &s3Object,
}); err != nil {
return nil, err
@@ -156,7 +159,7 @@ func (p *insightsPipeline) createText(inputPath string, opts client.PipelineRunO
return nil, err
}
/* Set text S3 object */
- s3Object := client.S3Object{
+ s3Object := api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/text.txt",
Size: helper.ToPtr(int64(len(*text))),
@@ -164,9 +167,9 @@ func (p *insightsPipeline) createText(inputPath string, opts client.PipelineRunO
if err := p.s3.PutText(s3Object.Key, *text, "text/plain", s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return nil, err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldText},
+ Fields: []string{api_client.SnapshotFieldText},
Text: &s3Object,
}); err != nil {
return nil, err
@@ -174,14 +177,14 @@ func (p *insightsPipeline) createText(inputPath string, opts client.PipelineRunO
return text, nil
}
-func (p *insightsPipeline) createEntities(text string, opts client.PipelineRunOptions) error {
+func (p *insightsPipeline) createEntities(text string, opts api_client.PipelineRunOptions) error {
if len(text) == 0 {
return errors.New("text is empty")
}
if len(text) > 1000000 {
return errors.New("text exceeds supported limit of 1000000 characters")
}
- res, err := p.languageClient.GetEntities(client.GetEntitiesOptions{
+ res, err := p.languageClient.GetEntities(language_client.GetEntitiesOptions{
Text: text,
Language: opts.Payload["language"],
})
@@ -193,7 +196,7 @@ func (p *insightsPipeline) createEntities(text string, opts client.PipelineRunOp
return err
}
content := string(b)
- s3Object := client.S3Object{
+ s3Object := api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/entities.json",
Size: helper.ToPtr(int64(len(content))),
@@ -201,9 +204,9 @@ func (p *insightsPipeline) createEntities(text string, opts client.PipelineRunOp
if err := p.s3.PutText(s3Object.Key, content, "application/json", s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldEntities},
+ Fields: []string{api_client.SnapshotFieldEntities},
Entities: &s3Object,
}); err != nil {
return err
diff --git a/conversion/pipeline/mosaic_pipeline.go b/conversion/pipeline/mosaic_pipeline.go
index 3d4a2fa3d..72033a792 100644
--- a/conversion/pipeline/mosaic_pipeline.go
+++ b/conversion/pipeline/mosaic_pipeline.go
@@ -17,7 +17,8 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
+ "github.com/kouprlabs/voltaserve/conversion/client/mosaic_client"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
"github.com/kouprlabs/voltaserve/conversion/infra"
@@ -26,24 +27,26 @@ import (
)
type mosaicPipeline struct {
- videoProc *processor.VideoProcessor
- fileIdent *identifier.FileIdentifier
- s3 *infra.S3Manager
- apiClient *client.APIClient
- mosaicClient *client.MosaicClient
+ videoProc *processor.VideoProcessor
+ fileIdent *identifier.FileIdentifier
+ s3 *infra.S3Manager
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
+ mosaicClient *mosaic_client.MosaicClient
}
func NewMosaicPipeline() model.Pipeline {
return &mosaicPipeline{
- videoProc: processor.NewVideoProcessor(),
- fileIdent: identifier.NewFileIdentifier(),
- s3: infra.NewS3Manager(),
- apiClient: client.NewAPIClient(),
- mosaicClient: client.NewMosaicClient(),
+ videoProc: processor.NewVideoProcessor(),
+ fileIdent: identifier.NewFileIdentifier(),
+ s3: infra.NewS3Manager(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
+ mosaicClient: mosaic_client.NewMosaicClient(),
}
}
-func (p *mosaicPipeline) Run(opts client.PipelineRunOptions) error {
+func (p *mosaicPipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -55,8 +58,8 @@ func (p *mosaicPipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Creating mosaic."),
}); err != nil {
return err
@@ -64,29 +67,29 @@ func (p *mosaicPipeline) Run(opts client.PipelineRunOptions) error {
if err := p.create(inputPath, opts); err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName, client.TaskFieldStatus},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName, api_client.TaskFieldStatus},
Name: helper.ToPtr("Done."),
- Status: helper.ToPtr(client.TaskStatusSuccess),
+ Status: helper.ToPtr(api_client.TaskStatusSuccess),
}); err != nil {
return err
}
return nil
}
-func (p *mosaicPipeline) create(inputPath string, opts client.PipelineRunOptions) error {
+func (p *mosaicPipeline) create(inputPath string, opts api_client.PipelineRunOptions) error {
if p.fileIdent.IsImage(opts.Key) {
- if _, err := p.mosaicClient.Create(client.MosaicCreateOptions{
+ if _, err := p.mosaicClient.Create(mosaic_client.MosaicCreateOptions{
Path: inputPath,
S3Key: filepath.FromSlash(opts.SnapshotID),
S3Bucket: opts.Bucket,
}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldMosaic},
- Mosaic: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldMosaic},
+ Mosaic: &api_client.S3Object{
Key: filepath.FromSlash(opts.SnapshotID + "/mosaic.json"),
Bucket: opts.Bucket,
},
diff --git a/conversion/pipeline/office_pipeline.go b/conversion/pipeline/office_pipeline.go
index 5bcc9a588..22e08fdca 100644
--- a/conversion/pipeline/office_pipeline.go
+++ b/conversion/pipeline/office_pipeline.go
@@ -17,7 +17,7 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/infra"
@@ -26,26 +26,28 @@ import (
)
type officePipeline struct {
- pdfPipeline model.Pipeline
- officeProc *processor.OfficeProcessor
- pdfProc *processor.PDFProcessor
- s3 *infra.S3Manager
- config *config.Config
- apiClient *client.APIClient
+ pdfPipeline model.Pipeline
+ officeProc *processor.OfficeProcessor
+ pdfProc *processor.PDFProcessor
+ s3 *infra.S3Manager
+ config *config.Config
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
}
func NewOfficePipeline() model.Pipeline {
return &officePipeline{
- pdfPipeline: NewPDFPipeline(),
- officeProc: processor.NewOfficeProcessor(),
- pdfProc: processor.NewPDFProcessor(),
- s3: infra.NewS3Manager(),
- config: config.GetConfig(),
- apiClient: client.NewAPIClient(),
+ pdfPipeline: NewPDFPipeline(),
+ officeProc: processor.NewOfficeProcessor(),
+ pdfProc: processor.NewPDFProcessor(),
+ s3: infra.NewS3Manager(),
+ config: config.GetConfig(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
}
}
-func (p *officePipeline) Run(opts client.PipelineRunOptions) error {
+func (p *officePipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -58,8 +60,8 @@ func (p *officePipeline) Run(opts client.PipelineRunOptions) error {
}
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Converting to PDF."),
}); err != nil {
return err
@@ -68,7 +70,7 @@ func (p *officePipeline) Run(opts client.PipelineRunOptions) error {
if err != nil {
return err
}
- if err := p.pdfPipeline.Run(client.PipelineRunOptions{
+ if err := p.pdfPipeline.Run(api_client.PipelineRunOptions{
Bucket: opts.Bucket,
Key: *pdfKey,
SnapshotID: opts.SnapshotID,
@@ -78,7 +80,7 @@ func (p *officePipeline) Run(opts client.PipelineRunOptions) error {
return nil
}
-func (p *officePipeline) convertToPDF(inputPath string, opts client.PipelineRunOptions) (*string, error) {
+func (p *officePipeline) convertToPDF(inputPath string, opts api_client.PipelineRunOptions) (*string, error) {
outputDir := filepath.FromSlash(os.TempDir() + "/" + helper.NewID())
outputPath, err := p.officeProc.PDF(inputPath, outputDir)
if err != nil {
@@ -104,10 +106,10 @@ func (p *officePipeline) convertToPDF(inputPath string, opts client.PipelineRunO
if err := p.s3.PutFile(pdfKey, *outputPath, helper.DetectMimeFromFile(*outputPath), opts.Bucket, minio.PutObjectOptions{}); err != nil {
return nil, err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
- Preview: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldPreview},
+ Preview: &api_client.S3Object{
Bucket: opts.Bucket,
Key: pdfKey,
Size: helper.ToPtr(stat.Size()),
diff --git a/conversion/pipeline/pdf_pipeline.go b/conversion/pipeline/pdf_pipeline.go
index 7d886d761..4484aaddb 100644
--- a/conversion/pipeline/pdf_pipeline.go
+++ b/conversion/pipeline/pdf_pipeline.go
@@ -17,7 +17,7 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
@@ -27,26 +27,28 @@ import (
)
type pdfPipeline struct {
- pdfProc *processor.PDFProcessor
- imageProc *processor.ImageProcessor
- s3 *infra.S3Manager
- apiClient *client.APIClient
- fileIdent *identifier.FileIdentifier
- config *config.Config
+ pdfProc *processor.PDFProcessor
+ imageProc *processor.ImageProcessor
+ s3 *infra.S3Manager
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
+ fileIdent *identifier.FileIdentifier
+ config *config.Config
}
func NewPDFPipeline() model.Pipeline {
return &pdfPipeline{
- pdfProc: processor.NewPDFProcessor(),
- imageProc: processor.NewImageProcessor(),
- s3: infra.NewS3Manager(),
- apiClient: client.NewAPIClient(),
- fileIdent: identifier.NewFileIdentifier(),
- config: config.GetConfig(),
+ pdfProc: processor.NewPDFProcessor(),
+ imageProc: processor.NewImageProcessor(),
+ s3: infra.NewS3Manager(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
+ fileIdent: identifier.NewFileIdentifier(),
+ config: config.GetConfig(),
}
}
-func (p *pdfPipeline) Run(opts client.PipelineRunOptions) error {
+func (p *pdfPipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -58,8 +60,8 @@ func (p *pdfPipeline) Run(opts client.PipelineRunOptions) error {
infra.GetLogger().Error(err)
}
}(inputPath)
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Creating thumbnail."),
}); err != nil {
return err
@@ -67,8 +69,8 @@ func (p *pdfPipeline) Run(opts client.PipelineRunOptions) error {
if err := p.createThumbnail(inputPath, opts); err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Saving preview."),
}); err != nil {
return err
@@ -76,8 +78,8 @@ func (p *pdfPipeline) Run(opts client.PipelineRunOptions) error {
if err := p.saveOriginalAsPreview(inputPath, opts); err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Extracting text."),
}); err != nil {
return err
@@ -85,17 +87,17 @@ func (p *pdfPipeline) Run(opts client.PipelineRunOptions) error {
if err := p.extractText(inputPath, opts); err != nil {
return err
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName, client.TaskFieldStatus},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName, api_client.TaskFieldStatus},
Name: helper.ToPtr("Done."),
- Status: helper.ToPtr(client.TaskStatusSuccess),
+ Status: helper.ToPtr(api_client.TaskStatusSuccess),
}); err != nil {
return err
}
return nil
}
-func (p *pdfPipeline) createThumbnail(inputPath string, opts client.PipelineRunOptions) error {
+func (p *pdfPipeline) createThumbnail(inputPath string, opts api_client.PipelineRunOptions) error {
tmpPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".png")
// We don't consider failing the creation of the thumbnail as an error
_ = p.pdfProc.Thumbnail(inputPath, 0, p.config.Limits.ImagePreviewMaxHeight, tmpPath)
@@ -114,7 +116,7 @@ func (p *pdfPipeline) createThumbnail(inputPath string, opts client.PipelineRunO
if err != nil {
return err
}
- s3Object := &client.S3Object{
+ s3Object := &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.SnapshotID + "/thumbnail" + filepath.Ext(tmpPath),
Image: props,
@@ -123,9 +125,9 @@ func (p *pdfPipeline) createThumbnail(inputPath string, opts client.PipelineRunO
if err := p.s3.PutFile(s3Object.Key, tmpPath, helper.DetectMimeFromFile(tmpPath), s3Object.Bucket, minio.PutObjectOptions{}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldThumbnail},
+ Fields: []string{api_client.SnapshotFieldThumbnail},
Thumbnail: s3Object,
}); err != nil {
return err
@@ -133,7 +135,7 @@ func (p *pdfPipeline) createThumbnail(inputPath string, opts client.PipelineRunO
return nil
}
-func (p *pdfPipeline) extractText(inputPath string, opts client.PipelineRunOptions) error {
+func (p *pdfPipeline) extractText(inputPath string, opts api_client.PipelineRunOptions) error {
text, err := p.pdfProc.TextFromPDF(inputPath)
if err != nil {
infra.GetLogger().Named(infra.StrPipeline).Errorw(err.Error())
@@ -145,10 +147,10 @@ func (p *pdfPipeline) extractText(inputPath string, opts client.PipelineRunOptio
if err := p.s3.PutText(key, *text, "text/plain", opts.Bucket, minio.PutObjectOptions{}); err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldText},
- Text: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldText},
+ Text: &api_client.S3Object{
Bucket: opts.Bucket,
Key: key,
Size: helper.ToPtr(int64(len(*text))),
@@ -159,15 +161,15 @@ func (p *pdfPipeline) extractText(inputPath string, opts client.PipelineRunOptio
return nil
}
-func (p *pdfPipeline) saveOriginalAsPreview(inputPath string, opts client.PipelineRunOptions) error {
+func (p *pdfPipeline) saveOriginalAsPreview(inputPath string, opts api_client.PipelineRunOptions) error {
stat, err := os.Stat(inputPath)
if err != nil {
return err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
- Preview: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldPreview},
+ Preview: &api_client.S3Object{
Bucket: opts.Bucket,
Key: opts.Key,
Size: helper.ToPtr(stat.Size()),
diff --git a/conversion/pipeline/zip_pipeline.go b/conversion/pipeline/zip_pipeline.go
index 305121a28..8b9786303 100644
--- a/conversion/pipeline/zip_pipeline.go
+++ b/conversion/pipeline/zip_pipeline.go
@@ -17,7 +17,7 @@ import (
"github.com/minio/minio-go/v7"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
"github.com/kouprlabs/voltaserve/conversion/infra"
@@ -26,26 +26,28 @@ import (
)
type zipPipeline struct {
- glbPipeline model.Pipeline
- zipProc *processor.ZIPProcessor
- gltfProc *processor.GLTFProcessor
- s3 *infra.S3Manager
- fi *identifier.FileIdentifier
- apiClient *client.APIClient
+ glbPipeline model.Pipeline
+ zipProc *processor.ZIPProcessor
+ gltfProc *processor.GLTFProcessor
+ s3 *infra.S3Manager
+ fi *identifier.FileIdentifier
+ taskClient *api_client.TaskClient
+ snapshotClient *api_client.SnapshotClient
}
func NewZIPPipeline() model.Pipeline {
return &zipPipeline{
- glbPipeline: NewGLBPipeline(),
- zipProc: processor.NewZIPProcessor(),
- gltfProc: processor.NewGLTFProcessor(),
- s3: infra.NewS3Manager(),
- fi: identifier.NewFileIdentifier(),
- apiClient: client.NewAPIClient(),
+ glbPipeline: NewGLBPipeline(),
+ zipProc: processor.NewZIPProcessor(),
+ gltfProc: processor.NewGLTFProcessor(),
+ s3: infra.NewS3Manager(),
+ fi: identifier.NewFileIdentifier(),
+ taskClient: api_client.NewTaskClient(),
+ snapshotClient: api_client.NewSnapshotClient(),
}
}
-func (p *zipPipeline) Run(opts client.PipelineRunOptions) error {
+func (p *zipPipeline) Run(opts api_client.PipelineRunOptions) error {
inputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + filepath.Ext(opts.Key))
if err := p.s3.GetFile(opts.Key, inputPath, opts.Bucket, minio.GetObjectOptions{}); err != nil {
return err
@@ -62,8 +64,8 @@ func (p *zipPipeline) Run(opts client.PipelineRunOptions) error {
return err
}
if isGLTF {
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Extracting ZIP."),
}); err != nil {
return err
@@ -85,8 +87,8 @@ func (p *zipPipeline) Run(opts client.PipelineRunOptions) error {
// Do nothing, treat it as a ZIP file
return nil
}
- if err := p.apiClient.PatchTask(opts.TaskID, client.TaskPatchOptions{
- Fields: []string{client.TaskFieldName},
+ if err := p.taskClient.Patch(opts.TaskID, api_client.TaskPatchOptions{
+ Fields: []string{api_client.TaskFieldName},
Name: helper.ToPtr("Converting to GLB."),
}); err != nil {
return err
@@ -95,7 +97,7 @@ func (p *zipPipeline) Run(opts client.PipelineRunOptions) error {
if err != nil {
return err
}
- if err := p.glbPipeline.Run(client.PipelineRunOptions{
+ if err := p.glbPipeline.Run(api_client.PipelineRunOptions{
Bucket: opts.Bucket,
Key: *glbKey,
SnapshotID: opts.SnapshotID,
@@ -107,7 +109,7 @@ func (p *zipPipeline) Run(opts client.PipelineRunOptions) error {
return nil
}
-func (p *zipPipeline) convertToGLB(inputPath string, opts client.PipelineRunOptions) (*string, error) {
+func (p *zipPipeline) convertToGLB(inputPath string, opts api_client.PipelineRunOptions) (*string, error) {
outputPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".glb")
if err := p.gltfProc.ToGLB(inputPath, outputPath); err != nil {
return nil, err
@@ -127,10 +129,10 @@ func (p *zipPipeline) convertToGLB(inputPath string, opts client.PipelineRunOpti
if err := p.s3.PutFile(glbKey, outputPath, helper.DetectMimeFromFile(outputPath), opts.Bucket, minio.PutObjectOptions{}); err != nil {
return nil, err
}
- if err := p.apiClient.PatchSnapshot(client.SnapshotPatchOptions{
+ if err := p.snapshotClient.Patch(api_client.SnapshotPatchOptions{
Options: opts,
- Fields: []string{client.SnapshotFieldPreview},
- Preview: &client.S3Object{
+ Fields: []string{api_client.SnapshotFieldPreview},
+ Preview: &api_client.S3Object{
Bucket: opts.Bucket,
Key: glbKey,
Size: helper.ToPtr(stat.Size()),
diff --git a/conversion/processor/image_processor.go b/conversion/processor/image_processor.go
index ae0396f3c..9375cb023 100644
--- a/conversion/processor/image_processor.go
+++ b/conversion/processor/image_processor.go
@@ -14,7 +14,7 @@ import (
"strconv"
"strings"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/helper"
"github.com/kouprlabs/voltaserve/conversion/identifier"
@@ -22,14 +22,12 @@ import (
)
type ImageProcessor struct {
- apiClient *client.APIClient
fileIdent *identifier.FileIdentifier
config *config.Config
}
func NewImageProcessor() *ImageProcessor {
return &ImageProcessor{
- apiClient: client.NewAPIClient(),
fileIdent: identifier.NewFileIdentifier(),
config: config.GetConfig(),
}
@@ -55,7 +53,7 @@ func (p *ImageProcessor) Thumbnail(inputPath string, outputPath string) (*bool,
return helper.ToPtr(false), nil
}
-func (p *ImageProcessor) MeasureImage(inputPath string) (*client.ImageProps, error) {
+func (p *ImageProcessor) MeasureImage(inputPath string) (*api_client.ImageProps, error) {
size, err := infra.NewCommand().ReadOutput("identify", "-format", "%w,%h", inputPath)
if err != nil {
return nil, err
@@ -69,7 +67,7 @@ func (p *ImageProcessor) MeasureImage(inputPath string) (*client.ImageProps, err
if err != nil {
return nil, err
}
- return &client.ImageProps{
+ return &api_client.ImageProps{
Width: width,
Height: height,
}, nil
diff --git a/conversion/router/health_router.go b/conversion/router/health_router.go
index 2412c43d1..9cc0ff9c6 100644
--- a/conversion/router/health_router.go
+++ b/conversion/router/health_router.go
@@ -15,7 +15,7 @@ import (
"github.com/gofiber/fiber/v2"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/infra"
"github.com/kouprlabs/voltaserve/conversion/runtime"
)
@@ -38,7 +38,7 @@ func (r *HealthRouter) AppendRoutes(g fiber.Router) {
g.Get("health", r.GetHealth)
}
-// Healdth godoc
+// GetHealth godoc
//
// @Summary Get Health
// @Description Get Health
@@ -55,7 +55,7 @@ func (r *HealthRouter) GetHealth(c *fiber.Ctx) error {
if err := infra.NewS3Manager().Connect(); err != nil {
return c.SendStatus(http.StatusServiceUnavailable)
}
- if ok, err := client.NewAPIClient().GetHealth(); err != nil || ok != "OK" {
+ if ok, err := api_client.NewHealthClient().Get(); err != nil || ok != "OK" {
return c.SendStatus(http.StatusServiceUnavailable)
}
return c.SendString("OK")
diff --git a/conversion/router/pipeline_router.go b/conversion/router/pipeline_router.go
index bad0f7e7a..18c6ca890 100644
--- a/conversion/router/pipeline_router.go
+++ b/conversion/router/pipeline_router.go
@@ -14,7 +14,7 @@ import (
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/config"
"github.com/kouprlabs/voltaserve/conversion/errorpkg"
"github.com/kouprlabs/voltaserve/conversion/runtime"
@@ -40,7 +40,7 @@ func (r *PipelineRouter) AppendRoutes(g fiber.Router) {
g.Post("pipelines/run", r.Run)
}
-// Create godoc
+// Run godoc
//
// @Summary Run
// @Description Run
@@ -48,13 +48,13 @@ func (r *PipelineRouter) AppendRoutes(g fiber.Router) {
// @Id pipelines_run
// @Accept json
// @Produce json
-// @Param body body client.PipelineRunOptions true "Body"
+// @Param body body api_client.PipelineRunOptions true "Body"
// @Success 200
// @Failure 400
// @Failure 500
// @Router /pipelines/run [post]
func (r *PipelineRouter) Run(c *fiber.Ctx) error {
- opts := new(client.PipelineRunOptions)
+ opts := new(api_client.PipelineRunOptions)
if err := c.BodyParser(opts); err != nil {
return err
}
diff --git a/conversion/runtime/scheduler.go b/conversion/runtime/scheduler.go
index 3d93ead17..9c77f030c 100644
--- a/conversion/runtime/scheduler.go
+++ b/conversion/runtime/scheduler.go
@@ -14,17 +14,16 @@ import (
"runtime"
"time"
- "github.com/kouprlabs/voltaserve/conversion/client"
+ "github.com/kouprlabs/voltaserve/conversion/client/api_client"
"github.com/kouprlabs/voltaserve/conversion/infra"
"github.com/kouprlabs/voltaserve/conversion/pipeline"
)
type Scheduler struct {
- pipelineQueue [][]client.PipelineRunOptions
+ pipelineQueue [][]api_client.PipelineRunOptions
pipelineWorkerCount int
activePipelineCount int
installer *Installer
- apiClient *client.APIClient
}
type SchedulerOptions struct {
@@ -44,10 +43,9 @@ func NewDefaultSchedulerOptions() SchedulerOptions {
func NewScheduler(opts SchedulerOptions) *Scheduler {
return &Scheduler{
- pipelineQueue: make([][]client.PipelineRunOptions, opts.PipelineWorkerCount),
+ pipelineQueue: make([][]api_client.PipelineRunOptions, opts.PipelineWorkerCount),
pipelineWorkerCount: opts.PipelineWorkerCount,
installer: opts.Installer,
- apiClient: client.NewAPIClient(),
}
}
@@ -60,7 +58,7 @@ func (s *Scheduler) Start() {
go s.pipelineWorkerStatus()
}
-func (s *Scheduler) SchedulePipeline(opts *client.PipelineRunOptions) {
+func (s *Scheduler) SchedulePipeline(opts *api_client.PipelineRunOptions) {
index := s.choosePipeline()
infra.GetLogger().Named(infra.StrScheduler).Infow("👉 choosing", "pipeline", index)
s.pipelineQueue[index] = append(s.pipelineQueue[index], *opts)
@@ -81,7 +79,7 @@ func (s *Scheduler) choosePipeline() int {
func (s *Scheduler) pipelineWorker(index int) {
dispatcher := pipeline.NewDispatcher()
- s.pipelineQueue[index] = make([]client.PipelineRunOptions, 0)
+ s.pipelineQueue[index] = make([]api_client.PipelineRunOptions, 0)
infra.GetLogger().Named(infra.StrPipeline).Infow("⚙️ running", "worker", index)
for {
if len(s.pipelineQueue[index]) > 0 && !s.installer.IsRunning() {
diff --git a/ui/src/client/api/task.ts b/ui/src/client/api/task.ts
index a5fded926..163b8167e 100644
--- a/ui/src/client/api/task.ts
+++ b/ui/src/client/api/task.ts
@@ -40,7 +40,7 @@ export enum Status {
}
export type TaskPayload = {
- fileId?: string
+ object?: string
}
export type List = {
diff --git a/ui/src/components/task/task-item.tsx b/ui/src/components/task/task-item.tsx
index 8242e1eeb..369cbb482 100644
--- a/ui/src/components/task/task-item.tsx
+++ b/ui/src/components/task/task-item.tsx
@@ -7,7 +7,6 @@
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// licenses/AGPL.txt.
-
import { useCallback, useState } from 'react'
import {
Accordion,
@@ -17,14 +16,12 @@ import {
AccordionPanel,
Card,
CardBody,
- Text,
CircularProgress,
IconButton,
+ Text,
} from '@chakra-ui/react'
import cx from 'classnames'
-import FileAPI from '@/client/api/file'
import TaskAPI, { Status, Task } from '@/client/api/task'
-import { swrConfig } from '@/client/options'
import {
IconCheckCircle,
IconClose,
@@ -41,12 +38,6 @@ export type TaskDrawerItemProps = {
const TaskDrawerItem = ({ task }: TaskDrawerItemProps) => {
const [isDismissing, setIsDismissing] = useState(false)
const mutateList = useAppSelector((state) => state.ui.tasks.mutateList)
- const { data: file } = FileAPI.useGet(
- task.payload?.fileId,
- swrConfig(),
- false,
- )
- const fileName = file ? file?.name : 'File deleted.'
const handleDismiss = useCallback(async () => {
try {
@@ -83,9 +74,9 @@ const TaskDrawerItem = ({ task }: TaskDrawerItemProps) => {