You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.1 KiB
71 lines
1.1 KiB
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
var Pipelines []Pipeline
|
|
|
|
type PipelineType int
|
|
type PipelineStepType int
|
|
|
|
const (
|
|
Image PipelineType = iota
|
|
Video
|
|
)
|
|
|
|
const (
|
|
Resize PipelineStepType = iota
|
|
Compress
|
|
Encode
|
|
)
|
|
|
|
type Pipeline struct {
|
|
Name string
|
|
Type PipelineType
|
|
RemoveMetadata bool
|
|
Steps []Step
|
|
}
|
|
|
|
type Step struct {
|
|
Name string
|
|
Type PipelineStepType
|
|
}
|
|
|
|
func DeserializePipelines(pipelines [][]byte) []Pipeline {
|
|
values := make([]Pipeline, len(pipelines))
|
|
|
|
for index, pipeline := range pipelines {
|
|
var deserializedObject Pipeline
|
|
json.Unmarshal(pipeline, &deserializedObject)
|
|
values[index] = deserializedObject
|
|
}
|
|
|
|
return values
|
|
}
|
|
|
|
func LoadPipelines() {
|
|
var files [][]byte
|
|
|
|
path, _ := os.Getwd()
|
|
|
|
err := filepath.Walk(path+"/pipelines", func(path string, info fs.FileInfo, err error) error {
|
|
if err == nil && info.IsDir() == false {
|
|
fmt.Println(path)
|
|
data, _ := os.ReadFile(path)
|
|
files = append(files, data)
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
Pipelines = DeserializePipelines(files)
|
|
}
|